Class: Telegram::Bot::RSpec::ArgListMatcher
- Inherits:
-
Object
- Object
- Telegram::Bot::RSpec::ArgListMatcher
- 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
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
-
#expected_proc ⇒ Object
readonly
Returns the value of attribute expected_proc.
Instance Method Summary collapse
- #args ⇒ Object
- #args_match?(*actual) ⇒ Boolean
-
#initialize(*args, &block) ⇒ ArgListMatcher
constructor
A new instance of ArgListMatcher.
- #mocks_matcher? ⇒ Boolean
- #to_s ⇒ Object
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
#expected ⇒ Object (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_proc ⇒ Object (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
#args ⇒ Object
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
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
38 39 40 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 38 def mocks_matcher? defined?(::RSpec::Mocks::ArgumentListMatcher) end |
#to_s ⇒ Object
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 |