rumld 0.4.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.
- data/CHANGELOG +2 -0
- data/README +1 -0
- data/Rakefile +102 -0
- data/TODO +16 -0
- data/bin/rumld +50 -0
- data/lib/rumld/graph.rb +66 -0
- data/lib/rumld/node.rb +151 -0
- data/lib/rumld/options_struct.rb +59 -0
- data/lib/rumld/rdoc_inspector.rb +70 -0
- data/lib/rumld/tree.rb +62 -0
- data/lib/rumld.rb +18 -0
- data/spec/rumld_graph_spec.rb +43 -0
- data/spec/rumld_node_spec.rb +101 -0
- data/spec/rumld_rdoc_inspector_spec.rb +91 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +78 -0
- data/test/rumld_graph_test.rb +44 -0
- data/test/rumld_node_test.rb +121 -0
- data/test/rumld_rdoc_inspector_test.rb +90 -0
- data/test/rumld_tree_test.rb +59 -0
- data/test/test_helper.rb +15 -0
- metadata +102 -0
@@ -0,0 +1,101 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
module Rumld
|
4
|
+
describe 'Node' do
|
5
|
+
before(:each) do
|
6
|
+
@node = Rumld::Node.new(stub('tree', :doc_dir => '/chicken/noodle'), 'Rumld::Node')
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'to_dot for belongs_to relation is blank when there association is empty' do
|
10
|
+
assoc = stub('Assoc', :options => {})
|
11
|
+
@node.send(:to_dot_for_belongs_to, assoc).should be_empty
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'have an empty active record associations if the object does not have associations' do
|
15
|
+
@node.send(:active_record_associations).should == []
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'active record associations reflect on all associations when available' do
|
19
|
+
@node.send(:constant).expects(:reflect_on_all_associations).returns(['One'])
|
20
|
+
@node.send(:active_record_associations).should == ['One']
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'uses constant name to derive the constant' do
|
24
|
+
@node.send(:constant).should == Rumld::Node
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'uses the intersect of rdoc_insepctors all included modules and trees constant names to determine included modules' do
|
28
|
+
@node.tree.expects(:constant_names).returns(['A', 'C', 'A::D'])
|
29
|
+
@node.stubs(:rdoc_inspector).returns(stub('RDocInspector', :all_included_modules => ['A', 'B'] ))
|
30
|
+
@node.included_modules.should == ['A']
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'converts included_modules to_dot' do
|
34
|
+
@node.expects(:included_modules).returns(['NPR', 'Radio'])
|
35
|
+
@node.included_modules_to_dot.should == ['"Rumld::Node" -> "NPR" [style=dotted, arrowhead=empty]', '"Rumld::Node" -> "Radio" [style=dotted, arrowhead=empty]']
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should use self_to_dot in node_to_dot if there are no children' do
|
39
|
+
@node.expects(:self_to_dot).returns('No Children')
|
40
|
+
@node.expects(:children?).returns(false)
|
41
|
+
@node.node_to_dot.should == 'No Children'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should use self_to_dot and children node_to_dot if there are children' do
|
45
|
+
child = Rumld::Node.new(@node.tree, "#{@node.constant_name}::Considered")
|
46
|
+
@node.expects(:self_to_dot).returns('Children')
|
47
|
+
child.expects(:self_to_dot).returns('I am a child')
|
48
|
+
@node.children << child
|
49
|
+
|
50
|
+
@node.node_to_dot.no_whitespace.should match(/#{Regexp.escape(%(subgraphclusterNode{label="Node))}/ )
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should have a self_and_descendants' do
|
55
|
+
child = Rumld::Node.new(@node.tree, "#{@node.constant_name}::Considered")
|
56
|
+
child.expects(:self_and_descendants).returns([child]).at_least(1)
|
57
|
+
@node.children << child
|
58
|
+
@node.self_and_descendants.should == [@node, child]
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'by default it should have no children' do
|
62
|
+
@node.children.should == []
|
63
|
+
@node.children?.should == false
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should not be a parent of a constant at the same level in the module tree' do
|
67
|
+
@node = Rumld::Node.new(stub('tree', :doc_dir => '/chicken/noodle'), 'Object')
|
68
|
+
@node.should_be_parent_of?('Rumld').should be_false
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should be a parent of a constant one level deeper in the module tree' do
|
72
|
+
@node.should_be_parent_of?("#{@node.constant_name}::Considered").should be_true
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should not be a parent of itself' do
|
76
|
+
@node.should_be_parent_of?("#{@node.constant_name}").should be_false
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should not be a parent of a constant in the wrong module space' do
|
80
|
+
@node.should_be_parent_of?("Piggly::#{@node.constant_name}::Considered").should be_false
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should not be a parent of a constant two levels deeper than itself' do
|
84
|
+
@node.should_be_parent_of?("#{@node.constant_name}::Considered::Modules").should be_false
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'doc_dir is delegated to underlying tree' do
|
88
|
+
@node.tree.doc_dir.should == @node.doc_dir
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'constant_is_module is delegated to the underlying rdoc_inspector' do
|
92
|
+
@node.expects(:rdoc_inspector).returns(stub('RDocInspector', :doc_is_for_module? => true))
|
93
|
+
@node.constant_is_module?.should be_true
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'methods_by_section is delegated to undelrying rdoc_inspector' do
|
97
|
+
@node.expects(:rdoc_inspector).returns(stub('RDocInspector', :methods_by_section => {}))
|
98
|
+
@node.methods_by_section.should == {}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
#class Rumld::RDocInspectorTest < Test::Unit::TestCase
|
4
|
+
#
|
5
|
+
# def setup_rdoc
|
6
|
+
# `rdoc #{File.dirname(__FILE__).gsub(' ', '\\ ')}`
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
# def teardown
|
10
|
+
# `rm -rf #{File.join(File.dirname(__FILE__), 'doc').gsub(' ', '\\ ')}`
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# def setup
|
14
|
+
# @node = stub('Node', :constant_name => 'Rumld::RDocInspector', :doc_dir => File.join(File.dirname(__FILE__), '..', 'doc'))
|
15
|
+
# @constant_name = 'Rumld::RdocInspectorTest'
|
16
|
+
# @rdoc_inspector = Rumld::RDocInspector.new(@node, @constant_name)
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# def test_doc_file_for
|
20
|
+
# assert_equal 'hello/world/classes/How/Are/You.html', Rumld::RDocInspector.doc_file_for('hello/world', 'How::Are::You')
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# def test_all_included_modules
|
24
|
+
# string = %(
|
25
|
+
# <html><body><div id="includes">
|
26
|
+
# <h3 class="section-bar">Included Modules</h3>
|
27
|
+
#
|
28
|
+
# <div id="includes-list">
|
29
|
+
# <span class="include-name">Two::Towers</span>
|
30
|
+
# <span class="include-name"><a href="AccountModel/AccountImport.html">AccountModel::AccountImport</a></span>
|
31
|
+
# </div>
|
32
|
+
# </div></body></html>
|
33
|
+
# )
|
34
|
+
# @rdoc_inspector.expects(:doc).returns(Hpricot( string ))
|
35
|
+
# assert_equal ['Two::Towers', 'AccountModel::AccountImport'], @rdoc_inspector.all_included_modules
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# def test_all_included_modules_should_be_empty_when_no_matching_elements
|
39
|
+
# string = %(
|
40
|
+
# <html><body>
|
41
|
+
# </body></html>
|
42
|
+
# )
|
43
|
+
# @rdoc_inspector.expects(:doc).returns(Hpricot( string ))
|
44
|
+
# assert_equal [], @rdoc_inspector.all_included_modules
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# def test_doc_is_for_module_when_given_a_module_that_has_been_rdoced
|
48
|
+
# string = '<html><body><div id="classHeader">
|
49
|
+
# <table class="header-table">
|
50
|
+
# <tr class="top-aligned-row">
|
51
|
+
# <td><strong>Module</strong></td>
|
52
|
+
# <td class="class-name-in-header">Rumld::Grapher</td>
|
53
|
+
# </tr>
|
54
|
+
# </table>
|
55
|
+
# </div></body></html>'
|
56
|
+
# @rdoc_inspector.expects(:doc).returns(Hpricot( string ))
|
57
|
+
# assert @rdoc_inspector.doc_is_for_module?
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# def test_doc_is_for_module_when_given_a_class_that_has_been_rdoced
|
61
|
+
# string = '<html><body><div id="classHeader">
|
62
|
+
# <table class="header-table">
|
63
|
+
# <tr class="top-aligned-row">
|
64
|
+
# <td><strong>Class</strong></td>
|
65
|
+
# <td class="class-name-in-header">Rumld::Grapher</td>
|
66
|
+
# </tr>
|
67
|
+
# </table>
|
68
|
+
# </div></body></html>'
|
69
|
+
# @rdoc_inspector.expects(:doc).returns(Hpricot( string ))
|
70
|
+
# assert ! @rdoc_inspector.doc_is_for_module?
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# def test_doc_should_open_the_doc_for_file_and_yield_to_hpricot
|
74
|
+
# setup_rdoc
|
75
|
+
# assert_kind_of Hpricot, @rdoc_inspector.doc
|
76
|
+
# end
|
77
|
+
#
|
78
|
+
# def test_doc_file_for_should_delegate_to_class_methods
|
79
|
+
# Rumld::RDocInspector.expects(:doc_file_for).returns('hello')
|
80
|
+
# assert_equal 'hello', @rdoc_inspector.doc_file_for
|
81
|
+
# end
|
82
|
+
#
|
83
|
+
# def test_methods_by_section_has_public_instance_methods
|
84
|
+
# setup_rdoc
|
85
|
+
# result = @rdoc_inspector.methods_by_section
|
86
|
+
# assert result.has_key?(:public_instance)
|
87
|
+
# assert result[:public_instance].include?('test_methods_by_section_has_public_instance_methods()')
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
#end
|
91
|
+
#
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
## This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
2
|
+
## from the project root directory.
|
3
|
+
#ENV["RAILS_ENV"] = "test"
|
4
|
+
#require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
5
|
+
#require 'spec/rails'
|
6
|
+
#
|
7
|
+
#Spec::Runner.configure do |config|
|
8
|
+
# config.use_transactional_fixtures = true
|
9
|
+
# config.use_instantiated_fixtures = false
|
10
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures'
|
11
|
+
#
|
12
|
+
# # You can declare fixtures for each behaviour like this:
|
13
|
+
# # describe "...." do
|
14
|
+
# # fixtures :table_a, :table_b
|
15
|
+
# #
|
16
|
+
# # Alternatively, if you prefer to declare them only once, you can
|
17
|
+
# # do so here, like so ...
|
18
|
+
# #
|
19
|
+
# # config.global_fixtures = :table_a, :table_b
|
20
|
+
# #
|
21
|
+
# # If you declare global fixtures, be aware that they will be declared
|
22
|
+
# # for all of your examples, even those that don't use them.
|
23
|
+
#end
|
24
|
+
#
|
25
|
+
require 'stringio'
|
26
|
+
require 'rbconfig'
|
27
|
+
|
28
|
+
dir = File.dirname(__FILE__)
|
29
|
+
lib_path = File.expand_path("#{dir}/../lib")
|
30
|
+
$LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
|
31
|
+
$_spec_spec = true # Prevents Kernel.exit in various places
|
32
|
+
|
33
|
+
require 'rumld'
|
34
|
+
gem 'rspec'
|
35
|
+
require 'spec'
|
36
|
+
|
37
|
+
Spec::Runner.configure do |config|
|
38
|
+
config.mock_with :mocha
|
39
|
+
end
|
40
|
+
|
41
|
+
class << ActiveRecord::Base
|
42
|
+
def columns
|
43
|
+
[:id].collect{|i| ActiveRecord::ConnectionAdapters::Column.new(i, nil)}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module Abstract; end
|
48
|
+
class FirstAbstractUnit < ActiveRecord::Base
|
49
|
+
include Abstract
|
50
|
+
has_many :second_abstract_units
|
51
|
+
has_one :primary_abstract_unit, :class_name => 'SecondAbstractUnit'
|
52
|
+
end
|
53
|
+
|
54
|
+
class SecondAbstractUnit < ActiveRecord::Base
|
55
|
+
include Abstract
|
56
|
+
|
57
|
+
belongs_to :first_abstract_unit
|
58
|
+
end
|
59
|
+
|
60
|
+
class ThirdAbstractUnit < ActiveRecord::Base
|
61
|
+
belongs_to :stuff, :polymorphic => true
|
62
|
+
end
|
63
|
+
|
64
|
+
class FourthAbstractUnit < ActiveRecord::Base
|
65
|
+
has_many :third_abstract_units, :as => :stuff
|
66
|
+
end
|
67
|
+
|
68
|
+
class String
|
69
|
+
def no_whitespace
|
70
|
+
gsub(/(\ |\n|\r)/, '')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class Nil
|
75
|
+
def no_whitespace
|
76
|
+
self
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class Rumld::GraphTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_to_dot_delegates_to_tree
|
6
|
+
obj = Rumld::Graph.new('', [],[])
|
7
|
+
obj.expects(:tree).returns(stub('Tree', :to_dot => :to_dot))
|
8
|
+
assert_equal :to_dot, obj.to_dot
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_collect_possible_constant_names
|
12
|
+
assert_equal ["A", "A::B", "A::B::C", "A::B::C::D", "A::B::D", "A::C", "A::C::D", "A::D",
|
13
|
+
"B", "B::C", "B::C::D", "B::D",
|
14
|
+
"C", "C::D",
|
15
|
+
"D"], Rumld::Graph.new(nil, nil, nil).send(:collect_possible_constant_names, ['A', 'B', 'C', 'D'])
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_constants_defined
|
19
|
+
file = <<-EOV
|
20
|
+
class One
|
21
|
+
class Two::Three < One
|
22
|
+
include Eight
|
23
|
+
extend Nine
|
24
|
+
def function(one)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
module Four
|
28
|
+
end
|
29
|
+
class << self
|
30
|
+
end
|
31
|
+
|
32
|
+
class << Five
|
33
|
+
end
|
34
|
+
end
|
35
|
+
EOV
|
36
|
+
assert_equal( ['One', 'Two::Three', 'Four', 'Five'], Rumld::Graph.new(nil, nil, nil).send(:constants_defined, file.split("\n")))
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_files_to_process_should_use_the_files
|
40
|
+
grapher = Rumld::Graph.new(nil, [File.dirname(__FILE__),File.dirname(__FILE__)], [File.basename(__FILE__)])
|
41
|
+
assert_equal [__FILE__], grapher.send(:files_to_process)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class Rumld::NodeTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@node = Rumld::Node.new(stub('tree', :doc_dir => '/chicken/noodle'), 'Rumld::NodeTest')
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_to_dot_for_belongs_to_should_blank
|
9
|
+
assoc = stub('Assoc', :options => {})
|
10
|
+
assert @node.send(:to_dot_for_belongs_to, assoc).empty?
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def test_reflect_on_all_associations_without_an_active_record_object
|
15
|
+
@node = Rumld::Node.new(stub('tree', :doc_dir => '/chicken/noodle'), 'Rumld::Node')
|
16
|
+
assert_equal [], @node.send(:active_record_associations)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_reflect_on_all_associations_without_an_active_record_object
|
20
|
+
@node = Rumld::Node.new(stub('tree', :doc_dir => '/chicken/noodle'), 'Rumld::Node')
|
21
|
+
@node.send(:constant).expects(:reflect_on_all_associations).returns(['One'])
|
22
|
+
assert_equal ['One'], @node.send(:active_record_associations)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_constant
|
26
|
+
assert_equal Rumld::Node, Rumld::Node.new(stub('tree', :doc_dir => '/chicken/noodle'), 'Rumld::Node').send(:constant)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_active_record_associations
|
30
|
+
assert_equal Rumld::Node, Rumld::Node.new(stub('tree', :doc_dir => '/chicken/noodle'), 'Rumld::Node').send(:constant)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_included_modules_should_be_the_intersect_of_all_included_modules_and_rdocced_modules
|
34
|
+
@node.tree.expects(:constant_names).returns(['A', 'C', 'A::D'])
|
35
|
+
@node.stubs(:rdoc_inspector).returns(stub('RDocInspector', :all_included_modules => ['A', 'B'] ))
|
36
|
+
assert_equal ['A'], @node.included_modules
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_included_modules_to_dot
|
40
|
+
@node.expects(:included_modules).returns(['NPR', 'Radio'])
|
41
|
+
assert_equal( ['"Rumld::NodeTest" -> "NPR" [style=dotted, arrowhead=empty]', '"Rumld::NodeTest" -> "Radio" [style=dotted, arrowhead=empty]'], @node.included_modules_to_dot)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_node_to_dot_without_children
|
45
|
+
@node.expects(:self_to_dot).returns('No Children')
|
46
|
+
@node.expects(:children?).returns(false)
|
47
|
+
assert_equal 'No Children', @node.node_to_dot
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_node_to_dot_with_children
|
51
|
+
child = Rumld::Node.new(@node.tree, "#{@node.constant_name}::Considered")
|
52
|
+
@node.expects(:self_to_dot).returns('Children')
|
53
|
+
child.expects(:self_to_dot).returns('I am a child')
|
54
|
+
@node.children << child
|
55
|
+
|
56
|
+
assert_match( /#{Regexp.escape(%(subgraphclusterNodeTest{label="NodeTest))}/, @node.node_to_dot.no_whitespace)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_self_and_descendants
|
60
|
+
child = Rumld::Node.new(@node.tree, "#{@node.constant_name}::Considered")
|
61
|
+
child.expects(:self_and_descendants).returns([child]).at_least(1)
|
62
|
+
@node.children << child
|
63
|
+
assert_equal [@node, child], @node.self_and_descendants
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_children_should_default_to_an_array
|
67
|
+
assert_equal [], @node.children
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_children_empty_means_false_for_children?
|
71
|
+
assert ! @node.children?
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_children_not_empty_means_true_for_children?
|
75
|
+
@node.children << 'Hello'
|
76
|
+
assert @node.children?
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_constants_should_be_parent_of_regression_prevention_1
|
80
|
+
@node = Rumld::Node.new(stub('tree', :doc_dir => '/chicken/noodle'), 'Object')
|
81
|
+
assert ! @node.should_be_parent_of?('Rumld')
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_constants_one_module_level_deeper_should_be_child_of_node
|
85
|
+
assert @node.should_be_parent_of?('Rumld::NodeTest::Considered')
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_constants_should_not_be_parents_of_themselves
|
89
|
+
assert ! @node.should_be_parent_of?('Rumld::NodeTest')
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_constants_in_wrong_module_space_should_not_be_child_of_node
|
93
|
+
assert ! @node.should_be_parent_of?('This::Is::Rumld::NodeTest')
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_constants_one_module_level_deeper_in_wrong_module_space_should_not_be_child_of_node
|
97
|
+
assert ! @node.should_be_parent_of?('This::Is::Rumld::NodeTest::Considered')
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_constants_two_module_level_deeper_should_be_child_of_node
|
101
|
+
assert ! @node.should_be_parent_of?('Rumld::NodeTest::Considered::On')
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_doc_dir_is_delegated_to_nodes_tree
|
105
|
+
assert_equal @node.tree.doc_dir, @node.doc_dir
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_constant_is_module_is_delegated_to_rdoc_inspector_doc_is_for_module
|
109
|
+
@node.expects(:rdoc_inspector).returns(stub('RDocInspector', :doc_is_for_module? => true))
|
110
|
+
assert_equal true, @node.constant_is_module?
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_methods_by_section_is_delegated_to_rdoc_inspector
|
114
|
+
@node.expects(:rdoc_inspector).returns(stub('RDocInspector', :methods_by_section => {}))
|
115
|
+
assert_equal( {}, @node.methods_by_section )
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_format_methods_should_replace_block_bracketes
|
119
|
+
assert_equal "function(self = \\{ :page =\\> 1\\}) \\{ \\|self\\| ... \\}\\l", @node.send(:format_methods, ["function(self = { :page => 1}) { |self| ... }"])
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class Rumld::RDocInspectorTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup_rdoc
|
6
|
+
`rdoc #{File.dirname(__FILE__).gsub(' ', '\\ ')}`
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
`rm -rf #{File.join(File.dirname(__FILE__), 'doc').gsub(' ', '\\ ')}`
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@node = stub('Node', :constant_name => 'Rumld::RDocInspector', :doc_dir => File.join(File.dirname(__FILE__), '..', 'doc'))
|
15
|
+
@constant_name = 'Rumld::RdocInspectorTest'
|
16
|
+
@rdoc_inspector = Rumld::RDocInspector.new(@node, @constant_name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_doc_file_for
|
20
|
+
assert_equal 'hello/world/classes/How/Are/You.html', Rumld::RDocInspector.doc_file_for('hello/world', 'How::Are::You')
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_all_included_modules
|
24
|
+
string = %(
|
25
|
+
<html><body><div id="includes">
|
26
|
+
<h3 class="section-bar">Included Modules</h3>
|
27
|
+
|
28
|
+
<div id="includes-list">
|
29
|
+
<span class="include-name">Two::Towers</span>
|
30
|
+
<span class="include-name"><a href="AccountModel/AccountImport.html">AccountModel::AccountImport</a></span>
|
31
|
+
</div>
|
32
|
+
</div></body></html>
|
33
|
+
)
|
34
|
+
@rdoc_inspector.expects(:doc).returns(Hpricot( string ))
|
35
|
+
assert_equal ['Two::Towers', 'AccountModel::AccountImport'], @rdoc_inspector.all_included_modules
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_all_included_modules_should_be_empty_when_no_matching_elements
|
39
|
+
string = %(
|
40
|
+
<html><body>
|
41
|
+
</body></html>
|
42
|
+
)
|
43
|
+
@rdoc_inspector.expects(:doc).returns(Hpricot( string ))
|
44
|
+
assert_equal [], @rdoc_inspector.all_included_modules
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_doc_is_for_module_when_given_a_module_that_has_been_rdoced
|
48
|
+
string = '<html><body><div id="classHeader">
|
49
|
+
<table class="header-table">
|
50
|
+
<tr class="top-aligned-row">
|
51
|
+
<td><strong>Module</strong></td>
|
52
|
+
<td class="class-name-in-header">Rumld::Grapher</td>
|
53
|
+
</tr>
|
54
|
+
</table>
|
55
|
+
</div></body></html>'
|
56
|
+
@rdoc_inspector.expects(:doc).returns(Hpricot( string ))
|
57
|
+
assert @rdoc_inspector.doc_is_for_module?
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_doc_is_for_module_when_given_a_class_that_has_been_rdoced
|
61
|
+
string = '<html><body><div id="classHeader">
|
62
|
+
<table class="header-table">
|
63
|
+
<tr class="top-aligned-row">
|
64
|
+
<td><strong>Class</strong></td>
|
65
|
+
<td class="class-name-in-header">Rumld::Grapher</td>
|
66
|
+
</tr>
|
67
|
+
</table>
|
68
|
+
</div></body></html>'
|
69
|
+
@rdoc_inspector.expects(:doc).returns(Hpricot( string ))
|
70
|
+
assert ! @rdoc_inspector.doc_is_for_module?
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_doc_should_open_the_doc_for_file_and_yield_to_hpricot
|
74
|
+
setup_rdoc
|
75
|
+
assert_kind_of Hpricot, @rdoc_inspector.doc
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_doc_file_for_should_delegate_to_class_methods
|
79
|
+
Rumld::RDocInspector.expects(:doc_file_for).returns('hello')
|
80
|
+
assert_equal 'hello', @rdoc_inspector.doc_file_for
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_methods_by_section_has_public_instance_methods
|
84
|
+
setup_rdoc
|
85
|
+
result = @rdoc_inspector.methods_by_section
|
86
|
+
assert result.has_key?(:public_instance)
|
87
|
+
assert result[:public_instance].include?('test_methods_by_section_has_public_instance_methods()')
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class Rumld::TreeTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@tree = Rumld::Tree.new(nil, [])
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_doc_dir_is_delegated_graph
|
9
|
+
@tree.expects(:graph).returns(stub('Graph', :doc_dir => :doc_dir))
|
10
|
+
assert_equal :doc_dir, @tree.doc_dir
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_build_nodes_with_multi_level_constant_names
|
14
|
+
@tree = Rumld::Tree.new(nil, ['A', 'A::B', 'A::B::C'])
|
15
|
+
assert_equal ['A'], @tree.nodes.collect{|n| n.constant_name}
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_build_nodes_with_single_level_constant_names
|
19
|
+
@tree = Rumld::Tree.new(nil, ['A', 'A::B'])
|
20
|
+
assert_equal ['A'], @tree.nodes.collect{|n| n.constant_name}
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_all_nodes
|
24
|
+
@tree = Rumld::Tree.new(nil, ['A', 'A::B'])
|
25
|
+
assert_equal ['A', 'A::B'], @tree.all_nodes.collect{|n| n.constant_name}
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_node_for_should_return_a_node_that_matches_the_given_constant
|
29
|
+
node = stub("Node", :constant => self.class)
|
30
|
+
@tree.expects(:all_nodes).returns([node])
|
31
|
+
assert_equal node, @tree.node_for(self.class)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_node_for_should_return_a_node_that_matches_the_given_constant_name
|
35
|
+
node = stub("Node", :constant => self.class, :constant_name => "Awesome")
|
36
|
+
@tree.expects(:all_nodes).returns([node])
|
37
|
+
assert_equal node, @tree.node_for('Awesome')
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_inheritence_edge_to_dot
|
41
|
+
node = stub("Node", :inheritence_edge_to_dot => ['hello world'])
|
42
|
+
@tree.expects(:all_nodes).returns([node])
|
43
|
+
assert_equal 'hello world', @tree.send(:draw_inheritence_edges)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_to_dot_calls_draw_nodes_and_draw_included_modules
|
47
|
+
@tree.expects(:draw_nodes).returns('Draw Nodes')
|
48
|
+
@tree.expects(:draw_included_modules).returns('Draw Included Modules')
|
49
|
+
@tree.expects(:draw_associations).returns('Draw Associations')
|
50
|
+
@tree.expects(:draw_inheritence_edges).returns('Draw Inheritence Edges')
|
51
|
+
assert_equal( %(digraph uml_diagram {
|
52
|
+
graph[overlap=false, splines=true]
|
53
|
+
Draw Nodes
|
54
|
+
Draw Included Modules
|
55
|
+
Draw Associations
|
56
|
+
Draw Inheritence Edges
|
57
|
+
}).no_whitespace, @tree.to_dot.no_whitespace)
|
58
|
+
end
|
59
|
+
end
|
data/test/test_helper.rb
ADDED