Skip to content

Instantly share code, notes, and snippets.

@cluesque
Created May 28, 2015 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cluesque/4f76ee0a634138c71ad4 to your computer and use it in GitHub Desktop.
Save cluesque/4f76ee0a634138c71ad4 to your computer and use it in GitHub Desktop.
Macros for adding setup and teardown to a context don't do what I think they should
require 'test_helper'
class ShouldaContextTest < ActiveSupport::TestCase
def self.setup_setup_helper
setup { puts "running the setup helper"; @wrapped = true }
teardown{ puts "running the teardown helper"; @wrapped = false }
end
context "outer nesting" do
context "without setup" do
setup do
puts "inner explicit setup"
end
should 'not have run the other setup' do
puts "non-setup assertion"
assert !@wrapped
end
end
context 'irrelevant' do
setup_setup_helper
should 'not matter' do
puts "setup assertion"
assert @wrapped
end
end
end
end
$ time bundle exec ruby -Itest test/unit/shoulda_context_test.rb
WebMock disabling network connections (use SKIP_WEBMOCK to disable)
Loaded suite test/unit/shoulda_context_test
Started
running the setup helper
setup assertion
running the teardown helper
running the setup helper
inner explicit setup
non-setup assertion
F
===============================================================================
Failure: <false> is not true.
test: outer nesting without setup should not have run the other setup. (ShouldaContextTest)
test/unit/shoulda_context_test.rb:15:in `block (3 levels) in <class:ShouldaContextTest>'
===============================================================================
running the teardown helper
Finished in 0.934133 seconds.
2 tests, 3 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
0% passed
2.14 tests/s, 3.21 assertions/s
real 0m16.799s
user 0m8.270s
sys 0m3.669s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment