state_machines-graphviz 0.0.2 → 0.1.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 (42) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.txt +1 -1
  3. data/README.md +14 -2
  4. data/lib/state_machines/graphviz/graph.rb +5 -5
  5. data/lib/state_machines/graphviz/renderer.rb +155 -0
  6. data/lib/state_machines/graphviz/version.rb +3 -1
  7. data/lib/state_machines/graphviz.rb +33 -1
  8. data/lib/state_machines/tasks/railtie.rb +3 -2
  9. data/lib/state_machines/tasks/state_machines.rake +2 -0
  10. data/lib/state_machines-graphviz.rb +7 -0
  11. data/{spec → test}/files/switch.rb +2 -0
  12. data/test/graph_default_test.rb +24 -0
  13. data/test/graph_edges_test.rb +28 -0
  14. data/test/graph_nodes_test.rb +25 -0
  15. data/test/graph_output_test.rb +21 -0
  16. data/test/machine_class_drawing_test.rb +28 -0
  17. data/test/machine_drawing_test.rb +72 -0
  18. data/test/machine_drawing_with_dynamic_states_test.rb +38 -0
  19. data/test/machine_drawing_with_integer_states_test.rb +38 -0
  20. data/test/machine_drawing_with_nil_states_test.rb +37 -0
  21. data/test/state_drawing_final_test.rb +17 -0
  22. data/test/state_drawing_initial_test.rb +25 -0
  23. data/test/state_drawing_lambda_value_test.rb +21 -0
  24. data/test/state_drawing_nil_name_test.rb +22 -0
  25. data/test/state_drawing_non_final_test.rb +20 -0
  26. data/test/state_drawing_test.rb +33 -0
  27. data/test/state_drawing_with_human_name_test.rb +20 -0
  28. data/test/test_helper.rb +6 -0
  29. metadata +61 -28
  30. data/.gitignore +0 -23
  31. data/.rspec +0 -3
  32. data/.travis.yml +0 -12
  33. data/Gemfile +0 -4
  34. data/Rakefile +0 -13
  35. data/lib/state_machines/graphviz/monkeypatch.rb +0 -161
  36. data/lib/state_machines/tasks/state_machines.rb +0 -32
  37. data/spec/graph_spec.rb +0 -92
  38. data/spec/machine_drawing_spec.rb +0 -215
  39. data/spec/machine_spec.rb +0 -19
  40. data/spec/spec_helper.rb +0 -2
  41. data/spec/state_spec.rb +0 -142
  42. data/state_machines-graphviz.gemspec +0 -25
