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.



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

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.



11
12
13
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 11

def expected
  @expected
end

#expected_procObject (readonly)

Returns the value of attribute expected_proc.



11
12
13
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 11

def expected_proc
  @expected_proc
end

Instance Method Details

#argsObject



34
35
36
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 34

def args
  mocks_matcher? ? expected.args : expected
end

#args_match?(*actual) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


38
39
40
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 38

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

#to_sObject



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

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