1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

Fixing should piggybacking [#39]

This commit is contained in:
Jonathan Lim 2008-06-17 15:01:07 +01:00 committed by Tammer Saleh
parent 66fc5c31bf
commit 474f099fca
2 changed files with 15 additions and 8 deletions

View file

@ -34,14 +34,12 @@ module Thoughtbot
# Note: The part before <tt>should</tt> in the test name is gleamed from the name of the Test::Unit class. # Note: The part before <tt>should</tt> in the test name is gleamed from the name of the Test::Unit class.
def should(name, &blk) def should(name, &blk)
should_eventually(name) && return unless block_given?
if Shoulda.current_context if Shoulda.current_context
Shoulda.current_context.should(name, &blk) block_given? ? Shoulda.current_context.should(name, &blk) : Should.current_context.should_eventually(name)
else else
context_name = self.name.gsub(/Test/, "") context_name = self.name.gsub(/Test/, "")
context = Thoughtbot::Shoulda::Context.new(context_name, self) do context = Thoughtbot::Shoulda::Context.new(context_name, self) do
should(name, &blk) block_given? ? should(name, &blk) : should_eventually(name)
end end
context.build context.build
end end
@ -157,7 +155,11 @@ module Thoughtbot
end end
def should(name, &blk) def should(name, &blk)
self.shoulds << { :name => name, :block => blk } if block_given?
self.shoulds << { :name => name, :block => blk }
else
self.should_eventuallys << { :name => name }
end
end end
def should_eventually(name, &blk) def should_eventually(name, &blk)

View file

@ -96,10 +96,15 @@ class ContextTest < Test::Unit::TestCase # :nodoc:
end end
should_eventually "should pass, since it's unimplemented" do should_eventually "pass, since it's unimplemented" do
flunk "what?" flunk "what?"
end end
should_eventually "not require a block when using should_eventually"
should "pass without a block, as that causes it to piggyback to should_eventually"
should_eventually "should not require a block when using should_eventually" context "context for testing should piggybacking" do
should "should pass without a block, as that causes it to piggyback to should_eventually" # I do not think this works inside a context
should "call should_eventually as we are not passing a block"
end
end end