Class: RubyEventStore::RSpec::BeEvent

Inherits:
Object
  • Object
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

#expectedObject (readonly)

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_dataObject (readonly)

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

#expected_metadataObject (readonly)

Returns the value of attribute expected_metadata.


186
187
188
# File 'lib/ruby_event_store/rspec/be_event.rb', line 186

def 
  @expected_metadata
end

Instance Method Details

#data_and_metadata_expectations_descriptionObject


178
179
180
181
182
183
184
# File 'lib/ruby_event_store/rspec/be_event.rb', line 178

def 
  predicate = strict? ? "matching" : "including"
  expectation_list = []
  expectation_list << "with data #{predicate} #{formatter.(expected_data)}" if expected_data
  expectation_list << "with metadata #{predicate} #{formatter.()}" if 
  " (#{expectation_list.join(" and ")})" if expectation_list.any?
end

#descriptionObject


174
175
176
# File 'lib/ruby_event_store/rspec/be_event.rb', line 174

def description
  "be an event #{formatter.(expected)}#{}"
end

#failure_messageObject


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. if actual.respond_to?(:metadata)
  FailureMessage.new(
    expected,
    actual.class,
    expected_data,
    actual_data,
    ,
    ,
    differ: differ
  ).to_s
end

#failure_message_when_negatedObject


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

Returns:

  • (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

Returns:

  • (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

#strictObject


169
170
171
172
# File 'lib/ruby_event_store/rspec/be_event.rb', line 169

def strict
  @strict = true
  self
end

#strict?Boolean

Returns:

  • (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

#with_metadata(expected_metadata) ⇒ Object


143
144
145
146
# File 'lib/ruby_event_store/rspec/be_event.rb', line 143

def ()
  @expected_metadata = 
  self
end