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_call_original ⇒ Object
- #and_return(code) ⇒ Object
- #and_yield(subshell: true, &block) ⇒ 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_call_original ⇒ Object
49 50 51 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 49 def and_call_original tap { @double.call_original = true } end |
#and_return(code) ⇒ Object
26 27 28 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 26 def and_return(code) tap { @double.body = lambda { |*| "return #{code}" } } end |
#and_yield(subshell: true, &block) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 30 def and_yield(subshell: true, &block) tap { @double.body = block @double.subshell = subshell } end |
#at_least(n) ⇒ Object
41 42 43 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 41 def at_least(n) tap { @double.expected_call_count = [:at_least, n] } end |
#at_most(n) ⇒ Object
45 46 47 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 45 def at_most(n) tap { @double.expected_call_count = [:at_most, n] } end |
#exactly(n) ⇒ Object
37 38 39 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 37 def exactly(n) tap { @double.expected_call_count = [:exactly, n] } end |
#matches?(subject, &block) ⇒ Boolean
(RSpec::Bash::Script): RSpec::Bash::Mocks::ScriptMessageExpectation
76 77 78 79 80 81 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 76 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
53 54 55 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 53 def never exactly(0) end |
#once ⇒ Object
57 58 59 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 57 def once exactly(1) end |
#setup_allowance(subject, &block) ⇒ Object
(RSpec::Bash::Script): RSpec::Bash::Mocks::ScriptMessageExpectation
86 87 88 89 90 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 86 def setup_allowance(subject, &block) proxy_for(subject).( double: @double ) end |
#thrice ⇒ Object
65 66 67 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 65 def thrice exactly(3) end |
#times ⇒ Object
69 70 71 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 69 def times self end |
#twice ⇒ Object
61 62 63 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 61 def twice exactly(2) end |
#with_args(args) ⇒ Object
22 23 24 |
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 22 def with_args(args) tap { @double.expected_calls << args } end |