inch 0.4.10 → 0.5.0.rc1

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 (148) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -11
  3. data/Gemfile +2 -5
  4. data/README.md +1 -1
  5. data/Rakefile +2 -2
  6. data/bin/inch +3 -3
  7. data/config/defaults.rb +0 -7
  8. data/inch.gemspec +7 -7
  9. data/lib/inch.rb +9 -9
  10. data/lib/inch/api.rb +10 -10
  11. data/lib/inch/api/compare.rb +2 -2
  12. data/lib/inch/api/compare/code_objects.rb +3 -2
  13. data/lib/inch/api/compare/codebases.rb +1 -1
  14. data/lib/inch/api/diff.rb +10 -7
  15. data/lib/inch/api/filter.rb +1 -1
  16. data/lib/inch/api/get.rb +1 -1
  17. data/lib/inch/api/options/base.rb +4 -4
  18. data/lib/inch/api/options/filter.rb +4 -0
  19. data/lib/inch/api/options/suggest.rb +5 -1
  20. data/lib/inch/api/stats.rb +1 -0
  21. data/lib/inch/api/suggest.rb +10 -9
  22. data/lib/inch/cli.rb +6 -6
  23. data/lib/inch/cli/arguments.rb +2 -2
  24. data/lib/inch/cli/command.rb +15 -15
  25. data/lib/inch/cli/command/base.rb +4 -4
  26. data/lib/inch/cli/command/console.rb +5 -5
  27. data/lib/inch/cli/command/diff.rb +8 -7
  28. data/lib/inch/cli/command/inspect.rb +4 -5
  29. data/lib/inch/cli/command/list.rb +4 -4
  30. data/lib/inch/cli/command/options/base.rb +8 -8
  31. data/lib/inch/cli/command/options/base_list.rb +5 -9
  32. data/lib/inch/cli/command/options/console.rb +3 -4
  33. data/lib/inch/cli/command/options/diff.rb +6 -8
  34. data/lib/inch/cli/command/options/inspect.rb +2 -2
  35. data/lib/inch/cli/command/options/list.rb +2 -3
  36. data/lib/inch/cli/command/options/show.rb +2 -2
  37. data/lib/inch/cli/command/options/stats.rb +1 -2
  38. data/lib/inch/cli/command/options/suggest.rb +3 -6
  39. data/lib/inch/cli/command/output/base.rb +6 -4
  40. data/lib/inch/cli/command/output/console.rb +5 -4
  41. data/lib/inch/cli/command/output/diff.rb +6 -6
  42. data/lib/inch/cli/command/output/inspect.rb +8 -6
  43. data/lib/inch/cli/command/output/list.rb +1 -0
  44. data/lib/inch/cli/command/output/show.rb +5 -4
  45. data/lib/inch/cli/command/output/stats.rb +21 -21
  46. data/lib/inch/cli/command/output/suggest.rb +27 -30
  47. data/lib/inch/cli/command/show.rb +4 -4
  48. data/lib/inch/cli/command/stats.rb +4 -4
  49. data/lib/inch/cli/command/suggest.rb +6 -6
  50. data/lib/inch/cli/command_parser.rb +5 -6
  51. data/lib/inch/cli/sparkline_helper.rb +6 -6
  52. data/lib/inch/cli/trace_helper.rb +1 -1
  53. data/lib/inch/cli/yardopts_helper.rb +3 -4
  54. data/lib/inch/code_object.rb +3 -3
  55. data/lib/inch/code_object/converter.rb +8 -6
  56. data/lib/inch/code_object/provider.rb +1 -1
  57. data/lib/inch/code_object/provider/yard.rb +12 -10
  58. data/lib/inch/code_object/provider/yard/docstring.rb +19 -51
  59. data/lib/inch/code_object/provider/yard/nodoc_helper.rb +4 -4
  60. data/lib/inch/code_object/provider/yard/object.rb +10 -12
  61. data/lib/inch/code_object/provider/yard/object/base.rb +27 -48
  62. data/lib/inch/code_object/provider/yard/object/method_object.rb +10 -47
  63. data/lib/inch/code_object/provider/yard/object/method_parameter_object.rb +6 -10
  64. data/lib/inch/code_object/provider/yard/object/method_signature.rb +8 -12
  65. data/lib/inch/code_object/provider/yard/object/namespace_object.rb +4 -1
  66. data/lib/inch/code_object/provider/yard/parser.rb +3 -3
  67. data/lib/inch/code_object/proxy.rb +9 -10
  68. data/lib/inch/code_object/proxy/base.rb +10 -12
  69. data/lib/inch/code_object/proxy/method_object.rb +2 -3
  70. data/lib/inch/code_object/proxy/method_parameter_object.rb +3 -5
  71. data/lib/inch/codebase.rb +5 -4
  72. data/lib/inch/codebase/objects_filter.rb +4 -2
  73. data/lib/inch/codebase/serializer.rb +3 -3
  74. data/lib/inch/config.rb +2 -2
  75. data/lib/inch/config/base.rb +1 -0
  76. data/lib/inch/config/codebase.rb +4 -4
  77. data/lib/inch/core_ext.rb +1 -1
  78. data/lib/inch/core_ext/string.rb +1 -1
  79. data/lib/inch/evaluation.rb +15 -16
  80. data/lib/inch/evaluation/file.rb +1 -1
  81. data/lib/inch/evaluation/grade_list.rb +2 -2
  82. data/lib/inch/evaluation/object_schema.rb +1 -1
  83. data/lib/inch/evaluation/proxy.rb +7 -8
  84. data/lib/inch/evaluation/proxy/base.rb +10 -13
  85. data/lib/inch/evaluation/proxy/constant_object.rb +1 -1
  86. data/lib/inch/evaluation/proxy/method_object.rb +5 -12
  87. data/lib/inch/evaluation/proxy/module_object.rb +1 -1
  88. data/lib/inch/evaluation/proxy/namespace_object.rb +1 -1
  89. data/lib/inch/evaluation/role/base.rb +1 -1
  90. data/lib/inch/evaluation/role/method.rb +2 -2
  91. data/lib/inch/evaluation/role/method_parameter.rb +1 -2
  92. data/lib/inch/evaluation/role/object.rb +2 -2
  93. data/lib/inch/rake.rb +2 -2
  94. data/lib/inch/rake/suggest.rb +2 -3
  95. data/lib/inch/utils/shell_helper.rb +1 -1
  96. data/lib/inch/utils/ui.rb +5 -5
  97. data/lib/inch/utils/weighted_list.rb +3 -2
  98. data/lib/inch/version.rb +1 -1
  99. data/test/fixtures/simple/lib/broken.rb +7 -35
  100. data/test/fixtures/simple/lib/foo.rb +1 -22
  101. data/test/integration/api/compare/codebases.rb +1 -1
  102. data/test/integration/cli/command/console_test.rb +5 -5
  103. data/test/integration/cli/command/inspect_test.rb +5 -4
  104. data/test/integration/cli/command/list_test.rb +4 -3
  105. data/test/integration/cli/command/show_test.rb +4 -4
  106. data/test/integration/cli/command/stats_test.rb +2 -2
  107. data/test/integration/cli/command/suggest_test.rb +10 -10
  108. data/test/integration/stats_options_test.rb +3 -3
  109. data/test/integration/visibility_options_test.rb +13 -13
  110. data/test/shared/base_list.rb +3 -4
  111. data/test/test_helper.rb +6 -16
  112. data/test/unit/api/filter_test.rb +7 -7
  113. data/test/unit/api/get_test.rb +1 -1
  114. data/test/unit/api/list_test.rb +1 -1
  115. data/test/unit/api/options/base_test.rb +3 -3
  116. data/test/unit/api/stats_test.rb +1 -1
  117. data/test/unit/api/suggest_test.rb +3 -3
  118. data/test/unit/cli/arguments_test.rb +1 -1
  119. data/test/unit/cli/command/base_test.rb +1 -1
  120. data/test/unit/cli/command/options/base_list_test.rb +2 -2
  121. data/test/unit/cli/command/options/base_object_test.rb +1 -1
  122. data/test/unit/cli/command/options/base_test.rb +1 -1
  123. data/test/unit/cli/command_parser_test.rb +2 -2
  124. data/test/unit/cli/trace_helper_test.rb +1 -1
  125. data/test/unit/cli/yardopts_helper_test.rb +3 -4
  126. data/test/unit/code_object/converter_test.rb +1 -1
  127. data/test/unit/code_object/provider/yard/docstring_test.rb +28 -106
  128. data/test/unit/code_object/provider/yard/nodoc_helper_test.rb +5 -6
  129. data/test/unit/code_object/provider/yard/object/method_object_test.rb +10 -20
  130. data/test/unit/code_object/provider/yard_test.rb +4 -4
  131. data/test/unit/code_object/provider_test.rb +1 -1
  132. data/test/unit/code_object/proxy/method_object_test.rb +262 -382
  133. data/test/unit/code_object/proxy_test.rb +1 -1
  134. data/test/unit/codebase/objects_test.rb +2 -2
  135. data/test/unit/codebase/proxy_test.rb +1 -1
  136. data/test/unit/config/codebase_test.rb +1 -1
  137. data/test/unit/evaluation/role/base_test.rb +2 -2
  138. data/test/unit/utils/ui_test.rb +4 -4
  139. data/test/unit/utils/weighted_list_test.rb +4 -7
  140. metadata +4 -14
  141. data/.rubocop.yml +0 -15
  142. data/.rubocop_todo.yml +0 -94
  143. data/lib/inch/code_object/provider/yard/object/class_variable_object.rb +0 -12
  144. data/lib/inch/code_object/proxy/class_variable_object.rb +0 -8
  145. data/lib/inch/evaluation/proxy/class_variable_object.rb +0 -19
  146. data/lib/inch/evaluation/role/class_variable.rb +0 -55
  147. data/test/fixtures/simple/lib/broken_ruby_2_0_features.rb +0 -7
  148. data/test/fixtures/simple/lib/directives.rb +0 -8
