File: state_with_integer_value_test.rb

package info (click to toggle)
ruby-state-machines 0.100.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,600 kB
  • sloc: ruby: 18,854; sh: 17; makefile: 4
file content (36 lines) | stat: -rw-r--r-- 836 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

require 'test_helper'

class StateWithIntegerValueTest < StateMachinesTest
  def setup
    @klass = Class.new
    @machine = StateMachines::Machine.new(@klass)
    @machine.states << @state = StateMachines::State.new(@machine, :parked, value: 1)
  end

  def test_should_use_custom_value
    assert_equal 1, @state.value
  end

  def test_should_include_value_in_description
    assert_equal 'parked (1)', @state.description
  end

  def test_should_allow_human_name_in_description
    @state.human_name = 'Parked'

    assert_equal 'Parked (1)', @state.description(human_name: true)
  end

  def test_should_match_integer_value
    assert @state.matches?(1)
    refute @state.matches?(2)
  end

  def test_should_define_predicate
    object = @klass.new

    assert_respond_to object, :parked?
  end
end