Class: Recheck::Yields
- Inherits:
-
Object
- Object
- Recheck::Yields
- Defined in:
- lib/recheck/runner.rb
Instance Method Summary collapse
- #expect(hook:, reporter:) ⇒ Object
-
#initialize ⇒ Yields
constructor
A new instance of Yields.
- #raise_unless_all_reporters_yielded(hook:) ⇒ Object
- #ran(hook:, reporter:) ⇒ Object
Constructor Details
#initialize ⇒ Yields
Returns a new instance of Yields.
13 14 15 |
# File 'lib/recheck/runner.rb', line 13 def initialize @executions = {} end |
Instance Method Details
#expect(hook:, reporter:) ⇒ Object
17 18 19 20 21 |
# File 'lib/recheck/runner.rb', line 17 def expect(hook:, reporter:) @executions[hook] ||= {} @executions[hook][reporter] = false # puts "expect #{hook}, #{reporter.class.name}, id #{reporter.id}" end |
#raise_unless_all_reporters_yielded(hook:) ⇒ Object
32 33 34 35 |
# File 'lib/recheck/runner.rb', line 32 def raise_unless_all_reporters_yielded(hook:) didnt_yield = @executions[hook].filter { |reporter, ran| ran == false } raise HookDidNotYield, "Reporter(s) [#{didnt_yield.keys.join(", ")}] did not yield in their #{hook} hook" if didnt_yield.any? end |
#ran(hook:, reporter:) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/recheck/runner.rb', line 23 def ran(hook:, reporter:) raise UnexpectedHookYield, "Ran an unexpected hook #{hook} (for reporter #{reporter})" unless @executions.include? hook raise UnexpectedReporterYield, "Ran an expected hook #{hook} for an unexpected reporter #{reporter}" unless @executions[hook].include? reporter raise HookYieldedTwice, "Ran a hook #{hook} twice for reporter #{reporter}" unless @executions[hook][reporter] == false # puts "ran #{hook}, #{reporter}, #{reporter.id}" @executions[hook][reporter] = true end |