Class: RSpec::Bash::Mocks::ScriptMessageExpectation

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/bash/mocks/script_message_expectation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(double:, display_name:, error_generator:, backtrace_line: nil) ⇒ ScriptMessageExpectation

Returns a new instance of ScriptMessageExpectation.



11
12
13
14
15
16
17
18
# File 'lib/rspec/bash/mocks/script_message_expectation.rb', line 11

def initialize(double:, display_name:, error_generator:, backtrace_line: nil)
  @double = double
  @display_name = display_name
  @error_generator = error_generator
  @backtrace_line = backtrace_line
  @expected_args = double.expected_calls
  @message = @display_name
end

Instance Attribute Details

#expected_argsObject (readonly)

Returns the value of attribute expected_args.



9
10
11
# File 'lib/rspec/bash/mocks/script_message_expectation.rb', line 9

def expected_args
  @expected_args
end

#messageObject (readonly)

Returns the value of attribute message.



9
10
11
# File 'lib/rspec/bash/mocks/script_message_expectation.rb', line 9

def message
  @message
end

Instance Method Details

#called_max_times?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/rspec/bash/mocks/script_message_expectation.rb', line 26

def called_max_times?(*)
  false
end

#invokeObject



20
21
# File 'lib/rspec/bash/mocks/script_message_expectation.rb', line 20

def invoke(*)
end

#matches?Boolean

Returns:

  • (Boolean)


23
24
# File 'lib/rspec/bash/mocks/script_message_expectation.rb', line 23

def matches?(*)
end

#unadviseObject



73
74
# File 'lib/rspec/bash/mocks/script_message_expectation.rb', line 73

def unadvise(*)
end

#verify_messages_received(script) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rspec/bash/mocks/script_message_expectation.rb', line 30

def verify_messages_received(script)
  type, expected_count = *@double.expected_call_count
  actual_count = @double.call_count(script)

  report = lambda {
    @error_generator.raise_expectation_error(
      @display_name,
      expected_count,
      ::RSpec::Mocks::ArgumentListMatcher::MATCH_ALL,
      actual_count,
      nil,
      Array(@double.to_s),
      @backtrace_line
    )
  }

  case type
  when :at_least
    report[] if actual_count < expected_count
  when :at_most
    report[] if actual_count > expected_count
  when :exactly
    report[] if actual_count != expected_count
  else
    fail "Unrecognized call-count quantifier \"#{type}\""
  end

  @double.call_args(script).tap do |actual_args|
    @double.expected_calls.each_with_index do |args, index|
      expected = args
      actual = actual_args[index]

      if actual != expected
        @error_generator.raise_unexpected_message_args_error(
          self,
          actual_args.map { |x| Array(x) },
        )
        break
      end
    end
  end
end