@@ -1,215 +0,0 @@
1
- describe StateMachines::Graphviz do
2
- context 'Drawing' do
3
- let(:klass) do
4
- Class.new do
5
- def self.name
6
- @name ||= "Vehicle_#{rand(1_000_000)}"
7
- end
8
- end
9
- end
10
- let(:machine) { StateMachines::Machine.new(klass, initial: :parked) }
11
-
12
- before(:each) do
13
- machine.event :ignite do
14
- transition parked: :idling
15
- end
16
- end
17
-
18
- it 'should_raise_exception_if_invalid_option_specified' do
19
- expect { machine.draw(invalid: true) }.to raise_error(ArgumentError)
20
- end
21
-
22
- it 'should_save_file_with_class_name_by_default' do
23
- machine.draw
24
- expect(File.exist?("doc/state_machines/#{klass.name}_state.png")).to be_truthy
25
- end
26
-
27
- it 'should_allow_base_name_to_be_customized' do
28
- name = "machine_#{rand(1_000_000)}"
29
- machine.draw(name: name)
30
- @path = "doc/state_machines/#{name}.png"
31
- expect(File.exist?(@path)).to be_truthy
32
- end
33
-
34
- it 'should_allow_format_to_be_customized' do
35
- machine.draw(format: 'jpg')
36
- @path = "doc/state_machines/#{klass.name}_state.jpg"
37
- expect(File.exist?(@path)).to be_truthy
38
- end
39
-
40
- it 'should_allow_path_to_be_customized' do
41
- machine.draw(path: "#{File.dirname(__FILE__)}/")
42
- @path = "#{File.dirname(__FILE__)}/#{klass.name}_state.png"
43
- expect(File.exist?(@path)).to be_truthy
44
- end
45
-
46
- it 'should_allow_orientation_to_be_landscape' do
47
- graph = machine.draw(orientation: 'landscape')
48
- expect(graph['rankdir'].to_s.gsub('"', '')).to eq('LR')
49
- end
50
-
51
- it 'should_allow_orientation_to_be_portrait' do
52
- graph = machine.draw(orientation: 'portrait')
53
- expect(graph['rankdir'].to_s.gsub('"', '')).to eq('TB')
54
- end
55
-
56
- it 'should_allow_human_names_to_be_displayed' do
57
- machine.event :ignite, human_name: 'Ignite'
58
- machine.state :parked, human_name: 'Parked'
59
- machine.state :idling, human_name: 'Idling'
60
- graph = machine.draw(human_names: true)
61
-
62
- parked_node = graph.get_node('parked')
63
- expect(parked_node['label'].to_s.gsub('"', '')).to eq('Parked')
64
-
65
- idling_node = graph.get_node('idling')
66
- expect(idling_node['label'].to_s.gsub('"', '')).to eq('Idling')
67
- end
68
-
69
- after(:each) do
70
- FileUtils.rm Dir[@path || "doc/state_machines/#{klass.name}_state.png"]
71
- end
72
- end
73
-
74
- context 'DrawingWithIntegerStates' do
75
- let(:klass) do
76
- Class.new do
77
- def self.name
78
- @name ||= "Vehicle_#{rand(1_000_000)}"
79
- end
80
- end
81
- end
82
-
83
- let(:machine) { StateMachines::Machine.new(klass, :state_id, initial: :parked) }
84
- before(:each) do
85
- machine.event :ignite do
86
- transition parked: :idling
87
- end
88
- machine.state :parked, value: 1
89
- machine.state :idling, value: 2
90
- end
91
-
92
- let!(:graph) { machine.draw }
93
-
94
- it 'should_draw_all_states' do
95
- expect(graph.node_count).to eq(3)
96
- end
97
-
98
- it 'should_draw_all_events' do
99
- expect(graph.edge_count).to eq(2)
100
- end
101
-
102
- it 'should_draw_machine' do
103
- expect(File.exist?("doc/state_machines/#{klass.name}_state_id.png")).to be_truthy
104
- end
105
-
106
- after(:each) do
107
- FileUtils.rm Dir["doc/state_machines/#{klass.name}_state_id.png"]
108
- end
109
- end
110
-
111
- context 'DrawingWithNilStates' do
112
- let(:klass) do
113
- Class.new do
114
- def self.name
115
- @name ||= "Vehicle_#{rand(1_000_000)}"
116
- end
117
- end
118
- end
119
- let(:machine) { StateMachines::Machine.new(klass, initial: :parked) }
120
-
121
- before(:each) do
122
- machine.event :ignite do
123
- transition parked: :idling
124
- end
125
- machine.state :parked, value: nil
126
- end
127
-
128
- let!(:graph) { machine.draw }
129
-
130
- it 'should_draw_all_states' do
131
- expect(graph.node_count).to eq(3)
132
- end
133
-
134
- it 'should_draw_all_events' do
135
- expect(graph.edge_count).to eq(2)
136
- end
137
-
138
- it 'should_draw_machine' do
139
- expect(File.exist?("doc/state_machines/#{klass.name}_state.png")).to be_truthy
140
- end
141
-
142
- after(:each) do
143
- FileUtils.rm Dir["doc/state_machines/#{klass.name}_state.png"]
144
- end
145
- end
146
-
147
- context 'DrawingWithDynamicStates' do
148
- let(:klass) do
149
- Class.new do
150
- def self.name
151
- @name ||= "Vehicle_#{rand(1_000_000)}"
152
- end
153
- end
154
- end
155
-
156
- let(:machine) { StateMachines::Machine.new(klass, initial: :parked) }
157
-
158
- before(:each) do
159
- machine.event :activate do
160
- transition parked: :idling
161
- end
162
- machine.state :idling, value: lambda { Time.now }
163
- end
164
-
165
- let!(:graph) { machine.draw }
166
-
167
- it 'should_draw_all_states' do
168
- expect(graph.node_count).to eq(3)
169
- end
170
-
171
- it 'should_draw_all_events' do
172
- expect(graph.edge_count).to eq(2)
173
- end
174
-
175
- it 'should_draw_machine' do
176
- expect(File.exist?("doc/state_machines/#{klass.name}_state.png")).to be_truthy
177
- end
178
-
179
- after(:each) do
180
- FileUtils.rm Dir["doc/state_machines/#{klass.name}_state.png"]
181
- end
182
-
183
- end
184
-
185
- context 'ClassDrawing' do
186
- before(:each) do
187
- klass = Class.new do
188
- def self.name
189
- @name ||= "Vehicle_#{rand(1_000_000)}"
190
- end
191
- end
192
- machine = StateMachines::Machine.new(klass)
193
- machine.event :ignite do
194
- transition parked: :idling
195
- end
196
- end
197
-
198
- it 'should_raise_exception_if_no_class_names_specified' do
199
- expect { StateMachines::Machine.draw(nil) }.to raise_error(ArgumentError)
200
- # FixMe
201
- # assert_equal 'At least one class must be specified', exception.message
202
- end
203
-
204
- it 'should_load_files' do
205
- StateMachines::Machine.draw('Switch', file: File.expand_path("#{File.dirname(__FILE__)}/files/switch.rb"))
206
- expect(defined?(::Switch)).to be_truthy
207
- end
208
-
209
- it 'should_allow_path_and_format_to_be_customized' do
210
- StateMachines::Machine.draw('Switch', file: File.expand_path("#{File.dirname(__FILE__)}/files/switch.rb"), path: "#{File.dirname(__FILE__)}/", format: 'jpg')
211
- expect(File.exist?("#{File.dirname(__FILE__)}/#{Switch.name}_state.jpg")).to be_truthy
212
- FileUtils.rm Dir["{.,#{File.dirname(__FILE__)}}/#{Switch.name}_state.{jpg,png}"]
213
- end
214
- end
215
- end
data/spec/machine_spec.rb DELETED
@@ -1,19 +0,0 @@
1
- describe StateMachines::Machine do
2
- before(:each) do
3
- klass = Class.new do
4
- def self.name
5
- @name ||= "Vehicle_#{rand(1_000_000)}"
6
- end
7
- end
8
-
9
- @machine = StateMachines::Machine.new(klass, initial: :parked)
10
- @machine.event :ignite do
11
- transition parked: :idling
12
- end
13
- end
14
-
15
- it 'should not raise exception' do
16
- expect { @machine.draw }.not_to raise_error
17
- end
18
-
19
- end
data/spec/spec_helper.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'state_machines'
2
- require 'state_machines/graphviz'
data/spec/state_spec.rb DELETED
@@ -1,142 +0,0 @@
1
- context 'Drawing' do
2
- before(:each) do
3
- @machine = StateMachines::Machine.new(Class.new)
4
- @machine.states << @state = StateMachines::State.new(@machine, :parked, :value => 1)
5
- @machine.event :ignite do
6
- transition :parked => :idling
7
- end
8
-
9
- graph = StateMachines::Graph.new('test')
10
- @state.draw(graph)
11
- @node = graph.get_node('parked')
12
- end
13
-
14
- it 'should_use_ellipse_shape' do
15
- expect(@node['shape'].to_s.gsub('"', '')).to eq('ellipse')
16
- end
17
-
18
- it 'should_set_width_to_one' do
19
- expect('1').to eq(@node['width'].to_s.gsub('"', ''))
20
- end
21
-
22
- it 'should_set_height_to_one' do
23
- expect('1').to eq(@node['height'].to_s.gsub('"', ''))
24
- end
25
-
26
- it 'should_use_description_as_label' do
27
- expect('parked (1)').to eq(@node['label'].to_s.gsub('"', ''))
28
- end
29
- end
30
-
31
- context 'DrawingInitial' do
32
- before(:each) do
33
- @machine = StateMachines::Machine.new(Class.new)
34
- @machine.states << @state = StateMachines::State.new(@machine, :parked, :initial => true)
35
- @machine.event :ignite do
36
- transition :parked => :idling
37
- end
38
-
39
- @graph = StateMachines::Graph.new('test')
40
- @state.draw(@graph)
41
- @node = @graph.get_node('parked')
42
- end
43
-
44
- it 'should_use_ellipse_as_shape' do
45
- expect('ellipse').to eq(@node['shape'].to_s.gsub('"', ''))
46
- end
47
-
48
- it 'should_draw_edge_between_point_and_state' do
49
- expect(2).to eq(@graph.node_count)
50
- expect(1).to eq(@graph.edge_count)
51
- end
52
- end
53
-
54
- context 'DrawingNilName' do
55
- before(:each) do
56
- @machine = StateMachines::Machine.new(Class.new)
57
- @machine.states << @state = StateMachines::State.new(@machine, nil)
58
-
59
- graph = StateMachines::Graph.new('test')
60
- @state.draw(graph)
61
- @node = graph.get_node('nil')
62
- end
63
-
64
- it 'should_have_a_node' do
65
- expect(@node).to be_truthy
66
- end
67
-
68
- it 'should_use_description_as_label' do
69
- expect('nil').to eq(@node['label'].to_s.gsub('"', ''))
70
- end
71
- end
72
-
73
- context 'DrawingLambdaValue' do
74
- before(:each) do
75
- @machine = StateMachines::Machine.new(Class.new)
76
- @machine.states << @state = StateMachines::State.new(@machine, :parked, :value => lambda {})
77
-
78
- graph = StateMachines::Graph.new('test')
79
- @state.draw(graph)
80
- @node = graph.get_node('parked')
81
- end
82
-
83
- it 'should_have_a_node' do
84
- expect(@node).to be_truthy
85
- end
86
-
87
- it 'should_use_description_as_label' do
88
- expect('parked (*)').to eq(@node['label'].to_s.gsub('"', ''))
89
- end
90
- end
91
-
92
- context 'DrawingNonFinal' do
93
- before(:each) do
94
- @machine = StateMachines::Machine.new(Class.new)
95
- @machine.states << @state = StateMachines::State.new(@machine, :parked)
96
- @machine.event :ignite do
97
- transition :parked => :idling
98
- end
99
-
100
- graph = StateMachines::Graph.new('test')
101
- @state.draw(graph)
102
- @node = graph.get_node('parked')
103
- end
104
-
105
- it 'should_use_ellipse_as_shape' do
106
- expect('ellipse').to eq(@node['shape'].to_s.gsub('"', ''))
107
- end
108
- end
109
-
110
- context 'DrawingFinal' do
111
- before(:each) do
112
- @machine = StateMachines::Machine.new(Class.new)
113
- @machine.states << @state = StateMachines::State.new(@machine, :parked)
114
-
115
- graph = StateMachines::Graph.new('test')
116
- @state.draw(graph)
117
- @node = graph.get_node('parked')
118
- end
119
-
120
- it 'should_use_doublecircle_as_shape' do
121
- expect('doublecircle').to eq(@node['shape'].to_s.gsub('"', ''))
122
- end
123
- end
124
-
125
- context 'DrawingWithHumanName' do
126
- before(:each) do
127
- @machine = StateMachines::Machine.new(Class.new)
128
- @machine.states << @state = StateMachines::State.new(@machine, :parked, :human_name => 'Parked')
129
- @machine.event :ignite do
130
- transition :parked => :idling
131
- end
132
-
133
- graph = StateMachines::Graph.new('test')
134
- @state.draw(graph, :human_name => true)
135
- @node = graph.get_node('parked')
136
- end
137
-
138
- it 'should_use_description_with_human_name_as_label' do
139
- expect('Parked').to eq(@node['label'].to_s.gsub('"', ''))
140
- end
141
- end
142
-
@@ -1,25 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'state_machines/graphviz/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'state_machines-graphviz'
8
- spec.version = StateMachines::Graphviz::VERSION
9
- spec.authors = ['Abdelkader Boudih', 'Aaron Pfeifer']
10
- spec.email = ['terminale@gmail.com']
11
- spec.summary = %q(Drawing module for state machines)
12
- spec.description = %q(Graphviz module for state machines)
13
- spec.homepage = 'https://github.com/seuros/state_machines-graphviz'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.test_files = spec.files.grep(%r{/^spec\//})
18
- spec.require_paths = ['lib']
19
-
20
- spec.add_dependency 'state_machines'
21
- spec.add_dependency 'ruby-graphviz'
22
- spec.add_development_dependency 'bundler'
23
- spec.add_development_dependency 'rake'
24
- spec.add_development_dependency 'rspec' , '>=3.0.0'
25
- end