File: callback_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 (55 lines) | stat: -rw-r--r-- 1,723 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

require 'test_helper'

class CallbackTest < StateMachinesTest
  def test_should_raise_exception_if_invalid_type_specified
    exception = assert_raises(ArgumentError) { StateMachines::Callback.new(:invalid) {} }
    assert_equal 'Type must be :before, :after, :around, or :failure', exception.message
  end

  def test_should_not_raise_exception_if_using_before_type
    StateMachines::Callback.new(:before) {}
  end

  def test_should_not_raise_exception_if_using_after_type
    StateMachines::Callback.new(:after) {}
  end

  def test_should_not_raise_exception_if_using_around_type
    StateMachines::Callback.new(:around) {}
  end

  def test_should_not_raise_exception_if_using_failure_type
    StateMachines::Callback.new(:failure) {}
  end

  def test_should_raise_exception_if_no_methods_specified
    exception = assert_raises(ArgumentError) { StateMachines::Callback.new(:before) }
    assert_equal 'Method(s) for callback must be specified', exception.message
  end

  def test_should_not_raise_exception_if_method_specified_in_do_option
    StateMachines::Callback.new(:before, do: :run)
  end

  def test_should_not_raise_exception_if_method_specified_as_argument
    StateMachines::Callback.new(:before, :run)
  end

  def test_should_not_raise_exception_if_method_specified_as_block
    StateMachines::Callback.new(:before, :run) {}
  end

  def test_should_not_raise_exception_if_implicit_option_specified
    StateMachines::Callback.new(:before, do: :run, invalid: :valid)
  end

  def test_should_not_bind_to_objects
    refute StateMachines::Callback.bind_to_object
  end

  def test_should_not_have_a_terminator
    assert_nil StateMachines::Callback.terminator
  end
end