Module: MiniTest::Assertions

Defined in:
lib/aasm/minitest/allow_transition_to.rb,
lib/aasm/minitest/transition_from.rb,
lib/aasm/minitest/allow_event.rb,
lib/aasm/minitest/have_state.rb

Instance Method Summary collapse

Instance Method Details

#_transitions_from?(object, from_state, args, options) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
# File 'lib/aasm/minitest/transition_from.rb', line 16

def _transitions_from?(object, from_state, args, options)
  state_machine_name = options[:on]
  object.aasm(state_machine_name).current_state = from_state.to_sym
  object.send(options[:on_event], *args) && options[:to].to_sym == object.aasm(state_machine_name).current_state
end

#assert_event_allowed(object, event, options = {}) ⇒ Object



2
3
4
5
6
# File 'lib/aasm/minitest/allow_event.rb', line 2

def assert_event_allowed(object, event, options = {})
  state_machine_name = options.fetch(:on, :default)
  assert object.aasm(state_machine_name).may_fire_event?(event),
        "Expected that the event :#{event} would be allowed (on :#{state_machine_name})"
end

#assert_have_state(object, state, options = {}) ⇒ Object



2
3
4
5
6
# File 'lib/aasm/minitest/have_state.rb', line 2

def assert_have_state(object, state, options = {})
  state_machine_name = options.fetch(:on, :default)
  assert object.aasm(state_machine_name).current_state == state,
       "Expected that :#{object.aasm(state_machine_name).current_state} would be :#{state} (on :#{state_machine_name})"
end

#assert_transition_to_allowed(object, to_state, options = {}) ⇒ Object



2
3
4
5
6
# File 'lib/aasm/minitest/allow_transition_to.rb', line 2

def assert_transition_to_allowed(object, to_state, options = {})
  state_machine_name = options.fetch(:on, :default)
  assert object.aasm(state_machine_name).states(permitted: true).include?(to_state),
         "Expected that the state :#{to_state} would be reachable (on :#{state_machine_name})"
end

#assert_transitions_from(object, from_state, *args) ⇒ Object



2
3
4
5
6
7
# File 'lib/aasm/minitest/transition_from.rb', line 2

def assert_transitions_from(object, from_state, *args)
  options = args.first
  options[:on] ||= :default
  assert _transitions_from?(object, from_state, args, options),
        "Expected transition state to :#{options[:to]} from :#{from_state} on event :#{options[:on_event]}, (on :#{options[:on]})"
end

#refute_event_allowed(object, event, options = {}) ⇒ Object



8
9
10
11
12
# File 'lib/aasm/minitest/allow_event.rb', line 8

def refute_event_allowed(object, event, options = {})
  state_machine_name = options.fetch(:on, :default)
  refute object.aasm(state_machine_name).may_fire_event?(event),
        "Expected that the event :#{event} would not be allowed (on :#{state_machine_name})"
end

#refute_have_state(object, state, options = {}) ⇒ Object



8
9
10
11
12
# File 'lib/aasm/minitest/have_state.rb', line 8

def refute_have_state(object, state, options = {})
  state_machine_name = options.fetch(:on, :default)
  refute object.aasm(state_machine_name).current_state == state,
       "Expected that :#{object.aasm(state_machine_name).current_state} would be :#{state} (on :#{state_machine_name})"
end

#refute_transition_to_allowed(object, to_state, options = {}) ⇒ Object



8
9
10
11
12
# File 'lib/aasm/minitest/allow_transition_to.rb', line 8

def refute_transition_to_allowed(object, to_state, options = {})
  state_machine_name = options.fetch(:on, :default)
  refute object.aasm(state_machine_name).states(permitted: true).include?(to_state),
         "Expected that the state :#{to_state} would be reachable (on :#{state_machine_name})"
end

#refute_transitions_from(object, from_state, *args) ⇒ Object



9
10
11
12
13
14
# File 'lib/aasm/minitest/transition_from.rb', line 9

def refute_transitions_from(object, from_state, *args)
  options = args.first
  options[:on] ||= :default
  refute _transitions_from?(object, from_state, args, options),
        "Expected transition state to :#{options[:to]} from :#{from_state} on event :#{options[:on_event]}, (on :#{options[:on]})"
end