Class: Statecraft::RSpec::HaveTransitionedTo

Inherits:
Object
  • Object
show all
Defined in:
lib/statecraft/rspec/have_transitioned_to.rb

Overview

expect(record).to have_transitioned_to(:paid)

Strictly log-based, like transitioned_to? itself: the question is about history, never about the current state. The failure message shows what the log actually holds.

Instance Method Summary collapse

Constructor Details

#initialize(state_name) ⇒ HaveTransitionedTo

Returns a new instance of HaveTransitionedTo.



11
12
13
# File 'lib/statecraft/rspec/have_transitioned_to.rb', line 11

def initialize(state_name)
  @state_name = state_name.to_sym
end

Instance Method Details

#descriptionObject



30
31
32
# File 'lib/statecraft/rspec/have_transitioned_to.rb', line 30

def description
  "have transitioned to #{@state_name.inspect}"
end

#failure_messageObject



20
21
22
23
# File 'lib/statecraft/rspec/have_transitioned_to.rb', line 20

def failure_message
  "expected the log of #{StateReport.standing(@record)} to hold a transition to #{@state_name.inspect}, " \
    "but #{log_contents}"
end

#failure_message_when_negatedObject



25
26
27
28
# File 'lib/statecraft/rspec/have_transitioned_to.rb', line 25

def failure_message_when_negated
  "expected the log of #{StateReport.standing(@record)} to hold no transition to #{@state_name.inspect}, " \
    "but it does"
end

#matches?(record) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/statecraft/rspec/have_transitioned_to.rb', line 15

def matches?(record)
  @record = record
  record.transitioned_to?(@state_name)
end