inch 0.4.6 → 0.4.7

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