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.
139
140
141
142
143
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 139
def initialize(expected, differ:, formatter:)
@expected = expected
@differ = differ
@formatter = formatter
end
|
Instance Attribute Details
#expected ⇒ Object
Returns the value of attribute expected.
199
200
201
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 199
def expected
@expected
end
|
#expected_data ⇒ Object
Returns the value of attribute expected_data.
199
200
201
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 199
def expected_data
@expected_data
end
|
Returns the value of attribute expected_metadata.
199
200
201
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 199
def expected_metadata
@expected_metadata
end
|
Instance Method Details
191
192
193
194
195
196
197
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 191
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
187
188
189
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 187
def description
"be an event #{formatter.(expected)}#{data_and_metadata_expectations_description}"
end
|
#failure_message ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 160
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,
formatter: formatter,
).to_s
end
|
#failure_message_when_negated ⇒ Object
175
176
177
178
179
180
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 175
def failure_message_when_negated
"
expected: not a kind of #{expected}
got: #{actual.class}
"
end
|
#matches?(actual) ⇒ Boolean
145
146
147
148
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 145
def matches?(actual)
@actual = actual
matches_kind?(actual) && matches_data?(actual) && matches_metadata?(actual)
end
|
#matches_kind?(actual_event) ⇒ Boolean
205
206
207
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 205
def matches_kind?(actual_event)
KindMatcher.new(expected).matches?(actual_event)
end
|
#strict ⇒ Object
182
183
184
185
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 182
def strict
@strict = true
self
end
|
#strict? ⇒ Boolean
201
202
203
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 201
def strict?
@strict
end
|
#with_data(expected_data) ⇒ Object
150
151
152
153
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 150
def with_data(expected_data)
@expected_data = expected_data
self
end
|
155
156
157
158
|
# File 'lib/ruby_event_store/rspec/be_event.rb', line 155
def with_metadata(expected_metadata)
@expected_metadata = expected_metadata
self
end
|