lib/rspec/matchers/built_in/yield.rb in rspec-expectations-3.1.2 vs lib/rspec/matchers/built_in/yield.rb in rspec-expectations-3.2.0

- old
+ new

@@ -92,12 +92,11 @@ # @api private # Provides the implementation for `yield_control`. # Not intended to be instantiated directly. class YieldControl < BaseMatcher def initialize - @expectation_type = nil - @expected_yields_count = nil + at_least(:once) end # @api public # Specifies that the method is expected to yield once. def once @@ -149,15 +148,11 @@ # @private def matches?(block) @probe = YieldProbe.probe(block) return false unless @probe.has_block? - if @expectation_type - @probe.num_yields.__send__(@expectation_type, @expected_yields_count) - else - @probe.yielded_once?(:yield_control) - end + @probe.num_yields.__send__(@expectation_type, @expected_yields_count) end # @private def does_not_match?(block) !matches?(block) && @probe.has_block? @@ -193,25 +188,26 @@ end def failure_reason return " but was not a block" unless @probe.has_block? return '' unless @expected_yields_count - " #{human_readable_expecation_type}#{human_readable_count}" + " #{human_readable_expectation_type}#{human_readable_count(@expected_yields_count)}" \ + " but yielded #{human_readable_count(@probe.num_yields)}" end - def human_readable_expecation_type + def human_readable_expectation_type case @expectation_type when :<= then 'at most ' when :>= then 'at least ' else '' end end - def human_readable_count - case @expected_yields_count + def human_readable_count(count) + case count when 1 then "once" when 2 then "twice" - else "#{@expected_yields_count} times" + else "#{count} times" end end end # @api private