Class: RSpec::Matchers::BuiltIn::YieldWithArgs

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/matchers/built_in/yield.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ YieldWithArgs

Returns a new instance of YieldWithArgs.



109
110
111
# File 'lib/rspec/matchers/built_in/yield.rb', line 109

def initialize(*args)
  @expected = args
end

Instance Method Details

#descriptionObject



128
129
130
131
132
# File 'lib/rspec/matchers/built_in/yield.rb', line 128

def description
  desc = "yield with args"
  desc << "(" + @expected.map { |e| e.inspect }.join(", ") + ")" unless @expected.empty?
  desc
end

#failure_message_for_shouldObject



120
121
122
# File 'lib/rspec/matchers/built_in/yield.rb', line 120

def failure_message_for_should
  "expected given block to yield with arguments, but #{positive_failure_reason}"
end

#failure_message_for_should_notObject



124
125
126
# File 'lib/rspec/matchers/built_in/yield.rb', line 124

def failure_message_for_should_not
  "expected given block not to yield with arguments, but #{negative_failure_reason}"
end

#matches?(block) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


113
114
115
116
117
# File 'lib/rspec/matchers/built_in/yield.rb', line 113

def matches?(block)
  @probe = YieldProbe.probe(block)
  @actual = @probe.single_yield_args
  @probe.yielded_once?(:yield_with_args) && args_match?
end