state_machine 0.6.2 → 0.6.3

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.
@@ -1497,31 +1497,34 @@ begin
1497
1497
  end
1498
1498
 
1499
1499
  def test_should_save_file_with_class_name_by_default
1500
- @machine.draw
1501
- assert File.exist?('./Vehicle_state.png')
1502
- ensure
1503
- FileUtils.rm('./Vehicle_state.png')
1500
+ graph = @machine.draw(:output => false)
1501
+ assert_equal './Vehicle_state.png', graph.instance_variable_get('@filename')
1504
1502
  end
1505
1503
 
1506
1504
  def test_should_allow_base_name_to_be_customized
1507
- @machine.draw(:name => 'machine')
1508
- assert File.exist?('./machine.png')
1509
- ensure
1510
- FileUtils.rm('./machine.png')
1505
+ graph = @machine.draw(:name => 'machine', :output => false)
1506
+ assert_equal './machine.png', graph.instance_variable_get('@filename')
1511
1507
  end
1512
1508
 
1513
1509
  def test_should_allow_format_to_be_customized
1514
- @machine.draw(:format => 'jpg')
1515
- assert File.exist?('./Vehicle_state.jpg')
1516
- ensure
1517
- FileUtils.rm('./Vehicle_state.jpg')
1510
+ graph = @machine.draw(:format => 'jpg', :output => false)
1511
+ assert_equal './Vehicle_state.jpg', graph.instance_variable_get('@filename')
1512
+ assert_equal 'jpg', graph.instance_variable_get('@format')
1518
1513
  end
1519
1514
 
1520
1515
  def test_should_allow_path_to_be_customized
1521
- @machine.draw(:path => "#{File.dirname(__FILE__)}/")
1522
- assert File.exist?("#{File.dirname(__FILE__)}/Vehicle_state.png")
1523
- ensure
1524
- FileUtils.rm("#{File.dirname(__FILE__)}/Vehicle_state.png")
1516
+ graph = @machine.draw(:path => "#{File.dirname(__FILE__)}/", :output => false)
1517
+ assert_equal "#{File.dirname(__FILE__)}/Vehicle_state.png", graph.instance_variable_get('@filename')
1518
+ end
1519
+
1520
+ def test_should_allow_orientation_to_be_landscape
1521
+ graph = @machine.draw(:orientation => 'landscape', :output => false)
1522
+ assert_equal 'LR', graph['rankdir']
1523
+ end
1524
+
1525
+ def test_should_allow_orientation_to_be_portrait
1526
+ graph = @machine.draw(:orientation => 'portrait', :output => false)
1527
+ assert_equal 'TB', graph['rankdir']
1525
1528
  end
1526
1529
  end
1527
1530
 
@@ -1536,7 +1539,15 @@ begin
1536
1539
  end
1537
1540
  @machine.state :parked, :value => 1
1538
1541
  @machine.state :idling, :value => 2
1539
- @machine.draw
1542
+ @graph = @machine.draw
1543
+ end
1544
+
1545
+ def test_should_draw_all_states
1546
+ assert_equal 3, @graph.node_count
1547
+ end
1548
+
1549
+ def test_should_draw_all_events
1550
+ assert_equal 2, @graph.edge_count
1540
1551
  end
1541
1552
 
1542
1553
  def test_should_draw_machine
@@ -1556,7 +1567,15 @@ begin
1556
1567
  transition :parked => :idling
1557
1568
  end
1558
1569
  @machine.state :parked, :value => nil
1559
- @machine.draw
1570
+ @graph = @machine.draw
1571
+ end
1572
+
1573
+ def test_should_draw_all_states
1574
+ assert_equal 3, @graph.node_count
1575
+ end
1576
+
1577
+ def test_should_draw_all_events
1578
+ assert_equal 2, @graph.edge_count
1560
1579
  end
1561
1580
 
1562
1581
  def test_should_draw_machine
@@ -1576,7 +1595,15 @@ begin
1576
1595
  transition :parked => :idling
1577
1596
  end
1578
1597
  @machine.state :idling, :value => lambda {Time.now}
1579
- @machine.draw
1598
+ @graph = @machine.draw
1599
+ end
1600
+
1601
+ def test_should_draw_all_states
1602
+ assert_equal 3, @graph.node_count
1603
+ end
1604
+
1605
+ def test_should_draw_all_events
1606
+ assert_equal 2, @graph.edge_count
1580
1607
  end
1581
1608
 
1582
1609
  def test_should_draw_machine
@@ -258,6 +258,7 @@ class StateInitialTest < Test::Unit::TestCase
258
258
 
259
259
  def test_should_be_initial
260
260
  assert @state.initial
261
+ assert @state.initial?
261
262
  end
262
263
  end
263
264
 
@@ -269,6 +270,65 @@ class StateNotInitialTest < Test::Unit::TestCase
269
270
 
