Class: Telegram::Bot::RSpec::ArgListMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram/bot/rspec/client_matchers.rb

Overview

Proxy that uses RSpec::Mocks::ArgListMatcher when it’s available. Otherwise just performs ‘#==` match.

Also allows to check argumets with custom block.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ ArgListMatcher

Returns a new instance of ArgListMatcher.



11
12
13
14
15
16
17
18
19
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 11

def initialize(*args, &block)
  @expected_proc = block if block_given?
  @expected =
    if mocks_matcher?
      ::RSpec::Mocks::ArgumentListMatcher.new(*args)
    else
      args
    end
end

Instance Attribute Details

#expectedObject (readonly)

Returns the value of attribute expected.



9
10
11
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 9

def expected
  @expected
end

#expected_procObject (readonly)

Returns the value of attribute expected_proc.



9
10
11
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 9

def expected_proc
  @expected_proc
end

Instance Method Details

#argsObject



32
33
34
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 32

def args
  mocks_matcher? ? expected.args : expected
end

#args_match?(*actual) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 21

def args_match?(*actual)
  if expected_proc
    expected_proc[*actual]
    true
  elsif mocks_matcher?
    expected.args_match?(*actual)
  else
    expected == actual
  end
end

#mocks_matcher?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 36

def mocks_matcher?
  defined?(::RSpec::Mocks::ArgumentListMatcher)
end

#to_sObject



40
41
42
43
44
45
46
47
48
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 40

def to_s
  if mocks_matcher?
    expected.expected_args.inspect
  elsif expected_proc
    '(proc matcher)'
  else
    expected.inspect
  end
end