lib/rspec/matchers/built_in/yield.rb in rspec-expectations-2.99.2 vs lib/rspec/matchers/built_in/yield.rb in rspec-expectations-3.0.0.beta1
- old
+ new
@@ -22,10 +22,11 @@
probe = self
Proc.new do |*args|
probe.num_yields += 1
probe.yielded_args << args
+ nil # to indicate the block does not return a meaningful value
end
end
def single_yield_args
yielded_args.first
@@ -119,17 +120,12 @@
'expected given block not to yield control'.tap do |failure_message|
failure_message << relativity_failure_message
end
end
- # @private
- def supports_block_expectations?
- true
- end
+ private
- private
-
def set_expected_yields_count(relativity, n)
@expectation_type = relativity
@expected_yields_count = case n
when Numeric then n
when :once then 1
@@ -172,15 +168,10 @@
def failure_message_for_should_not
"expected given block not to yield with no arguments, but did"
end
- # @private
- def supports_block_expectations?
- true
- end
-
private
def failure_reason
if @probe.num_yields.zero?
"did not yield"
@@ -189,21 +180,20 @@
end
end
end
class YieldWithArgs
- include MatchAliases
-
def initialize(*args)
@expected = args
end
def matches?(block)
@probe = YieldProbe.probe(block)
@actual = @probe.single_yield_args
@probe.yielded_once?(:yield_with_args) && args_match?
end
+ alias == matches?
def failure_message_for_should
"expected given block to yield with arguments, but #{positive_failure_reason}"
end
@@ -215,15 +205,10 @@
desc = "yield with args"
desc << "(" + @expected.map { |e| e.inspect }.join(", ") + ")" unless @expected.empty?
desc
end
- # @private
- def supports_block_expectations?
- true
- end
-
private
def positive_failure_reason
if @probe.num_yields.zero?
"did not yield"
@@ -265,21 +250,20 @@
end
end
end
class YieldSuccessiveArgs
- include MatchAliases
-
def initialize(*args)
@expected = args
end
def matches?(block)
@probe = YieldProbe.probe(block)
@actual = @probe.successive_yield_args
args_match?
end
+ alias == matches?
def failure_message_for_should
"expected given block to yield successively with arguments, but yielded with unexpected arguments" +
"\nexpected: #{@expected.inspect}" +
"\n got: #{@actual.inspect} (compared using === and ==)"
@@ -293,14 +277,9 @@
def description
desc = "yield successive args"
desc << "(" + @expected.map { |e| e.inspect }.join(", ") + ")"
desc
- end
-
- # @private
- def supports_block_expectations?
- true
end
private
def args_match?