Class: Hiiro::Effects::NullExecutor
- Inherits:
-
Object
- Object
- Hiiro::Effects::NullExecutor
- Defined in:
- lib/hiiro/effects.rb
Overview
Instance Attribute Summary collapse
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
Instance Method Summary collapse
-
#called?(pattern) ⇒ Boolean
Returns true if any recorded call contains pattern as a substring of any arg.
-
#calls_to(method) ⇒ Object
Returns all calls to a given method (:capture, :run, :check).
- #capture(*args) ⇒ Object
- #check(*args) ⇒ Object
-
#initialize ⇒ NullExecutor
constructor
A new instance of NullExecutor.
-
#reset! ⇒ Object
Clear all recorded calls (useful between test assertions).
- #run(*args) ⇒ Object
-
#stub(pattern, output = '') ⇒ Object
Register a stub.
Constructor Details
#initialize ⇒ NullExecutor
Returns a new instance of NullExecutor.
23 24 25 26 |
# File 'lib/hiiro/effects.rb', line 23 def initialize @calls = [] @stubs = {} end |
Instance Attribute Details
#calls ⇒ Object (readonly)
Returns the value of attribute calls.
21 22 23 |
# File 'lib/hiiro/effects.rb', line 21 def calls @calls end |
Instance Method Details
#called?(pattern) ⇒ Boolean
Returns true if any recorded call contains pattern as a substring of any arg.
51 52 53 |
# File 'lib/hiiro/effects.rb', line 51 def called?(pattern) @calls.any? { |c| c[:args].any? { |a| a.to_s.include?(pattern.to_s) } } end |
#calls_to(method) ⇒ Object
Returns all calls to a given method (:capture, :run, :check).
56 57 58 |
# File 'lib/hiiro/effects.rb', line 56 def calls_to(method) @calls.select { |c| c[:method] == method } end |
#capture(*args) ⇒ Object
33 34 35 36 |
# File 'lib/hiiro/effects.rb', line 33 def capture(*args) record(:capture, args) find_stub(args) || '' end |
#check(*args) ⇒ Object
44 45 46 47 48 |
# File 'lib/hiiro/effects.rb', line 44 def check(*args) record(:check, args) result = find_stub(args) result.nil? ? true : !!result end |
#reset! ⇒ Object
Clear all recorded calls (useful between test assertions).
61 62 63 |
# File 'lib/hiiro/effects.rb', line 61 def reset! @calls = [] end |
#run(*args) ⇒ Object
38 39 40 41 42 |
# File 'lib/hiiro/effects.rb', line 38 def run(*args) record(:run, args) result = find_stub(args) result.nil? ? true : result end |
#stub(pattern, output = '') ⇒ Object
Register a stub. pattern is matched as a substring of the joined args string.
29 30 31 |
# File 'lib/hiiro/effects.rb', line 29 def stub(pattern, output = '') @stubs[pattern.to_s] = output end |