@@ -1,17 +1,14 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../../../../../test_helper")
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../../../test_helper')
2
2
 
3
3
  describe ::Inch::CodeObject::Provider::YARD::Parser do
4
4
  before do
5
5
  @config = Inch::Config.codebase
6
- @parser = ::Inch::CodeObject::Provider::YARD::Parser.parse(
7
- fixture_path(:simple), @config)
6
+ @parser = ::Inch::CodeObject::Provider::YARD::Parser.parse(fixture_path(:simple), @config)
8
7
  @objects = @parser.objects
9
8
  end
10
9
 
11
10
  it "should work for Overloading#params_also_in_overloads" do
12
- m = @objects.find do |o|
13
- o.fullname == "Overloading#params_also_in_overloads"
14
- end
11
+ m = @objects.detect { |o| o.fullname == 'Overloading#params_also_in_overloads' }
15
12
 
16
13
  assert m.has_code_example?
17
14
 
@@ -19,8 +16,7 @@ describe ::Inch::CodeObject::Provider::YARD::Parser do
19
16
  assert_equal 2, m.parameters.size # at this moment, this counts all parameters in all overloaded signatures
20
17
 
21
18
  signature = m.signatures[0]
22
- assert_equal "params_also_in_overloads(user_options = {})",
23
- signature.signature
19
+ assert_equal "params_also_in_overloads(user_options = {})", signature.signature
24
20
  assert_equal 1, signature.parameters.size
