rspec-cleanup¶ ↑
If you create classes or other constants in your specs, these classes can leak to other specs unless you take special care. This gem makes it easier to isolate specs that manipulate classes (or other constants) from each other.
Normally in rspec:
describe "in rspec, it-blocks within a describe-block" do before do class Person end end it "can see classes defined in before blocks" do Person.new end it "can see classes defined within the it-block itself" do class Address end Address.new end it "can see classes defined in other it-blocks" do Address.new end end describe "it-blocks within another describe block, even in other files" do it "can see classes defined in a before block of another describe block" do Person.new end it "can see classes defined in an it block in another describe block" do Address.new end end
But with rspec-cleanup:
describe "with rspec-cleanup, it-blocks within a describe-block" do # This is the magic phrase that removes created classes and # constants that might otherwise leak to other specs cleanup.after_spec before do class Computer end end it "should see classes defined in before blocks" do Computer.new end it "should see classes defined within the it-block itself" do class Mouse end Mouse.new end it "should not see classes defined in other it-blocks" do lambda { Mouse }.should raise_error end end describe "it-blocks within another describe block" do it "should not see classes defined in a before block of another describe block" do lambda { Computer }.should raise_error end it "should not see classes defined in an it block in another describe block" do lambda { Computer }.should raise_error end end
TODO¶ ↑
-
Add support for specs written inside a module
Note on Patches/Pull Requests¶ ↑
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Copyright¶ ↑
Copyright © 2010 Niclas Nilsson. See LICENSE for details.