Class: Telegram::Bot::RSpec::ClientMatchers::MakeTelegramRequest
- Inherits:
-
RSpec::Matchers::BuiltIn::BaseMatcher
- Object
- RSpec::Matchers::BuiltIn::BaseMatcher
- Telegram::Bot::RSpec::ClientMatchers::MakeTelegramRequest
- Defined in:
- lib/telegram/bot/rspec/client_matchers.rb
Constant Summary collapse
- EXPECTATION_TYPES =
{ exactly: :==, at_most: :>=, at_least: :<=, }.freeze
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#performed_requests ⇒ Object
readonly
Returns the value of attribute performed_requests.
Instance Method Summary collapse
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(bot, action, description: nil) ⇒ MakeTelegramRequest
constructor
A new instance of MakeTelegramRequest.
-
#matches?(proc) ⇒ Boolean
rubocop:disable AbcSize.
- #supports_block_expectations? ⇒ Boolean
- #times ⇒ Object
- #with(*args, &block) ⇒ Object
Constructor Details
#initialize(bot, action, description: nil) ⇒ MakeTelegramRequest
Returns a new instance of MakeTelegramRequest.
64 65 66 67 68 69 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 64 def initialize(bot, action, description: nil) @bot = bot @action = action @description = description || "make #{action} telegram request" exactly(1) end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
62 63 64 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 62 def description @description end |
#performed_requests ⇒ Object (readonly)
Returns the value of attribute performed_requests.
62 63 64 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 62 def performed_requests @performed_requests end |
Instance Method Details
#failure_message ⇒ Object
100 101 102 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 100 def "expected to #{}" end |
#failure_message_when_negated ⇒ Object
104 105 106 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 104 def "expected not to #{}" end |
#matches?(proc) ⇒ Boolean
rubocop:disable AbcSize
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 71 def matches?(proc) # rubocop:disable AbcSize raise ArgumentError, 'matcher only supports block expectations' unless proc.is_a?(Proc) original_requests_count = bot.requests[action].count proc.call @performed_requests = bot.requests[action].drop(original_requests_count) @matching_requests_count = performed_requests.count do |request| !arg_list_matcher || arg_list_matcher.args_match?(request) end expectation_method = EXPECTATION_TYPES[expectation_type] expected_number.public_send(expectation_method, matching_requests_count) end |
#supports_block_expectations? ⇒ Boolean
108 109 110 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 108 def supports_block_expectations? true end |
#times ⇒ Object
96 97 98 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 96 def times self end |
#with(*args, &block) ⇒ Object
83 84 85 86 |
# File 'lib/telegram/bot/rspec/client_matchers.rb', line 83 def with(*args, &block) @arg_list_matcher = ArgListMatcher.new(*args, &block) self end |