25
21
  refute signature.parameter(:user_options).nil?
26
22
  assert signature.has_code_example?
@@ -28,8 +24,7 @@ describe ::Inch::CodeObject::Provider::YARD::Parser do
28
24
 
29
25
  signature = m.signatures[1]
30
26
  assert_equal "params_also_in_overloads()", signature.signature
31
- assert signature.parameters.empty?,
32
- "Should have been empty: #{signature.parameters.inspect}"
27
+ assert signature.parameters.empty?, "Should have been empty: #{signature.parameters.inspect}"
33
28
  assert signature.has_code_example?
34
29
  refute signature.has_doc?
35
30
 
@@ -42,9 +37,7 @@ describe ::Inch::CodeObject::Provider::YARD::Parser do
42
37
  end
43
38
 
44
39
  it "should work for Overloading#params_only_in_overloads" do
45
- m = @objects.find do |o|
46
- o.fullname == "Overloading#params_only_in_overloads"
47
- end
40
+ m = @objects.detect { |o| o.fullname == 'Overloading#params_only_in_overloads' }
48
41
 
49
42
  assert m.has_code_example?
50
43
 
@@ -53,8 +46,7 @@ describe ::Inch::CodeObject::Provider::YARD::Parser do
53
46
 
54
47
  signature = m.signatures[0]
55
48
  assert_equal "params_only_in_overloads()", signature.signature
56
- assert signature.parameters.empty?,
57
- "Should have been empty: #{signature.parameters.inspect}"
49
+ assert signature.parameters.empty?, "Should have been empty: #{signature.parameters.inspect}"
58
50
  assert signature.has_code_example?
59
51
  refute signature.has_doc?
60
52
 
@@ -70,19 +62,17 @@ describe ::Inch::CodeObject::Provider::YARD::Parser do
70
62
  assert_equal 1, signature.parameters.size
71
63
  refute signature.parameter(:user_options).nil?
72
64
  assert signature.has_code_example?
73
- # assert signature.has_doc?
65
+ #assert signature.has_doc?
74
66
  end
75
67
 
76
68
  it "should work" do
77
- m = @objects.find do |o|
78
- o.fullname == "Foo::Bar#method_with_unstructured_doc"
79
- end
69
+ m = @objects.detect { |o| o.fullname == 'Foo::Bar#method_with_unstructured_doc' }
80
70
  assert_equal 1, m.signatures.size
81
71
  assert_equal 1, m.parameters.size
82
72
  end
83
73
 
84
74
  it "should work 2" do
85
- m = @objects.find { |o| o.fullname == "Foo#method_with_splat_parameter" }
75
+ m = @objects.detect { |o| o.fullname == 'Foo#method_with_splat_parameter' }
86
76
  assert_equal 1, m.signatures.size
87
77
  assert_equal 1, m.parameters.size
88
78
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../../../test_helper")
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
2
2
 
3
3
  describe ::Inch::CodeObject::Provider::YARD do
4
4
  let(:described_class) { ::Inch::CodeObject::Provider::YARD }
@@ -12,14 +12,14 @@ describe ::Inch::CodeObject::Provider::YARD do
12
12
  fullname = "Foo#b"
13
13
 
14
14
  provider1 = described_class.parse(fixture_path(:diff1))
15
- object1 = provider1.objects.find { |o| o.fullname == fullname }
15
+ object1 = provider1.objects.detect { |o| o.fullname == fullname }
16
16
 
17
17
  provider2 = described_class.parse(fixture_path(:diff2))
18
- object2 = provider2.objects.find { |o| o.fullname == fullname }
18
+ object2 = provider2.objects.detect { |o| o.fullname == fullname }
19
19
 
20
20
  refute object1.nil?
21
21
  refute object2.nil?
22
22
  assert object1.object_id != object2.object_id
23
23
  end
24
24
 
25
- end
25
+ end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../../test_helper")
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
2
 
3
3
  describe ::Inch::CodeObject::Provider do
4
4
  it "should parse all objects" do
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../../../test_helper")
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
2
2
 
3
3
  describe ::Inch::CodeObject::Proxy::MethodObject do
4
4
  before do
@@ -6,55 +6,47 @@ describe ::Inch::CodeObject::Proxy::MethodObject do
6
6
  @objects = @codebase.objects
7
7
  end
8
8
 
9
- describe "Scores" do
10
- #
11
- it "should not count tags that are transitive" do
12
- m = @objects.find("InchTest::Deprecated::ClassMethods")
13
- assert_equal 0, m.score
14
- assert m.undocumented?
15
- end
9
+ def test_transitive_tags_dont_matter
10
+ m = @objects.find("InchTest::Deprecated::ClassMethods")
11
+ assert_equal 0, m.score
12
+ assert m.undocumented?
13
+ end
16
14
 
17
- it "counts a @raise tag" do
18
- m = @objects.find("InchTest#raising_method_with_comment")
19
- assert m.score > 0
20
- refute m.undocumented?
21
- end
15
+ def test_raising_method_with_comment
16
+ m = @objects.find("InchTest#raising_method_with_comment")
17
+ assert m.score > 0
18
+ refute m.undocumented?
19
+ end
22
20
 
