PageRenderTime 49ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/test/unit/graph_test.rb

https://github.com/SupplyChainDesign/state_machine
Ruby | 98 lines | 78 code | 19 blank | 1 comment | 0 complexity | 8be132df0f3aeeff97851e8e0a00abf5 MD5 | raw file
  1. require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
  2. begin
  3. # Load library
  4. require 'graphviz'
  5. class GraphDefaultTest < Test::Unit::TestCase
  6. def setup
  7. @graph = StateMachine::Graph.new('test')
  8. end
  9. def test_should_have_a_default_font
  10. assert_equal 'Arial', @graph.font
  11. end
  12. def test_should_use_current_directory_for_filepath
  13. assert_equal './test.png', @graph.file_path
  14. end
  15. def test_should_have_a_default_file_format
  16. assert_equal 'png', @graph.file_format
  17. end
  18. def test_should_have_a_default_orientation
  19. assert_equal 'TB', @graph[:rankdir].source
  20. end
  21. end
  22. class GraphNodesTest < Test::Unit::TestCase
  23. def setup
  24. @graph = StateMachine::Graph.new('test')
  25. @node = @graph.add_nodes('parked', :shape => 'ellipse')
  26. end
  27. def test_should_return_generated_node
  28. assert_not_nil @node
  29. end
  30. def test_should_use_specified_name
  31. assert_equal @node, @graph.get_node('parked')
  32. end
  33. def test_should_use_specified_options
  34. assert_equal 'ellipse', @node['shape'].to_s.gsub('"', '')
  35. end
  36. def test_should_set_default_font
  37. assert_equal 'Arial', @node['fontname'].to_s.gsub('"', '')
  38. end
  39. end
  40. class GraphEdgesTest < Test::Unit::TestCase
  41. def setup
  42. @graph = StateMachine::Graph.new('test')
  43. @graph.add_nodes('parked', :shape => 'ellipse')
  44. @graph.add_nodes('idling', :shape => 'ellipse')
  45. @edge = @graph.add_edges('parked', 'idling', :label => 'ignite')
  46. end
  47. def test_should_return_generated_edge
  48. assert_not_nil @edge
  49. end
  50. def test_should_use_specified_nodes
  51. assert_equal 'parked', @edge.node_one(false)
  52. assert_equal 'idling', @edge.node_two(false)
  53. end
  54. def test_should_use_specified_options
  55. assert_equal 'ignite', @edge['label'].to_s.gsub('"', '')
  56. end
  57. def test_should_set_default_font
  58. assert_equal 'Arial', @edge['fontname'].to_s.gsub('"', '')
  59. end
  60. end
  61. class GraphOutputTest < Test::Unit::TestCase
  62. def setup
  63. @graph_name = "test_#{rand(1000000)}"
  64. @graph = StateMachine::Graph.new(@graph_name)
  65. @graph.add_nodes('parked', :shape => 'ellipse')
  66. @graph.add_nodes('idling', :shape => 'ellipse')
  67. @graph.add_edges('parked', 'idling', :label => 'ignite')
  68. @graph.output
  69. end
  70. def test_should_save_file
  71. assert File.exist?("./#{@graph_name}.png")
  72. end
  73. def teardown
  74. FileUtils.rm Dir["./#{@graph_name}.png"]
  75. end
  76. end
  77. rescue LoadError
  78. $stderr.puts 'Skipping GraphViz StateMachine::Graph tests. `gem install ruby-graphviz` >= v0.9.17 and try again.'
  79. end unless ENV['TRAVIS']