Class: ActiveEventStore::HavePublishedEvent
- Inherits:
-
RSpec::Matchers::BuiltIn::BaseMatcher
- Object
- RSpec::Matchers::BuiltIn::BaseMatcher
- ActiveEventStore::HavePublishedEvent
- Defined in:
- lib/active_event_store/rspec/have_published_event.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#event_class ⇒ Object
readonly
Returns the value of attribute event_class.
-
#event_store ⇒ Object
readonly
Returns the value of attribute event_store.
Instance Method Summary collapse
- #at_least(count) ⇒ Object
- #at_most(count) ⇒ Object
- #exactly(count) ⇒ Object
-
#initialize(event_class) ⇒ HavePublishedEvent
constructor
A new instance of HavePublishedEvent.
- #matches?(block) ⇒ Boolean
- #once ⇒ Object
- #supports_block_expectations? ⇒ Boolean
- #thrice ⇒ Object
- #times ⇒ Object
- #twice ⇒ Object
- #with(attributes) ⇒ Object
- #with_store(store) ⇒ Object
Constructor Details
#initialize(event_class) ⇒ HavePublishedEvent
Returns a new instance of HavePublishedEvent.
7 8 9 10 11 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 7 def initialize(event_class) @event_class = event_class @event_store = ActiveEventStore.event_store set_expected_number(:exactly, 1) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 5 def attributes @attributes end |
#event_class ⇒ Object (readonly)
Returns the value of attribute event_class.
5 6 7 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 5 def event_class @event_class end |
#event_store ⇒ Object (readonly)
Returns the value of attribute event_store.
5 6 7 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 5 def event_store @event_store end |
Instance Method Details
#at_least(count) ⇒ Object
28 29 30 31 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 28 def at_least(count) set_expected_number(:at_least, count) self end |
#at_most(count) ⇒ Object
33 34 35 36 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 33 def at_most(count) set_expected_number(:at_most, count) self end |
#exactly(count) ⇒ Object
23 24 25 26 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 23 def exactly(count) set_expected_number(:exactly, count) self end |
#matches?(block) ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 58 def matches?(block) raise ArgumentError, "have_published_event only supports block expectations" unless block.is_a?(Proc) original_count = event_store.read.count block.call new_count = event_store.read.count - original_count in_block_events = new_count.positive? ? event_store.read.backward.limit(new_count).to_a : [] @matching_events, @unmatching_events = in_block_events.partition do |actual_event| (event_class.identifier == actual_event.event_type) && (attributes.nil? || attributes_match?(actual_event)) end @matching_count = @matching_events.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
42 43 44 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 42 def once exactly(:once) end |
#supports_block_expectations? ⇒ Boolean
54 55 56 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 54 def supports_block_expectations? true end |
#thrice ⇒ Object
50 51 52 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 50 def thrice exactly(:thrice) end |
#times ⇒ Object
38 39 40 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 38 def times self end |
#twice ⇒ Object
46 47 48 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 46 def twice exactly(:twice) end |
#with(attributes) ⇒ Object
18 19 20 21 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 18 def with(attributes) @attributes = attributes self end |
#with_store(store) ⇒ Object
13 14 15 16 |
# File 'lib/active_event_store/rspec/have_published_event.rb', line 13 def with_store(store) @event_store = store self end |