Module: RSpec::Risky::Probe::ExpectationProbe

Defined in:
lib/rspec/risky/probe/expectation_probe.rb

Defined Under Namespace

Modules: HaveReceivedPatch, ReceiveMessageChainPatch, ReceiveMessagesPatch, ReceivePatch, ShouldSyntaxPatch, StandardExpectationPatch Classes: State

Constant Summary collapse

THREAD_KEY =
:__rspec_risky_expectation_probe_state

Class Method Summary collapse

Class Method Details

.finish(state) ⇒ Object



124
125
126
127
128
# File 'lib/rspec/risky/probe/expectation_probe.rb', line 124

def finish(state)
  state.mock_expectation_count = [state.mock_expectation_count, verified_mock_expectation_count].max if state
  Thread.current[THREAD_KEY] = state.previous_state if state
  state
end

.installObject



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/rspec/risky/probe/expectation_probe.rb', line 101

def install
  return if @installed

  ::RSpec::Expectations::ExpectationTarget.prepend(StandardExpectationPatch)
  ::RSpec::Mocks::Matchers::Receive.prepend(ReceivePatch)
  ::RSpec::Mocks::Matchers::ReceiveMessages.prepend(ReceiveMessagesPatch)
  ::RSpec::Mocks::Matchers::ReceiveMessageChain.prepend(ReceiveMessageChainPatch)
  ::RSpec::Mocks::Matchers::HaveReceived.prepend(HaveReceivedPatch)
  ::RSpec::Mocks.singleton_class.prepend(ShouldSyntaxPatch)

  @installed = true
end

.record_custom_expectation(count = 1) ⇒ Object



144
145
146
147
148
# File 'lib/rspec/risky/probe/expectation_probe.rb', line 144

def record_custom_expectation(count = 1)
  return unless current

  current.custom_expectation_count += count
end

.record_expectation(count = 1) ⇒ Object



130
131
132
133
134
# File 'lib/rspec/risky/probe/expectation_probe.rb', line 130

def record_expectation(count = 1)
  return unless current

  current.expectation_count += count
end

.record_mock_expectation(count = 1) ⇒ Object Also known as: record_declared_mock_expectation



136
137
138
139
140
# File 'lib/rspec/risky/probe/expectation_probe.rb', line 136

def record_mock_expectation(count = 1)
  return unless current

  current.mock_expectation_count += count
end

.start(example) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/rspec/risky/probe/expectation_probe.rb', line 114

def start(example)
  State.new(
    example: example,
    expectation_count: 0,
    mock_expectation_count: 0,
    custom_expectation_count: 0,
    previous_state: current
  ).tap { |state| Thread.current[THREAD_KEY] = state }
end