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

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

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

#initializeYieldControl

Returns 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

#at_least(number) ⇒ Object



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

#at_most(number) ⇒ Object



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

#exactly(number) ⇒ Object



93
94
95
96
# File 'lib/rspec/matchers/built_in/yield.rb', line 93

def exactly(number)
  set_expected_yields_count(:==, number)
  self
end

#failure_message_for_shouldObject



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

#failure_message_for_should_notObject



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

#matches?(block) ⇒ Boolean

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

#onceObject



83
84
85
86
# File 'lib/rspec/matchers/built_in/yield.rb', line 83

def once
  exactly(1)
  self
end

#timesObject



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

def times
  self
end

#twiceObject



88
89
90
91
# File 'lib/rspec/matchers/built_in/yield.rb', line 88

def twice
  exactly(2)
  self
end