1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00
therubyracer/spec/c/exception_spec.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

28 lines
673 B
Ruby

require 'spec_helper'
describe V8::C::Exception do
requires_v8_context
it "can be thrown from Ruby" do
t = V8::C::FunctionTemplate::New(method(:explode))
@cxt.Global().Set("explode", t.GetFunction())
script = V8::C::Script::New(<<-JS, '<eval>')
(function() {
try {
explode()
} catch (e) {
return e.message
}
})()
JS
result = script.Run()
result.should_not be_nil
result.should be_kind_of(V8::C::String)
result.Utf8Value().should eql 'did not pay syntax'
end
def explode(arguments)
error = V8::C::Exception::SyntaxError('did not pay syntax')
V8::C::ThrowException(error)
end
end