Class: RSpec::Matchers::BuiltIn::YieldControl

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

Constant Summary

Constant Summary

Constants inherited from BaseMatcher

BaseMatcher::UNDEFINED

Instance Attribute Summary

Attributes inherited from BaseMatcher

#actual, #expected, #rescued_exception

Instance Method Summary (collapse)

Methods inherited from BaseMatcher

#==, #description, #diffable?, #match_unless_raises

Methods included from Pretty

#_pretty_print, #expected_to_sentence, #name, #name_to_sentence, #split_words, #to_sentence, #to_word, #underscore

Constructor Details

- (YieldControl) initialize

A new instance of YieldControl

68
69
70
71
# File 'lib/rspec/matchers/built_in/yield.rb', line 68
def initialize
  @expectation_type = nil
  @expected_yields_count = nil
end

Instance Method Details

- (Object) at_least(number)

103
104
105
106
# File 'lib/rspec/matchers/built_in/yield.rb', line 103
def at_least(number)
  set_expected_yields_count(:>=, number)
  self
end

- (Object) at_most(number)

98
99
100
101
# File 'lib/rspec/matchers/built_in/yield.rb', line 98
def at_most(number)
  set_expected_yields_count(:<=, number)
  self
end

- (Object) exactly(number)

93
94
95
96
# File 'lib/rspec/matchers/built_in/yield.rb', line 93
def exactly(number)
  set_expected_yields_count(:==, number)
  self
end

- (Object) failure_message_for_should

112
113
114
115
116
# File 'lib/rspec/matchers/built_in/yield.rb', line 112
def failure_message_for_should
  'expected given block to yield control'.tap do |failure_message|
    failure_message << relativity_failure_message
  end
end

- (Object) failure_message_for_should_not

118
119
120
121
122
# File 'lib/rspec/matchers/built_in/yield.rb', line 118
def failure_message_for_should_not
  'expected given block not to yield control'.tap do |failure_message|
    failure_message << relativity_failure_message
  end
end

- (Boolean) matches?(block)

Returns:

  • (Boolean)
73
74
75
76
77
78
79
80
81
# File 'lib/rspec/matchers/built_in/yield.rb', line 73
def matches?(block)
  probe = YieldProbe.probe(block)
  if @expectation_type
    probe.num_yields.send(@expectation_type, @expected_yields_count)
  else
    probe.yielded_once?(:yield_control)
  end
end

- (Object) once

83
84
85
86
# File 'lib/rspec/matchers/built_in/yield.rb', line 83
def once
  exactly(1)
  self
end

- (Object) times

108
109
110
# File 'lib/rspec/matchers/built_in/yield.rb', line 108
def times
  self
end

- (Object) twice

88
89
90
91
# File 'lib/rspec/matchers/built_in/yield.rb', line 88
def twice
  exactly(2)
  self
end