Class: ErgomentumRspec::Matchers::Yield::YieldAll

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers::Composable
Defined in:
lib/ergomentum_rspec/matchers/yield/yield_all.rb

Instance Method Summary collapse

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

#descriptionObject



58
59
60
# File 'lib/ergomentum_rspec/matchers/yield/yield_all.rb', line 58

def description
  "yields all"
end

#failure_messageObject



50
51
52
53
54
55
56
# File 'lib/ergomentum_rspec/matchers/yield/yield_all.rb', line 50

def failure_message
  if @expected.respond_to?(:failure_message)
    "Failed for #{ActiveSupport::Inflector.ordinalize(@count)} yield with:\n#{@expected.failure_message}"
  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

Returns:

  • (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

Returns:

  • (Boolean)


23
24
25
# File 'lib/ergomentum_rspec/matchers/yield/yield_all.rb', line 23

def supports_block_expectations?
  true
end