finite_machine 0.12.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -1
  3. data/README.md +1 -1
  4. data/lib/finite_machine.rb +3 -1
  5. data/lib/finite_machine/choice_merger.rb +2 -2
  6. data/lib/finite_machine/dsl.rb +4 -4
  7. data/lib/finite_machine/message_queue.rb +0 -1
  8. data/lib/finite_machine/state_machine.rb +3 -3
  9. data/lib/finite_machine/two_phase_lock.rb +6 -6
  10. data/lib/finite_machine/version.rb +1 -1
  11. metadata +20 -146
  12. data/Rakefile +0 -12
  13. data/benchmarks/memory_profile.rb +0 -11
  14. data/benchmarks/memory_usage.rb +0 -28
  15. data/examples/atm.rb +0 -45
  16. data/examples/bug_system.rb +0 -145
  17. data/finite_machine.gemspec +0 -30
  18. data/spec/integration/system_spec.rb +0 -93
  19. data/spec/performance/benchmark_spec.rb +0 -54
  20. data/spec/spec_helper.rb +0 -34
  21. data/spec/unit/alias_target_spec.rb +0 -89
  22. data/spec/unit/async_callbacks_spec.rb +0 -28
  23. data/spec/unit/auto_methods_spec.rb +0 -44
  24. data/spec/unit/callable/call_spec.rb +0 -111
  25. data/spec/unit/callbacks_spec.rb +0 -851
  26. data/spec/unit/can_spec.rb +0 -88
  27. data/spec/unit/cancel_callbacks_spec.rb +0 -46
  28. data/spec/unit/choice_spec.rb +0 -295
  29. data/spec/unit/define_spec.rb +0 -55
  30. data/spec/unit/definition_spec.rb +0 -98
  31. data/spec/unit/event_names_spec.rb +0 -15
  32. data/spec/unit/events_map/add_spec.rb +0 -23
  33. data/spec/unit/events_map/choice_transition_spec.rb +0 -25
  34. data/spec/unit/events_map/clear_spec.rb +0 -13
  35. data/spec/unit/events_map/events_spec.rb +0 -16
  36. data/spec/unit/events_map/inspect_spec.rb +0 -22
  37. data/spec/unit/events_map/match_transition_spec.rb +0 -35
  38. data/spec/unit/events_map/move_to_spec.rb +0 -45
  39. data/spec/unit/events_map/states_for_spec.rb +0 -17
  40. data/spec/unit/events_spec.rb +0 -390
  41. data/spec/unit/handlers_spec.rb +0 -120
  42. data/spec/unit/hook_event/any_state_or_event_spec.rb +0 -13
  43. data/spec/unit/hook_event/build_spec.rb +0 -13
  44. data/spec/unit/hook_event/eql_spec.rb +0 -34
  45. data/spec/unit/hook_event/initialize_spec.rb +0 -23
  46. data/spec/unit/hook_event/notify_spec.rb +0 -12
  47. data/spec/unit/hooks/clear_spec.rb +0 -16
  48. data/spec/unit/hooks/find_spec.rb +0 -19
  49. data/spec/unit/hooks/inspect_spec.rb +0 -25
  50. data/spec/unit/hooks/register_spec.rb +0 -17
  51. data/spec/unit/if_unless_spec.rb +0 -314
  52. data/spec/unit/initial_spec.rb +0 -190
  53. data/spec/unit/inspect_spec.rb +0 -22
  54. data/spec/unit/is_spec.rb +0 -49
  55. data/spec/unit/log_transitions_spec.rb +0 -24
  56. data/spec/unit/logger_spec.rb +0 -36
  57. data/spec/unit/message_queue_spec.rb +0 -62
  58. data/spec/unit/new_spec.rb +0 -50
  59. data/spec/unit/respond_to_spec.rb +0 -34
  60. data/spec/unit/state_parser/parse_spec.rb +0 -56
  61. data/spec/unit/states_spec.rb +0 -28
  62. data/spec/unit/subscribers_spec.rb +0 -40
  63. data/spec/unit/target_spec.rb +0 -225
  64. data/spec/unit/terminated_spec.rb +0 -85
  65. data/spec/unit/transition/check_conditions_spec.rb +0 -55
  66. data/spec/unit/transition/inspect_spec.rb +0 -25
  67. data/spec/unit/transition/matches_spec.rb +0 -21
  68. data/spec/unit/transition/states_spec.rb +0 -29
  69. data/spec/unit/transition/to_state_spec.rb +0 -19
  70. data/spec/unit/trigger_spec.rb +0 -18
  71. data/spec/unit/undefined_transition/eql_spec.rb +0 -15
  72. data/tasks/console.rake +0 -11
  73. data/tasks/coverage.rake +0 -11
  74. data/tasks/spec.rake +0 -34
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe FiniteMachine::Transition, '#inspect' do
4
- let(:machine) { double(:machine) }
5
-
6
- subject(:transition) { described_class.new(machine, event_name, attrs) }
7
-
8
- context 'when inspecting' do
9
- let(:event_name) { :start }
10
- let(:attrs) { { states: { :foo => :bar, :baz => :daz } } }
11
-
12
- it "displays name and transitions" do
13
- expect(transition.inspect).to eql("<#FiniteMachine::Transition @name=start, @transitions=foo -> bar, baz -> daz, @when=[]>")
14
- end
15
- end
16
-
17
- context 'when converting to string' do
18
- let(:event_name) { :start }
19
- let(:attrs) { { states: { :foo => :bar } } }
20
-
21
- it "displays name and transitions" do
22
- expect(transition.to_s).to eql("start")
23
- end
24
- end
25
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe FiniteMachine::Transition, '#matches?' do
4
- let(:machine) { double(:machine) }
5
-
6
- it "matches from state" do
7
- states = {:green => :red}
8
- transition = described_class.new(machine, :event_name, states: states)
9
-
10
- expect(transition.matches?(:green)).to eq(true)
11
- expect(transition.matches?(:red)).to eq(false)
12
- end
13
-
14
- it "matches any state" do
15
- states = {FiniteMachine::ANY_STATE => :red}
16
- transition = described_class.new(machine, :event_name, states: states)
17
-
18
- expect(transition.matches?(:green)).to eq(true)
19
- end
20
- end
21
-
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe FiniteMachine::Transition, '#states' do
4
- let(:machine) { double(:machine) }
5
-
6
- it "groups states with :to key only" do
7
- attrs = {states: {:any => :red}}
8
- transition = FiniteMachine::Transition.new(machine, :event_name, attrs)
9
- expect(transition.states).to eql({any: :red})
10
- end
11
-
12
- it "groups states when from array" do
13
- attrs = {states: { :green => :red, :yellow => :red}}
14
- transition = FiniteMachine::Transition.new(machine, :event_name, attrs)
15
- expect(transition.states.keys).to match_array([:green, :yellow])
16
- expect(transition.states.values).to eql([:red, :red])
17
- end
18
-
19
-
20
- it "groups states when hash of states" do
21
- attrs = {states: {
22
- :initial => :low,
23
- :low => :medium,
24
- :medium => :high }}
25
- transition = FiniteMachine::Transition.new(machine, :event_name, attrs)
26
- expect(transition.states.keys).to match_array([:initial, :low, :medium])
27
- expect(transition.states.values).to eql([:low, :medium, :high])
28
- end
29
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe FiniteMachine::Transition, '#to_state' do
4
- let(:machine) { double(:machine) }
5
-
6
- it "finds to state" do
7
- states = {:green => :red}
8
- transition = described_class.new(machine, :event_name, states: states)
9
-
10
- expect(transition.to_state(:green)).to eq(:red)
11
- end
12
-
13
- it "finds to state for transition from any state" do
14
- states = {FiniteMachine::ANY_STATE => :red}
15
- transition = described_class.new(machine, :event_name, states: states)
16
-
17
- expect(transition.to_state(:green)).to eq(:red)
18
- end
19
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe FiniteMachine::StateMachine, '#trigger' do
4
- it "triggers event manually" do
5
- called = []
6
- fsm = FiniteMachine.new do
7
- initial :red
8
-
9
- event :start, :red => :green, if: proc { |_, name| called << name; true }
10
- event :stop, :green => :red
11
- end
12
-
13
- expect(fsm.current).to eq(:red)
14
- fsm.trigger(:start, 'Piotr')
15
- expect(fsm.current).to eq(:green)
16
- expect(called).to eq(['Piotr'])
17
- end
18
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe FiniteMachine::UndefinedTransition, '#==' do
4
- it "is true with the same name" do
5
- expect(described_class.new(:go)).to eq(described_class.new(:go))
6
- end
7
-
8
- it "is false with a different name" do
9
- expect(described_class.new(:go)).to_not eq(described_class.new(:other))
10
- end
11
-
12
- it "is false with another object" do
13
- expect(described_class.new(:go)).to_not eq(:other)
14
- end
15
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Load gem inside irb console'
4
- task :console do
5
- require 'irb'
6
- require 'irb/completion'
7
- require File.join(__FILE__, '../../lib/finite_machine')
8
- ARGV.clear
9
- IRB.start
10
- end
11
- task :c => :console
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Measure code coverage'
4
- task :coverage do
5
- begin
6
- original, ENV['COVERAGE'] = ENV['COVERAGE'], 'true'
7
- Rake::Task['spec'].invoke
8
- ensure
9
- ENV['COVERAGE'] = original
10
- end
11
- end
@@ -1,34 +0,0 @@
1
- # encoding: utf-8
2
-
3
- begin
4
- require 'rspec/core/rake_task'
5
-
6
- desc 'Run all specs'
7
- RSpec::Core::RakeTask.new(:spec) do |task|
8
- task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
9
- end
10
-
11
- namespace :spec do
12
- desc 'Run unit specs'
13
- RSpec::Core::RakeTask.new(:unit) do |task|
14
- task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
15
- end
16
-
17
- desc 'Run integration specs'
18
- RSpec::Core::RakeTask.new(:integration) do |task|
19
- task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
20
- end
21
-
22
- desc 'Run performance specs'
23
- RSpec::Core::RakeTask.new(:perf) do |task|
24
- task.pattern = 'spec/performance{,/*/**}/*_spec.rb'
25
- end
26
- end
27
-
28
- rescue LoadError
29
- %w[spec spec:unit spec:integration].each do |name|
30
- task name do
31
- $stderr.puts "In order to run #{name}, do `gem install rspec`"
32
- end
33
- end
34
- end