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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
begin
# Load library
require 'graphviz'
class GraphDefaultTest < Test::Unit::TestCase
def setup
@graph = StateMachine::Graph.new('test')
end
def test_should_have_a_default_font
assert_equal 'Arial', @graph.font
end
def test_should_use_current_directory_for_filepath
assert_equal './test.png', @graph.file_path
end
def test_should_have_a_default_file_format
assert_equal 'png', @graph.file_format
end
def test_should_have_a_default_orientation
assert_equal 'TB', @graph[:rankdir].source
end
end
class GraphNodesTest < Test::Unit::TestCase
def setup
@graph = StateMachine::Graph.new('test')
@node = @graph.add_nodes('parked', :shape => 'ellipse')
end
def test_should_return_generated_node
assert_not_nil @node
end
def test_should_use_specified_name
assert_equal @node, @graph.get_node('parked')
end
def test_should_use_specified_options
assert_equal 'ellipse', @node['shape'].to_s.gsub('"', '')
end
def test_should_set_default_font
assert_equal 'Arial', @node['fontname'].to_s.gsub('"', '')
end
end
class GraphEdgesTest < Test::Unit::TestCase
def setup
@graph = StateMachine::Graph.new('test')
@graph.add_nodes('parked', :shape => 'ellipse')
@graph.add_nodes('idling', :shape => 'ellipse')
@edge = @graph.add_edges('parked', 'idling', :label => 'ignite')
end
def test_should_return_generated_edge
assert_not_nil @edge
end
def test_should_use_specified_nodes
assert_equal 'parked', @edge.node_one(false)
assert_equal 'idling', @edge.node_two(false)
end
def test_should_use_specified_options
assert_equal 'ignite', @edge['label'].to_s.gsub('"', '')
end
def test_should_set_default_font
assert_equal 'Arial', @edge['fontname'].to_s.gsub('"', '')
end
end
class GraphOutputTest < Test::Unit::TestCase
def setup
@graph_name = "test_#{rand(1000000)}"
@graph = StateMachine::Graph.new(@graph_name)
@graph.add_nodes('parked', :shape => 'ellipse')
@graph.add_nodes('idling', :shape => 'ellipse')
@graph.add_edges('parked', 'idling', :label => 'ignite')
@graph.output
end
def test_should_save_file
assert File.exist?("./#{@graph_name}.png")
end
def teardown
FileUtils.rm Dir["./#{@graph_name}.png"]
end
end
rescue LoadError
$stderr.puts 'Skipping GraphViz StateMachine::Graph tests. `gem install ruby-graphviz` >= v0.9.17 and try again.'
end unless ENV['TRAVIS']
|