270
271
  def test_should_not_be_initial
271
272
  assert !@state.initial
273
+ assert !@state.initial?
274
+ end
275
+ end
276
+
277
+ class StateFinalTest < Test::Unit::TestCase
278
+ def setup
279
+ @machine = StateMachine::Machine.new(Class.new)
280
+ @state = StateMachine::State.new(@machine, :parked)
281
+ end
282
+
283
+ def test_should_be_final_without_input_transitions
284
+ assert @state.final?
285
+ end
286
+
287
+ def test_should_be_final_with_input_transitions
288
+ @machine.event :park do
289
+ transition :idling => :parked
290
+ end
291
+
292
+ assert @state.final?
293
+ end
294
+
295
+ def test_should_be_final_with_loopback
296
+ @machine.event :ignite do
297
+ transition :parked => same
298
+ end
299
+
300
+ assert @state.final?
301
+ end
302
+ end
303
+
304
+ class StateNotFinalTest < Test::Unit::TestCase
305
+ def setup
306
+ @machine = StateMachine::Machine.new(Class.new)
307
+ @state = StateMachine::State.new(@machine, :parked)
308
+ end
309
+
310
+ def test_should_not_be_final_with_outgoing_whitelist_transitions
311
+ @machine.event :ignite do
312
+ transition :parked => :idling
313
+ end
314
+
315
+ assert !@state.final?
316
+ end
317
+
318
+ def test_should_not_be_final_with_outgoing_all_transitions
319
+ @machine.event :ignite do
320
+ transition all => :idling
321
+ end
322
+
323
+ assert !@state.final?
324
+ end
325
+
326
+ def test_should_not_be_final_with_outgoing_blacklist_transitions
327
+ @machine.event :ignite do
328
+ transition all - :first_gear => :idling
329
+ end
330
+
331
+ assert !@state.final?
272
332
  end
273
333
  end
274
334
 
@@ -531,6 +591,9 @@ begin
531
591
  class StateDrawingTest < Test::Unit::TestCase
532
592
  def setup
533
593
  @machine = StateMachine::Machine.new(Class.new)
594
+ @machine.event :ignite do
595
+ transition :parked => :idling
596
+ end
534
597
  @state = StateMachine::State.new(@machine, :parked, :value => 1)
535
598
 
536
599
  graph = GraphViz.new('G')
@@ -561,14 +624,22 @@ begin
561
624
  class StateDrawingInitialTest < Test::Unit::TestCase
562
625
  def setup
563
626
  @machine = StateMachine::Machine.new(Class.new)
627
+ @machine.event :ignite do
628
+ transition :parked => :idling
629
+ end
564
630
  @state = StateMachine::State.new(@machine, :parked, :initial => true)
565
631
 
566
- graph = GraphViz.new('G')
567
- @node = @state.draw(graph)
632
+ @graph = GraphViz.new('G')
633
+ @node = @state.draw(@graph)
568
634
  end
569
635
 
570
- def test_should_use_doublecircle_as_shape
571
- assert_equal 'doublecircle', @node['shape']
636
+ def test_should_use_ellipse_as_shape
637
+ assert_equal 'ellipse', @node['shape']
638
+ end
639
+
640
+ def test_should_draw_edge_between_point_and_state
641
+ assert_equal 2, @graph.node_count
642
+ assert_equal 1, @graph.edge_count
572
643
  end
573
644
  end
574
645
 
@@ -607,6 +678,37 @@ begin
607
678
  assert_equal 'parked (*)', @node['label']
608
679
  end
609
680
  end
681
+
682
+ class StateDrawingNonFinalTest < Test::Unit::TestCase
683
+ def setup
684
+ @machine = StateMachine::Machine.new(Class.new)
685
+ @machine.event :ignite do
686
+ transition :parked => :idling
687
+ end
688
+ @state = StateMachine::State.new(@machine, :parked)
689
+
690
+ graph = GraphViz.new('G')
691
+ @node = @state.draw(graph)
692
+ end
693
+
694
+ def test_should_use_ellipse_as_shape
695
+ assert_equal 'ellipse', @node['shape']
696
+ end
697
+ end
698
+
699
+ class StateDrawingFinalTest < Test::Unit::TestCase
700
+ def setup
701
+ @machine = StateMachine::Machine.new(Class.new)
702
+ @state = StateMachine::State.new(@machine, :parked)
703
+
704
+ graph = GraphViz.new('G')
705
+ @node = @state.draw(graph)
706
+ end
707
+
708
+ def test_should_use_doublecircle_as_shape
709
+ assert_equal 'doublecircle', @node['shape']
710
+ end
711
+ end
610
712
  rescue LoadError
611
713
  $stderr.puts 'Skipping GraphViz StateMachine::State tests. `gem install ruby-graphviz` and try again.'
612
714
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Pfeifer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-07 23:00:00 -05:00
12
+ date: 2009-03-10 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15