On Mon, Aug 24, 2009 at 2:19 PM, Gregory Hnatiuk<[email protected]> wrote:
> What is the expected/intended behavior for the scope of class instance
> variables when running multiple specs?
>
> It appears that setting a class instance variable in one spec will
> affect it in a second spec run like so:
>
> http://gist.github.com/174018
>
> running `spec spec1_spec.rb spec2_spec.rb`  or `spec .` from within
> that directory will fail because the state of the instance variable is
> maintained.
>
> I'm investigating a case where this behavior is affecting the passing/
> failing of specs based on the order they are loaded by Rake's
> FileList, and am looking for a little background before I try to solve
> it.

Each example is run in a separate scope, so locals and instance
variables are cleaned up by Ruby's gc after each example.

All the examples run in one process, however, so globals are a
different matter. RSpec will clean up globals that it sets internally,
like if you stub methods on class objects, etc. Any global state
changed by the spec or the app is really up to you as the spec author
to clean up after each example.

HTH,
David

> _______________________________________________
> rspec-users mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to