Class: RubyEventStore::RSpec::BeEvent
- Inherits:
-
Object
- Object
- RubyEventStore::RSpec::BeEvent
show all
- Includes:
- RSpec::Matchers::Composable
- Defined in:
- lib/ruby_event_store/rspec/be_event.rb
Defined Under Namespace
Classes: DataMatcher, FailureMessage, KindMatcher
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(expected, differ:, formatter:) ⇒ BeEvent
Returns a new instance of BeEvent.
127
128
129
130
131
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 127
def initialize(expected, differ:, formatter:)
@expected = expected
@differ = differ
@formatter = formatter
end
|
Instance Attribute Details
#expected ⇒ Object
Returns the value of attribute expected.
186
187
188
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 186
def expected
@expected
end
|
#expected_data ⇒ Object
Returns the value of attribute expected_data.
186
187
188
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 186
def expected_data
@expected_data
end
|
Returns the value of attribute expected_metadata.
186
187
188
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 186
def expected_metadata
@expected_metadata
end
|
Instance Method Details
178
179
180
181
182
183
184
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 178
def data_and_metadata_expectations_description
predicate = strict? ? "matching" : "including"
expectation_list = []
expectation_list << "with data #{predicate} #{formatter.(expected_data)}" if expected_data
expectation_list << "with metadata #{predicate} #{formatter.(expected_metadata)}" if expected_metadata
" (#{expectation_list.join(" and ")})" if expectation_list.any?
end
|
#description ⇒ Object
174
175
176
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 174
def description
"be an event #{formatter.(expected)}#{data_and_metadata_expectations_description}"
end
|
#failure_message ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 148
def failure_message
actual_data = actual.data if actual.respond_to?(:data)
actual_metadata = actual.metadata if actual.respond_to?(:metadata)
FailureMessage.new(
expected,
actual.class,
expected_data,
actual_data,
expected_metadata,
actual_metadata,
differ: differ
).to_s
end
|
#failure_message_when_negated ⇒ Object
162
163
164
165
166
167
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 162
def failure_message_when_negated
"
expected: not a kind of #{expected}
got: #{actual.class}
"
end
|
#matches?(actual) ⇒ Boolean
133
134
135
136
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 133
def matches?(actual)
@actual = actual
matches_kind?(actual) && matches_data?(actual) && matches_metadata?(actual)
end
|
#matches_kind?(actual_event) ⇒ Boolean
192
193
194
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 192
def matches_kind?(actual_event)
KindMatcher.new(expected).matches?(actual_event)
end
|
#strict ⇒ Object
169
170
171
172
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 169
def strict
@strict = true
self
end
|
#strict? ⇒ Boolean
188
189
190
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 188
def strict?
@strict
end
|
#with_data(expected_data) ⇒ Object
138
139
140
141
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 138
def with_data(expected_data)
@expected_data = expected_data
self
end
|
143
144
145
146
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 143
def with_metadata(expected_metadata)
@expected_metadata = expected_metadata
self
end
|