23
- it "should not count a call to `raise`" do
24
- m = @objects.find("InchTest#raising_method")
25
- assert_equal 0, m.score
26
- assert m.undocumented?
27
- end
21
+ def test_raising_method
22
+ m = @objects.find("InchTest#raising_method")
23
+ assert_equal 0, m.score
24
+ assert m.undocumented?
25
+ end
28
26
 
29
- it "should not count a call to `yield`" do
30
- m = @objects.find("InchTest#yielding_method")
31
- assert_equal 0, m.score
32
- assert m.undocumented?
33
- end
27
+ def test_yielding_method
28
+ m = @objects.find("InchTest#yielding_method")
29
+ assert_equal 0, m.score
30
+ assert m.undocumented?
34
31
  end
35
32
 
36
- describe "Taggings" do
37
- #
38
- it "should recognize forms of @private-tags" do
39
- %w( InchTest#method_with_private_tag
40
- InchTest#private_method_with_tomdoc).each do |fullname|
41
- m = @objects.find(fullname)
42
- assert m.tagged_as_private?
43
- end
33
+ def test_tagged_as_private
34
+ %w( InchTest#method_with_private_tag
35
+ InchTest#private_method_with_tomdoc).each do |fullname|
36
+ m = @objects.find(fullname)
37
+ assert m.tagged_as_private?
44
38
  end
39
+ end
45
40
 
46
- it "should recognize forms of internal-tags" do
47
- # @api private in YARD
48
- # Internal: in TomDoc
49
- %w( InchTest#private_api_with_yard
50
- InchTest#internal_api_with_tomdoc).each do |fullname|
51
- m = @objects.find(fullname)
52
- assert m.tagged_as_internal_api?
53
- end
41
+ def test_tagged_as_internal_api
42
+ %w( InchTest#private_api_with_yard
43
+ InchTest#internal_api_with_tomdoc).each do |fullname|
44
+ m = @objects.find(fullname)
45
+ assert m.tagged_as_internal_api?
54
46
  end
55
47
  end
56
48
 
57
- it "should recognize undocumented methods without parameters" do
49
+ def test_method_without_doc
58
50
  m = @objects.find("Foo::Bar#method_without_doc")
59
51
  refute m.has_doc?
60
52
  refute m.has_parameters?
@@ -64,7 +56,7 @@ describe ::Inch::CodeObject::Proxy::MethodObject do
64
56
  assert_equal 0, m.score
65
57
  end
66
58
 
67
- it "should recognize missing parameter documentation" do
59
+ def test_method_with_missing_param_doc
68
60
  m = @objects.find("Foo::Bar#method_with_missing_param_doc")
69
61
  assert m.has_doc?
70
62
  assert m.has_parameters?
@@ -75,399 +67,287 @@ describe ::Inch::CodeObject::Proxy::MethodObject do
75
67
  assert p.mentioned?
76
68
  p = m.parameter(:param2)
77
69
  assert p.mentioned?
78
-
79
- # not mentioned
80
70
  p = m.parameter(:param3)
81
71
  refute p.mentioned?
82
72
 
83
73
  assert m.score
84
74
  end
85
75
 
86
- describe "Documentation Styles" do
87
- #
88
- it "should handle YARD when no additional docstring is given" do
89
- m = @objects.find("Foo::Bar#method_without_docstring")
90
- refute m.has_doc?
91
- assert m.has_parameters?
92
- assert m.return_mentioned?
93
-
94
- assert m.score
95
- end
96
-
97
- it "should handle YARD when only @return is given" do
98
- m = @objects.find("Foo::Bar#method_without_params_or_docstring")
99
- refute m.has_doc?
100
- refute m.has_parameters?
101
- assert m.return_mentioned?
102
- refute m.return_described?
103
-
104
- assert m.score
105
- end
106
-
107
- it "should handle unusable return value when only @return [void] is given" do
108
- m = @objects.find("Foo::Bar#method_without_usable_return_value")
109
- assert m.return_mentioned?
110
- assert m.return_described?
111
-
112
- assert m.score
113
- end
114
-
115
- it "should handle RDoc" do
116
- m = @objects.find("Foo::Bar#method_with_rdoc_doc")
117
- assert m.has_doc?
118
- assert m.has_parameters?
119
- p = m.parameter(:param1)
120
- assert p.mentioned? # mentioned in docs, correctly
121
- refute m.return_mentioned?
122
-
123
- assert m.score
124
- end
125
-
126
- it "should handle other RDoc styles" do
127
- m = @objects.find("Foo::Bar#method_with_other_rdoc_doc")
128
- assert m.has_doc?
129
- assert m.has_parameters?
130
- p = m.parameter(:param1)
131
- assert p.mentioned? # mentioned in docs, correctly
132
- p = m.parameter(:param2)
133
- assert p.mentioned? # mentioned in docs, correctly
134
- p = m.parameter(:param3)
135
- assert p.mentioned? # mentioned in docs, correctly
136
- refute m.return_mentioned?
137
-
138
- assert m.score
139
- end
76
+ def test_method_with_wrong_doc
77
+ m = @objects.find("Foo::Bar#method_with_wrong_doc")
78
+ assert m.has_doc?
79
+ assert m.has_parameters?
80
+ assert m.return_mentioned?
140
81
 
141
- it "should handle yet other RDoc styles" do
142
- m = @objects.find("Foo::Bar#method_with_yet_another_rdoc_doc")
143
- assert m.has_doc?
144
- assert m.has_parameters?
145
- p = m.parameter(:param1)
146
- assert p.mentioned? # mentioned in docs, correctly
147
- p = m.parameter(:param2)
148
- assert p.mentioned? # mentioned in docs, correctly
82
+ assert_equal 4, m.parameters.size
83
+ p = m.parameter(:param1)
84
+ assert p.mentioned? # mentioned in docs, correctly
85
+ refute p.wrongly_mentioned?
86
+ p = m.parameter(:param2)
87
+ refute p.mentioned?
88
+ refute p.wrongly_mentioned? # not mentioned in docs at all
89
+ p = m.parameter(:param3)
90
+ refute p.mentioned?
91
+ refute p.wrongly_mentioned? # not mentioned in docs at all
92
+ p = m.parameter(:param4)
93
+ assert p.mentioned?
94
+ assert p.wrongly_mentioned? # mentioned in docs, but not present
149
95
 
150
- assert m.score
151
- end
96
+ assert m.score
97
+ end
152
98
 
153
- it "should handle unstructured doc styles" do
154
- m = @objects.find("Foo::Bar#method_with_unstructured_doc")
155
- assert m.has_doc?
156
- assert m.has_parameters?
157
- p = m.parameter(:param1)
158
- assert p.mentioned? # mentioned in docs, correctly
159
- refute m.return_mentioned?
99
+ def test_method_with_full_doc
100
+ m = @objects.find("Foo::Bar#method_with_full_doc")
101
+ assert m.has_doc?
102
+ assert m.has_parameters?
103
+ assert m.return_mentioned?
160
104
 
161
- assert m.score
105
+ assert_equal 2, m.parameters.size
106
+ m.parameters.each do |param|
107
+ assert param.mentioned?
108
+ assert param.typed?
109
+ assert param.described?
110
+ refute param.wrongly_mentioned?
162
111
  end
163
112
 
164
- it "should handle unstructured doc styles with an undocumented param" do
165
- m = @objects.find("Foo::Bar#method_with_unstructured_doc_missing_params")
166
- assert m.has_doc?
167
- assert m.has_parameters?
168
- p = m.parameter(:format)
169
- refute p.mentioned? # mentioned in docs, correctly
170
- refute m.return_mentioned?
171
-
172
- assert m.score
173
- end
113
+ assert_equal 100, m.score
114
+ end
174
115
 
175
- it "should handle methods (without parameters) that have only a docstring" \
176
- " (text comment)" do
177
- m = @objects.find("Foo::Bar#method_without_params_or_return_type")
178
- assert m.has_doc?
179
- refute m.has_parameters?
180
- refute m.return_mentioned?
116
+ def test_method_without_params_or_return_type
117
+ m = @objects.find("Foo::Bar#method_without_params_or_return_type")
118
+ assert m.has_doc?
119
+ refute m.has_parameters?
120
+ refute m.return_mentioned?
181
121
 
182
- assert m.score
183
- end
122
+ assert m.score
184
123
  end
185
124
 
186
- describe "Getter/Setter Handling" do
125
+ def test_method_without_docstring
126
+ m = @objects.find("Foo::Bar#method_without_docstring")
127
+ refute m.has_doc?
128
+ assert m.has_parameters?
129
+ assert m.return_mentioned?
187
130
 
188
- it "should recognize a getter method" do
189
- m = @objects.find("InchTest#getter")
190
- assert m.getter?, "should be a getter"
191
- refute m.setter?
192
- refute m.has_doc?
193
- assert_equal 0, m.score
194
- end
131
+ assert m.score
132
+ end
195
133
 
196
- it "should recognize a setter method" do
197
- m = @objects.find("InchTest#attr_setter=")
198
- refute m.getter?
199
- assert m.setter?, "should be a setter"
200
- refute m.has_doc?
201
- assert_equal 0, m.score
202
- end
134
+ def test_method_without_params_or_docstring
135
+ m = @objects.find("Foo::Bar#method_without_params_or_docstring")
136
+ refute m.has_doc?
137
+ refute m.has_parameters?
138
+ assert m.return_mentioned?
203
139
 
204
- it "should recognize a manually defined setter method" do
205
- m = @objects.find("InchTest#manual_setter=")
206
- refute m.getter?
207
- assert m.setter?, "should be a setter"
208
- refute m.has_doc?
209
- assert_equal 0, m.score
210
- end
140
+ assert m.score
141
+ end
211
142
 
212
- it "should recognize a getter in a manually defined getter/setter pair" do
213
- m = @objects.find("InchTest#manual_getset")
214
- assert m.getter?, "should be a getter"
215
- refute m.setter?
216
- refute m.has_doc?
217
- assert_equal 0, m.score
218
- end
143
+ def test_method_with_rdoc_doc
144
+ m = @objects.find("Foo::Bar#method_with_rdoc_doc")
145
+ assert m.has_doc?
146
+ assert m.has_parameters?
147
+ p = m.parameter(:param1)
148
+ assert p.mentioned? # mentioned in docs, correctly
149
+ refute m.return_mentioned?
219
150
 
220
- it "should recognize a setter in a manually defined getter/setter pair" do
221
- m = @objects.find("InchTest#manual_getset=")
222
- refute m.getter?
223
- assert m.setter?, "should be a setter"
224
- refute m.has_doc?
225
- assert_equal 0, m.score
226
- end
151
+ assert m.score
152
+ end
227
153
 
228
- it "should recognize a getter in a getter/setter pair defined via" \
229
- " attr_accessor" do
230
- m = @objects.find("InchTest#attr_getset")
231
- assert m.getter?, "should be a getter"
232
- refute m.setter?
233
- refute m.has_doc?
234
- assert_equal 0, m.score
235
- end
154
+ def test_method_with_other_rdoc_doc
155
+ m = @objects.find("Foo::Bar#method_with_other_rdoc_doc")
156
+ assert m.has_doc?
157
+ assert m.has_parameters?
158
+ p = m.parameter(:param1)
159
+ assert p.mentioned? # mentioned in docs, correctly
160
+ p = m.parameter(:param2)
161
+ assert p.mentioned? # mentioned in docs, correctly
162
+ p = m.parameter(:param3)
163
+ assert p.mentioned? # mentioned in docs, correctly
164
+ refute m.return_mentioned?
236
165
 
237
- it "should recognize a setter in a getter/setter pair defined via" \
238
- " attr_accessor" do
239
- m = @objects.find("InchTest#attr_getset=")
240
- refute m.getter?
241
- assert m.setter?, "should be a setter"
242
- refute m.has_doc?
243
- assert_equal 0, m.score
244
- end
166
+ assert m.score
167
+ end
245
168
 
246
- it "should recognize a getter in a getter/setter pair defined via Struct" do
247
- m = @objects.find("InchTest::StructGetSet#struct_getset")
248
- assert m.getter?, "should be a getter"
249
- refute m.setter?
250
- refute m.has_doc?
251
- assert_equal 0, m.score
252
- end
169
+ def test_method_with_unstructured_doc
170
+ m = @objects.find("Foo::Bar#method_with_unstructured_doc")
171
+ assert m.has_doc?
172
+ assert m.has_parameters?
173
+ p = m.parameter(:param1)
174
+ assert p.mentioned? # mentioned in docs, correctly
175
+ refute m.return_mentioned?
253
176
 
254
- it "should recognize a setter in a getter/setter pair defined via Struct" do
255
- m = @objects.find("InchTest::StructGetSet#struct_getset=")
256
- refute m.getter?
257
- assert m.setter?, "should be a setter"
258
- refute m.has_doc?
259
- assert_equal 0, m.score
260
- end
177
+ assert m.score
178
+ end
261
179
 
262
- it "should recognize docs on a getter in a getter/setter pair defined via" \
263
- " attr_accessor" do
264
- m = @objects.find("Attributes#username")
265
- refute_equal 0, m.score
266
- refute m.undocumented?
267
- end
180
+ def test_method_with_unstructured_doc_missing_params
181
+ m = @objects.find("Foo::Bar#method_with_unstructured_doc_missing_params")
182
+ assert m.has_doc?
183
+ assert m.has_parameters?
184
+ p = m.parameter(:format)
185
+ refute p.mentioned? # mentioned in docs, correctly
186
+ refute m.return_mentioned?
268
187
 
269
- it "should recognize docs on a setter in a getter/setter pair defined via" \
270
- " attr_accessor" do
271
- m = @objects.find("Attributes#username=")
272
- refute_equal 0, m.score
273
- refute m.undocumented?
274
- end
188
+ assert m.score
189
+ end
275
190
 
276
- it "should recognize splat parameter notation" do
277
- # it should assign the same score whether the parameter is
278
- # described with or without the splat (*) operator
279
- m1 = @objects.find("Foo#method_with_splat_parameter")
280
- m2 = @objects.find("Foo#method_with_splat_parameter2")
281
- assert_equal 1, m1.parameters.size
282
- assert_equal 1, m2.parameters.size
283
- assert_equal m1.score, m2.score
284
- end
191
+ def test_question_mark_method
192
+ m = @objects.find("InchTest#question_mark_method?")
193
+ refute m.has_doc?
194
+ refute m.has_parameters?
285
195
 
286
- it "should recognize alias methods and aliased methods" do
287
- m1 = @objects.find("InchTest#_aliased_method")
288
- m2 = @objects.find("InchTest#_alias_method")
289
- assert_equal m1.score, m2.score
290
- end
196
+ assert_equal 0, m.score
291
197
  end
292
198
 
293
- describe "YARDs @!attribute directive on a class" do
294
- #
295
- it "should work as a reader" do
296
- m = @objects.find("Attributes#email")
297
- refute_equal 0, m.score
298
- refute m.undocumented?
299
- end
199
+ def test_question_mark_method_with_description
200
+ m = @objects.find("InchTest#question_mark_method_with_description?")
201
+ refute m.has_doc?
202
+ refute m.has_parameters?
300
203
 
301
- it "should work as a writer" do
302
- m = @objects.find("Attributes#email=")
303
- refute_equal 0, m.score
304
- # refute m.undocumented?
305
- # NOTE: this is undocumented since there is no original_docstring
306
- end
204
+ assert m.score > 0
205
+ assert m.score >= 50 # TODO: don't use magic numbers
307
206
  end
308
207
 
309
- describe "YARDs @overload tag on methods" do
310
- #
311
- it "should work with basic overloading" do
312
- list = []
313
- list << @objects.find("Overloading#rgb")
314
- list << @objects.find("Overloading#rgba")
315
- list << @objects.find("Overloading#change_color")
316
- list << @objects.find("Overloading#mix")
317
- list << @objects.find("Overloading#hooks")
318
- list << @objects.find("Overloading#identifiers")
319
- list << @objects.find("Overloading#params_only_in_overloads")
320
- list.each do |m|
321
- assert_equal 100, m.score, "#{m.fullname} did not get 100"
322
- end
323
- end
208
+ def test_method_with_description_and_parameters
209
+ m = @objects.find("InchTest#method_with_description_and_parameters?")
210
+ refute m.has_doc?
211
+ assert m.has_parameters?
324
212
 
325
- it "should work with a malformed @param tag in an overload tag" do
326
- m = @objects.find("Overloading#missing_param_names")
327
- refute m.has_doc? # it may be mentioned in the docs, but it's malformed.
328
- end
213
+ assert m.score > 0
214
+ end
329
215
 
330
- it "should work with several overload tags on the same method" do
331
- skip
332
- m = @objects.find("Overloading#many_overloads")
333
- assert_equal 1, count_roles(
334
- m, Inch::Evaluation::Role::Method::WithoutReturnDescription)
335
- assert_equal 1, count_roles(
336
- m, Inch::Evaluation::Role::Method::WithoutReturnType)
337
- assert_equal 1, count_roles(
338
- m, Inch::Evaluation::Role::MethodParameter::WithoutMention, "block")
339
- end
216
+ def test_depth
217
+ m = @objects.find("#root_method")
218
+ assert_equal 1, m.depth
219
+ m = @objects.find("InchTest#getter")
220
+ assert_equal 2, m.depth
221
+ m = @objects.find("Foo::Bar#method_without_doc")
222
+ assert_equal 3, m.depth
223
+ end
340
224
 
341
- it "should work if @param tags are only present in the @overload tags," \
342
- " but not on the actual method" do
343
- m = @objects.find("Overloading#params_only_in_overloads")
344
- unexpected_roles = [
345
- Inch::Evaluation::Role::Object::WithoutCodeExample,
346
- Inch::Evaluation::Role::MethodParameter::WithoutMention,
347
- Inch::Evaluation::Role::MethodParameter::WithoutType
348
- ]
349
- assert_roles m, [], unexpected_roles
350
- end
225
+ def test_getter
226
+ m = @objects.find("InchTest#getter")
227
+ assert m.getter?, "should be a getter"
228
+ refute m.setter?
229
+ refute m.has_doc?
230
+ assert_equal 0, m.score
231
+ end
351
232
 
352
- it "should work with one param missing in the overload tag" do
353
- m = @objects.find("Overloading#one_param_missing_in_overload")
354
- unexpected_roles = [
355
- Inch::Evaluation::Role::Object::WithoutCodeExample
356
- ]
357
- expected_roles = [
358
- Inch::Evaluation::Role::MethodParameter::WithoutMention,
359
- Inch::Evaluation::Role::MethodParameter::WithoutType
360
- ]
361
- assert_roles m, expected_roles, unexpected_roles
362
- end
233
+ def test_setter
234
+ m = @objects.find("InchTest#attr_setter=")
235
+ refute m.getter?
236
+ assert m.setter?, "should be a setter"
237
+ refute m.has_doc?
238
+ assert_equal 0, m.score
363
239
  end
364
240
 
365
- describe "MISC" do
366
- #
367
- it "should recognize named parameters in Ruby 2.1" do
368
- skip # unless RUBY_VERSION =~ /^2/
241
+ def test_setter2
242
+ m = @objects.find("InchTest#manual_setter=")
243
+ refute m.getter?
244
+ assert m.setter?, "should be a setter"
245
+ refute m.has_doc?
246
+ assert_equal 0, m.score
247
+ end
369
248
 
370
- m = @objects.find("Foo#method_with_named_parameter")
371
- unexpected_roles = [
372
- Inch::Evaluation::Role::MethodParameter::WithoutMention,
373
- Inch::Evaluation::Role::MethodParameter::WithoutType
374
- ]
375
- assert_roles m, [], unexpected_roles
376
- end
249
+ def test_manual_getset
250
+ m = @objects.find("InchTest#manual_getset")
251
+ assert m.getter?, "should be a getter"
252
+ refute m.setter?
253
+ refute m.has_doc?
254
+ assert_equal 0, m.score
255
+ end
377
256
 
378
- it "should recognize indented parameter documentation" do
379
- skip # YARD cannot parse this
257
+ def test_manual_getset2
258
+ m = @objects.find("InchTest#manual_getset=")
259
+ refute m.getter?
260
+ assert m.setter?, "should be a setter"
261
+ refute m.has_doc?
262
+ assert_equal 0, m.score
263
+ end
380
264
 
381
- m = @objects.find("Foo#method_with_indented_param_tag")
382
- unexpected_roles = [
383
- Inch::Evaluation::Role::MethodParameter::WithoutMention,
384
- Inch::Evaluation::Role::MethodParameter::WithoutType
385
- ]
386
- assert_roles m, [], unexpected_roles
387
- end
265
+ def test_attr_getset
266
+ m = @objects.find("InchTest#attr_getset")
267
+ assert m.getter?, "should be a getter"
268
+ refute m.setter?
269
+ refute m.has_doc?
270
+ assert_equal 0, m.score
271
+ end
388
272
 
389
- it "should recognize wrong parameter documentation" do
390
- m = @objects.find("Foo::Bar#method_with_wrong_doc")
391
- assert m.has_doc?
392
- assert m.has_parameters?
393
- assert m.return_mentioned?
394
-
395
- assert_equal 4, m.parameters.size
396
- p = m.parameter(:param1)
397
- assert p.mentioned? # mentioned in docs, correctly
398
- refute p.wrongly_mentioned?
399
- p = m.parameter(:param2)
400
- refute p.mentioned?
401
- refute p.wrongly_mentioned? # not mentioned in docs at all
402
- p = m.parameter(:param3)
403
- refute p.mentioned?
404
- refute p.wrongly_mentioned? # not mentioned in docs at all
405
-
406
- p = m.parameter(:param4)
407
- assert p.mentioned?
408
- assert p.wrongly_mentioned? # mentioned in docs, but not present
409
-
410
- assert m.score
411
- end
273
+ def test_attr_getset2
274
+ m = @objects.find("InchTest#attr_getset=")
275
+ refute m.getter?
276
+ assert m.setter?, "should be a setter"
277
+ refute m.has_doc?
278
+ assert_equal 0, m.score
279
+ end
412
280
 
413
- it "should recognize fully-documented methods with parameters" do
414
- m = @objects.find("Foo::Bar#method_with_full_doc")
415
- assert m.has_doc?
416
- assert m.has_parameters?
417
- assert m.return_mentioned?
418
-
419
- assert_equal 2, m.parameters.size
420
- m.parameters.each do |param|
421
- assert param.mentioned?
422
- assert param.typed?
423
- assert param.described?
424
- refute param.wrongly_mentioned?
425
- end
426
-
427
- assert_equal 100, m.score
428
- end
281
+ def test_struct_getset
282
+ m = @objects.find("InchTest::StructGetSet#struct_getset")
283
+ assert m.getter?, "should be a getter"
284
+ refute m.setter?
285
+ refute m.has_doc?
286
+ assert_equal 0, m.score
287
+ end
429
288
 
430
- it "should recognize question mark methods" do
431
- m = @objects.find("InchTest#question_mark_method?")
432
- refute m.has_doc?
433
- refute m.has_parameters?
289
+ def test_struct_getset2
290
+ m = @objects.find("InchTest::StructGetSet#struct_getset=")
291
+ refute m.getter?
292
+ assert m.setter?, "should be a setter"
293
+ refute m.has_doc?
294
+ assert_equal 0, m.score
295
+ end
434
296
 
435
- # assert it is zero, because YARD auto-assigns tags to these
436
- assert_equal 0, m.score
437
- end
297
+ def test_splat_parameter_notation
298
+ # it should assign the same score whether the parameter is
299
+ # described with or without the splat (*) operator
300
+ m1 = @objects.find("Foo#method_with_splat_parameter")
301
+ m2 = @objects.find("Foo#method_with_splat_parameter2")
302
+ assert_equal 1, m1.parameters.size
303
+ assert_equal 1, m2.parameters.size
304
+ assert_equal m1.score, m2.score
305
+ end
438
306
 
439
- it "should recognize question mark methods with description" do
440
- m = @objects.find("InchTest#question_mark_method_with_description?")
441
- refute m.has_doc?
442
- refute m.has_parameters?
307
+ def test_alias_method
308
+ m1 = @objects.find("InchTest#_aliased_method")
309
+ m2 = @objects.find("InchTest#_alias_method")
310
+ assert_equal m1.score, m2.score
311
+ end
443
312
 
444
- assert m.score > 0
445
- assert m.score >= 50 # TODO: don't use magic numbers
313
+ def test_overloading1
314
+ list = []
315
+ list << @objects.find("Overloading#rgb")
316
+ list << @objects.find("Overloading#rgba")
317
+ list << @objects.find("Overloading#change_color")
318
+ list << @objects.find("Overloading#mix")
319
+ list << @objects.find("Overloading#hooks")
320
+ list << @objects.find("Overloading#identifiers")
321
+ list << @objects.find("Overloading#params_only_in_overloads")
322
+ list.each do |m|
323
+ assert_equal 100, m.score, "#{m.fullname} did not get 100"
446
324
  end
325
+ end
447
326
 
448
- it "should recognize question mark methods with description and" \
449
- " parameters" do
450
- m = @objects.find("InchTest#method_with_description_and_parameters?")
451
- refute m.has_doc?
452
- assert m.has_parameters?
453
-
454
- assert m.score > 0
455
- end
327
+ def test_overloading_with_bad_doc
328
+ m = @objects.find("Overloading#missing_param_names")
329
+ refute m.has_doc? # it may be mentioned in the docs, but it's malformed.
330
+ end
456
331
 
457
- it "should recognize the depth of methods" do
458
- m = @objects.find("#root_method")
459
- assert_equal 1, m.depth
460
- m = @objects.find("InchTest#getter")
461
- assert_equal 2, m.depth
462
- m = @objects.find("Foo::Bar#method_without_doc")
463
- assert_equal 3, m.depth
464
- end
332
+ def test_overloading_with_bad_doc
333
+ m = @objects.find("Overloading#params_only_in_overloads")
334
+ unexpected_roles = [
335
+ Inch::Evaluation::Role::Object::WithoutCodeExample,
336
+ Inch::Evaluation::Role::MethodParameter::WithoutMention,
337
+ Inch::Evaluation::Role::MethodParameter::WithoutType,
338
+ ]
339
+ assert_roles m, [], unexpected_roles
340
+ end
465
341
 
466
- it "should recognize docs on class variables" do
467
- m = @objects.find("Foo::@@class_variable")
468
- assert m.has_doc?
469
- refute m.undocumented?
470
- assert_equal 100, m.score
471
- end
342
+ def test_overloading_with_half_bad_doc
343
+ m = @objects.find("Overloading#one_param_missing_in_overload")
344
+ unexpected_roles = [
345
+ Inch::Evaluation::Role::Object::WithoutCodeExample,
346
+ ]
347
+ expected_roles = [
348
+ Inch::Evaluation::Role::MethodParameter::WithoutMention,
349
+ Inch::Evaluation::Role::MethodParameter::WithoutType,
350
+ ]
351
+ assert_roles m, expected_roles, unexpected_roles
472
352
  end
473
353
  end