Class: RSpec::Bash::Mocks::Matchers::BaseMatcher

Inherits:
Object
  • Object
show all
Includes:
Mocks::Matchers::Matcher
Defined in:
lib/rspec/bash/mocks/matchers/base_matcher.rb

Direct Known Subclasses

Receive, Test

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBaseMatcher

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

#doubleObject (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_originalObject



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

Returns:

  • (Boolean)


76
77
78
79
80
81
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 76

def matches?(subject, &block)
  proxy_for(subject).expect_message(
    double: @double,
    display_name: @display_name
  )
end

#nameObject



18
19
20
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 18

def name
  @display_name
end

#neverObject



53
54
55
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 53

def never
  exactly(0)
end

#onceObject



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).allow_message(
    double: @double
  )
end

#thriceObject



65
66
67
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 65

def thrice
  exactly(3)
end

#timesObject



69
70
71
# File 'lib/rspec/bash/mocks/matchers/base_matcher.rb', line 69

def times
  self
end

#twiceObject



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