diff --git a/spec/c/array_spec.rb b/spec/c/array_spec.rb index 06ef20c..138e081 100644 --- a/spec/c/array_spec.rb +++ b/spec/c/array_spec.rb @@ -1,13 +1,7 @@ require 'spec_helper' describe V8::C::Array do - before do - @cxt = V8::C::Context::New() - @cxt.Enter() - end - after do - @cxt.Exit() - end + include C::ContextHelper it "can store and retrieve a value" do V8::C::HandleScope() do o = V8::C::Object::New() diff --git a/spec/c/context_helper.rb b/spec/c/context_helper.rb new file mode 100644 index 0000000..69c196b --- /dev/null +++ b/spec/c/context_helper.rb @@ -0,0 +1,15 @@ +module C + module ContextHelper + def self.included(base) + base.instance_eval do + before do + @cxt = V8::C::Context::New() + @cxt.Enter() + end + after do + @cxt.Exit() + end + end + end + end +end \ No newline at end of file diff --git a/spec/c/external_spec.rb b/spec/c/external_spec.rb index 6bea513..741772e 100644 --- a/spec/c/external_spec.rb +++ b/spec/c/external_spec.rb @@ -1,13 +1,7 @@ require 'spec_helper' describe V8::C::External do - before do - @cxt = V8::C::Context::New() - @cxt.Enter() - end - after do - @cxt.Exit() - end + include C::ContextHelper it "can store and retrieve a value" do V8::C::HandleScope() do o = Object.new diff --git a/spec/c/function_spec.rb b/spec/c/function_spec.rb index 71ee14e..b063124 100644 --- a/spec/c/function_spec.rb +++ b/spec/c/function_spec.rb @@ -1,13 +1,7 @@ require 'spec_helper' describe V8::C::Function do - before do - @cxt = V8::C::Context::New() - @cxt.Enter() - end - after do - @cxt.Exit() - end + include C::ContextHelper it "can be called" do V8::C::HandleScope() do fn = run '(function() {return "foo"})' diff --git a/spec/c/handles_spec.rb b/spec/c/handles_spec.rb index 9921cde..1d76341 100644 --- a/spec/c/handles_spec.rb +++ b/spec/c/handles_spec.rb @@ -1,9 +1,7 @@ require 'spec_helper' describe "setting up handles scopes" do - before {@cxt = V8::C::Context::New()} - before {@cxt.Enter()} - after {@cxt.Exit()} + include C::ContextHelper it "can allocate handle scopes" do V8::C::HandleScope() do V8::C::Object::New() diff --git a/spec/c/object_spec.rb b/spec/c/object_spec.rb index 207bc8f..8863a89 100644 --- a/spec/c/object_spec.rb +++ b/spec/c/object_spec.rb @@ -1,13 +1,8 @@ require 'spec_helper' describe V8::C::Object do - before do - @cxt = V8::C::Context::New() - @cxt.Enter() - end - after do - @cxt.Exit() - end + include C::ContextHelper + it "can store and retrieve a value" do V8::C::HandleScope() do o = V8::C::Object::New() diff --git a/spec/c/script_spec.rb b/spec/c/script_spec.rb index 0dfdd52..d9fb669 100644 --- a/spec/c/script_spec.rb +++ b/spec/c/script_spec.rb @@ -1,13 +1,7 @@ require 'spec_helper' describe V8::C::External do - before do - @cxt = V8::C::Context::New() - @cxt.Enter() - end - after do - @cxt.Exit() - end + include C::ContextHelper it "can run a script and return a polymorphic result" do V8::C::HandleScope() do source = V8::C::String::New("(new Array())") diff --git a/spec/c/template_spec.rb b/spec/c/template_spec.rb index 13b18f5..1c21cea 100644 --- a/spec/c/template_spec.rb +++ b/spec/c/template_spec.rb @@ -1,13 +1,7 @@ require 'spec_helper' describe V8::C::Template do - before do - @cxt = V8::C::Context::New() - @cxt.Enter() - end - after do - @cxt.Exit() - end + include C::ContextHelper describe V8::C::FunctionTemplate do it "can be created with no arguments" do diff --git a/spec/c/trycatch_spec.rb b/spec/c/trycatch_spec.rb index 958d76b..7bbda72 100644 --- a/spec/c/trycatch_spec.rb +++ b/spec/c/trycatch_spec.rb @@ -1,13 +1,8 @@ require 'spec_helper' describe V8::C::External do - before do - @cxt = V8::C::Context::New() - @cxt.Enter() - end - after do - @cxt.Exit() - end + include C::ContextHelper + it "can catch javascript exceptions" do V8::C::V8::SetCaptureStackTraceForUncaughtExceptions(true, 99, V8::C::StackTrace::kDetailed) V8::C::TryCatch() do |trycatch| diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ad66ba3..b972703 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,5 @@ require 'v8' +load File.expand_path '../c/context_helper.rb', __FILE__ def run_v8_gc while !V8::C::V8::IdleNotification() do