From: "Suraj N. Kurapati" Date: 2006-05-13T13:36:06+09:00 Subject: Re: using RSpec without runner - inconsistent context evalua -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Scott L Holmes wrote: > Your situation is very much different from mine but I think the solution > may be the same. > > What is happening is that the contexts are being executed one by one in > the embedded (ruby) invocation versus "collected" and executed together > in the spec invocation. > > The context class has a built in capability to attach itself to the > runner as they are being created, given all defaults. If you type the > contexts in to irb, you'd probably get similar behavior. > > So what you'll need to do is replicate what the spec command is doing: > > # create a runner and tell the Context class to use it from now on. > context_runner = Spec::Runner::ContextRunner.new(["-v"],[nil]) > Spec::Runner::Context.context_runner = context_runner > # include your contexts and specs here > # then run them all at once. > context_runner.run > > This is taken from the spec command that's in the bin folder of the > distribution 0.5.3 Thanks for your help Scott. The contexts are now evaluated as expected. I'll post this as a feature request to the RSpec tracker. ### begin stack_spec.rb ### require 'rubygems' require_gem 'rspec' require 'spec' # bypass termination when no arguments are provided ARGV.unshift '' context_runner = Spec::Runner::ContextRunner.new(ARGV) Spec::Runner::Context.context_runner = context_runner at_exit {context_runner.run} context "A new stack" do specify "should be empty" do end end context "An empty stack" do specify "should not be empty after 'push'" do end end ### end stack_spec.rb ### ### begin output ### $ ruby stack_spec.rb -v A new stack - - should be empty An empty stack - - should not be empty after 'push' Finished in 0.001342 seconds 2 contexts, 2 specifications, 0 failures ### end output ### -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) iD8DBQFEZWIqmV9O7RYnKMcRArrQAJ9WXcmVsUNMLY51/AW77FwjVgeSxgCggKqa lMP5DMEhnfBJLVU+fjh4CSo= =hp7S -----END PGP SIGNATURE-----