Class: AbstractNotifier::HaveSentNotification
- Inherits:
-
RSpec::Matchers::BuiltIn::BaseMatcher
- Object
- RSpec::Matchers::BuiltIn::BaseMatcher
- AbstractNotifier::HaveSentNotification
- Defined in:
- lib/abstract_notifier/testing/rspec.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Instance Method Summary collapse
- #at_least(count) ⇒ Object
- #at_most(count) ⇒ Object
- #exactly(count) ⇒ Object
-
#initialize(payload = nil) ⇒ HaveSentNotification
constructor
A new instance of HaveSentNotification.
- #matches?(proc) ⇒ Boolean
- #once ⇒ Object
- #supports_block_expectations? ⇒ Boolean
- #thrice ⇒ Object
- #times ⇒ Object
- #twice ⇒ Object
Constructor Details
#initialize(payload = nil) ⇒ HaveSentNotification
Returns a new instance of HaveSentNotification.
7 8 9 10 |
# File 'lib/abstract_notifier/testing/rspec.rb', line 7 def initialize(payload = nil) @payload = payload set_expected_number(:exactly, 1) end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/abstract_notifier/testing/rspec.rb', line 5 def payload @payload end |
Instance Method Details
#at_least(count) ⇒ Object
17 18 19 20 |
# File 'lib/abstract_notifier/testing/rspec.rb', line 17 def at_least(count) set_expected_number(:at_least, count) self end |
#at_most(count) ⇒ Object
22 23 24 25 |
# File 'lib/abstract_notifier/testing/rspec.rb', line 22 def at_most(count) set_expected_number(:at_most, count) self end |
#exactly(count) ⇒ Object
12 13 14 15 |
# File 'lib/abstract_notifier/testing/rspec.rb', line 12 def exactly(count) set_expected_number(:exactly, count) self end |
#matches?(proc) ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/abstract_notifier/testing/rspec.rb', line 47 def matches?(proc) raise ArgumentError, "have_sent_notification only supports block expectations" unless Proc === proc raise "You can only use have_sent_notification matcher in :test delivery mode" unless AbstractNotifier.test? original_deliveries_count = deliveries.count proc.call in_block_deliveries = deliveries.drop(original_deliveries_count) @matching_deliveries, @unmatching_deliveries = in_block_deliveries.partition do |actual_payload| payload.nil? || (payload === actual_payload) end @matching_count = @matching_deliveries.size case @expectation_type when :exactly then @expected_number == @matching_count when :at_most then @expected_number >= @matching_count when :at_least then @expected_number <= @matching_count end end |
#once ⇒ Object
31 32 33 |
# File 'lib/abstract_notifier/testing/rspec.rb', line 31 def once exactly(:once) end |
#supports_block_expectations? ⇒ Boolean
43 44 45 |
# File 'lib/abstract_notifier/testing/rspec.rb', line 43 def supports_block_expectations? true end |
#thrice ⇒ Object
39 40 41 |
# File 'lib/abstract_notifier/testing/rspec.rb', line 39 def thrice exactly(:thrice) end |
#times ⇒ Object
27 28 29 |
# File 'lib/abstract_notifier/testing/rspec.rb', line 27 def times self end |
#twice ⇒ Object
35 36 37 |
# File 'lib/abstract_notifier/testing/rspec.rb', line 35 def twice exactly(:twice) end |