Class: RSpec::Bash::Mocks::Matchers::BaseMatcher
- Inherits:
-
Object
- Object
- RSpec::Bash::Mocks::Matchers::BaseMatcher
- Includes:
- Mocks::Matchers::Matcher
- Defined in:
- lib/rspec/bash/mocks/matchers/base_matcher.rb
Instance Attribute Summary collapse
-
#double ⇒ Object
readonly
Returns the value of attribute double.
Instance Method Summary collapse
- #and_always_return(code) ⇒ Object
- #and_always_yield(subshell: true, &body) ⇒ Object
- #and_call_original ⇒ Object
- #and_return(code, times: 1) ⇒ Object
- #and_yield(subshell: true, times: 1, &body) ⇒ Object
- #at_least(n) ⇒ Object
- #at_most(n) ⇒ Object
- #exactly(n) ⇒ Object
-
#initialize ⇒ BaseMatcher
constructor
A new instance of BaseMatcher.
-
#matches?(subject, &block) ⇒ Boolean
(RSpec::Bash::Script): RSpec::Bash::Mocks::ScriptMessageExpectation.
- #name ⇒ Object
- #never ⇒ Object
- #once ⇒ Object
-
#setup_allowance(subject, &block) ⇒ Object
(RSpec::Bash::Script): RSpec::Bash::Mocks::ScriptMessageExpectation.
- #thrice ⇒ Object
- #times ⇒ Object
- #twice ⇒ Object
- #with_args(args) ⇒ Object
Constructor Details
#initialize ⇒ BaseMatcher
Returns a new instance of BaseMatcher.
13 14 15 16 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 13 def initialize() fail "@double must be created by implementation" if @double.nil? fail "@display_name must be specified by implementation" if @display_name.nil? end |
Instance Attribute Details
#double ⇒ Object (readonly)
Returns the value of attribute double.
11 12 13 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 11 def double @double end |
Instance Method Details
#and_always_return(code) ⇒ Object
44 45 46 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 44 def and_always_return(code) and_return(code, times: Float::INFINITY) end |
#and_always_yield(subshell: true, &body) ⇒ Object
48 49 50 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 48 def and_always_yield(subshell: true, &body) and_yield(subshell: subshell, times: Float::INFINITY, &body) end |
#and_call_original ⇒ Object
74 75 76 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 74 def and_call_original tap { @double.call_original = true } end |
#and_return(code, times: 1) ⇒ Object
40 41 42 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 40 def and_return(code, times: 1) and_yield(subshell: false, times: times) { |*| "return #{code}" } end |
#and_yield(subshell: true, times: 1, &body) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 29 def and_yield(subshell: true, times: 1, &body) tap { @double.subshell = subshell behavior = find_last_blank_or_create_behavior behavior[:body] = body behavior[:charges] = behavior[:charges] == 0 ? times : behavior[:charges] behavior[:subshell] = subshell } end |
#at_least(n) ⇒ Object
66 67 68 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 66 def at_least(n) tap { @double.expected_call_count = [:at_least, n] } end |
#at_most(n) ⇒ Object
70 71 72 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 70 def at_most(n) tap { @double.expected_call_count = [:at_most, n] } end |
#exactly(n) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 52 def exactly(n) tap do if @double.behaviors.last @double.behaviors.last[:charges] = n (n-1).times do @double.expected_calls << @double.expected_calls.last end else @double.expected_call_count = [:exactly, n] end end end |
#matches?(subject, &block) ⇒ Boolean
(RSpec::Bash::Script): RSpec::Bash::Mocks::ScriptMessageExpectation
101 102 103 104 105 106 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 101 def matches?(subject, &block) proxy_for(subject).( double: @double, display_name: @display_name ) end |
#name ⇒ Object
18 19 20 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 18 def name @display_name end |
#never ⇒ Object
78 79 80 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 78 def never exactly(0) end |
#once ⇒ Object
82 83 84 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 82 def once exactly(1) end |
#setup_allowance(subject, &block) ⇒ Object
(RSpec::Bash::Script): RSpec::Bash::Mocks::ScriptMessageExpectation
111 112 113 114 115 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 111 def setup_allowance(subject, &block) proxy_for(subject).( double: @double ) end |
#thrice ⇒ Object
90 91 92 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 90 def thrice exactly(3) end |
#times ⇒ Object
94 95 96 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 94 def times self end |
#twice ⇒ Object
86 87 88 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 86 def twice exactly(2) end |
#with_args(args) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 22 def with_args(args) tap { @double.expected_calls << args @double.behaviors << create_behavior({ args: args }) } end |