class RubyEventStore::RSpec::BeEvent

Attributes

actual[R]
differ[R]
expected[R]
expected_data[R]
expected_metadata[R]
formatter[R]

Public Class Methods

new(expected, differ:, formatter:) click to toggle source
# File lib/ruby_event_store/rspec/be_event.rb, line 119
def initialize(expected, differ:, formatter:)
  @expected  = expected
  @differ    = differ
  @formatter = formatter
end

Public Instance Methods

data_and_metadata_expectations_description() click to toggle source
# File lib/ruby_event_store/rspec/be_event.rb, line 162
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() click to toggle source
# File lib/ruby_event_store/rspec/be_event.rb, line 158
def description
  "be an event #{formatter.(expected)}#{data_and_metadata_expectations_description}"
end
failure_message() click to toggle source
# File lib/ruby_event_store/rspec/be_event.rb, line 140
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() click to toggle source
# File lib/ruby_event_store/rspec/be_event.rb, line 146
      def failure_message_when_negated
        %Q{
expected: not a kind of #{expected}
     got: #{actual.class}
}
      end
matches?(actual) click to toggle source
# File lib/ruby_event_store/rspec/be_event.rb, line 125
def matches?(actual)
  @actual = actual
  matches_kind?(actual) && matches_data?(actual) && matches_metadata?(actual)
end
matches_kind?(actual_event) click to toggle source
# File lib/ruby_event_store/rspec/be_event.rb, line 176
def matches_kind?(actual_event)
  KindMatcher.new(expected).matches?(actual_event)
end
strict() click to toggle source
# File lib/ruby_event_store/rspec/be_event.rb, line 153
def strict
  @strict = true
  self
end
strict?() click to toggle source
# File lib/ruby_event_store/rspec/be_event.rb, line 172
def strict?
  @strict
end
with_data(expected_data) click to toggle source
# File lib/ruby_event_store/rspec/be_event.rb, line 130
def with_data(expected_data)
  @expected_data = expected_data
  self
end
with_metadata(expected_metadata) click to toggle source
# File lib/ruby_event_store/rspec/be_event.rb, line 135
def with_metadata(expected_metadata)
  @expected_metadata = expected_metadata
  self
end

Private Instance Methods

matches_data?(actual_event) click to toggle source
# File lib/ruby_event_store/rspec/be_event.rb, line 182
def matches_data?(actual_event)
  DataMatcher.new(expected_data, strict: strict?).matches?(actual_event.data)
end
matches_metadata?(actual_event) click to toggle source
# File lib/ruby_event_store/rspec/be_event.rb, line 186
def matches_metadata?(actual_event)
  DataMatcher.new(expected_metadata, strict: strict?).matches?(actual_event.metadata.to_h)
end