Class: ErgomentumRspec::Matchers::Yield::YieldAll
- Inherits:
-
Object
- Object
- ErgomentumRspec::Matchers::Yield::YieldAll
- Includes:
- RSpec::Matchers::Composable
- Defined in:
- lib/ergomentum_rspec/matchers/yield/yield_all.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(expected) ⇒ YieldAll
constructor
A new instance of YieldAll.
- #match(actual) ⇒ Object
- #matches?(*block) ⇒ Boolean
- #supports_block_expectations? ⇒ Boolean
Constructor Details
#initialize(expected) ⇒ YieldAll
Returns a new instance of YieldAll.
19 20 21 |
# File 'lib/ergomentum_rspec/matchers/yield/yield_all.rb', line 19 def initialize(expected) @expected = expected end |
Instance Method Details
#description ⇒ Object
58 59 60 |
# File 'lib/ergomentum_rspec/matchers/yield/yield_all.rb', line 58 def description "yields all" end |
#failure_message ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/ergomentum_rspec/matchers/yield/yield_all.rb', line 50 def if @expected.respond_to?(:failure_message) "Failed for #{ActiveSupport::Inflector.ordinalize(@count)} yield with:\n#{@expected.}" else "Expecting #{@expected} got #{@last} for #{ActiveSupport::Inflector.ordinalize(@count)} yield" end end |
#match(actual) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/ergomentum_rspec/matchers/yield/yield_all.rb', line 40 def match(actual) @count += 1 @last = actual @result &&= if @expected.respond_to?(:matches?) @expected.matches?(actual) else values_match?(@expected, actual) end end |
#matches?(*block) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ergomentum_rspec/matchers/yield/yield_all.rb', line 27 def matches?(*block) @count = 0 @result = true if block_given? yield(method(:match)) elsif block.first.is_a?(Proc) block.first.call(method(:match)) else raise NoBlockGivenError end @result end |
#supports_block_expectations? ⇒ Boolean
23 24 25 |
# File 'lib/ergomentum_rspec/matchers/yield/yield_all.rb', line 23 def supports_block_expectations? true end |