1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/spec/spec_helper.rb
Georgy Angelov 654b808ac5 Use #around for creation of context for C examples
This fixes segmentation fault in the tests as extending the examples in a before block with override of `#instance_eval` seems to not work.

Also, the context wrap is now opt-in with a helper method, instead of opt-out and relying on `#described_class` (which has slightly different behavior in RSpec 3).

Tested on Ruby 2.1.5 and RSpec 2.99.2.
2015-03-15 18:27:19 +00:00

41 lines
711 B
Ruby

require 'v8'
def run_v8_gc
V8::C::V8::LowMemoryNotification()
while !V8::C::V8::IdleNotification() do
end
end
def rputs(msg)
puts "<pre>#{ERB::Util.h(msg)}</pre>"
$stdout.flush
end
module V8ContextHelpers
module GroupMethods
def requires_v8_context
around(:each) do |example|
bootstrap_v8_context(&example)
end
end
end
def bootstrap_v8_context
V8::C::Locker() do
V8::C::HandleScope() do
@cxt = V8::C::Context::New()
begin
@cxt.Enter()
yield
ensure
@cxt.Exit()
end
end
end
end
end
RSpec.configure do |c|
c.include V8ContextHelpers
c.extend V8ContextHelpers::GroupMethods
end