yardstick 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +4 -0
  4. data/.ruby-gemset +1 -0
  5. data/.travis.yml +11 -16
  6. data/CONTRIBUTING.md +11 -0
  7. data/Gemfile +3 -59
  8. data/Gemfile.devtools +54 -0
  9. data/Guardfile +32 -0
  10. data/LICENSE +1 -1
  11. data/README.md +71 -55
  12. data/Rakefile +2 -7
  13. data/TODO +12 -0
  14. data/bin/yardstick +1 -0
  15. data/config/devtools.yml +2 -0
  16. data/config/flay.yml +2 -2
  17. data/config/flog.yml +1 -1
  18. data/config/mutant.yml +3 -0
  19. data/config/{site.reek → reek.yml} +31 -25
  20. data/config/rubocop.yml +49 -0
  21. data/config/yardstick.yml +31 -0
  22. data/lib/yardstick.rb +35 -15
  23. data/lib/yardstick/cli.rb +7 -7
  24. data/lib/yardstick/config.rb +176 -0
  25. data/lib/yardstick/document.rb +215 -0
  26. data/lib/yardstick/document_set.rb +21 -0
  27. data/lib/yardstick/measurement.rb +18 -145
  28. data/lib/yardstick/measurement_set.rb +2 -2
  29. data/lib/yardstick/parser.rb +61 -0
  30. data/lib/yardstick/processor.rb +21 -35
  31. data/lib/yardstick/rake/measurement.rb +7 -49
  32. data/lib/yardstick/rake/verify.rb +28 -55
  33. data/lib/yardstick/report_output.rb +57 -0
  34. data/lib/yardstick/rule.rb +64 -37
  35. data/lib/yardstick/rule_config.rb +56 -0
  36. data/lib/yardstick/rules/api_tag.rb +95 -0
  37. data/lib/yardstick/rules/example_tag.rb +33 -0
  38. data/lib/yardstick/rules/return_tag.rb +21 -0
  39. data/lib/yardstick/rules/summary.rb +87 -0
  40. data/lib/yardstick/version.rb +1 -1
  41. data/lib/yardstick/yard_ext.rb +1 -6
  42. data/spec/integration/yardstick/class_methods/measure_spec.rb +22 -0
  43. data/spec/integration/yardstick/class_methods/measure_string_spec.rb +20 -0
  44. data/spec/integration/yardstick/document/file_spec.rb +16 -0
  45. data/spec/integration/yardstick/document/line_spec.rb +25 -0
  46. data/spec/integration/yardstick/document/path_spec.rb +45 -0
  47. data/spec/integration/yardstick/processor/process_string_spec.rb +401 -0
  48. data/spec/integration/yardstick/rake/measurement_spec.rb +22 -0
  49. data/spec/integration/yardstick/rake/verify_spec.rb +19 -0
  50. data/spec/shared/measured_itself_behavior.rb +15 -0
  51. data/spec/spec_helper.rb +13 -26
  52. data/spec/support/document_mock.rb +16 -0
  53. data/spec/support/rules.rb +51 -0
  54. data/spec/unit/yardstick/class_methods/measure_spec.rb +31 -0
  55. data/spec/unit/yardstick/class_methods/measure_string_spec.rb +33 -0
  56. data/spec/unit/yardstick/cli_spec.rb +11 -8
  57. data/spec/unit/yardstick/config/class_methods/coerce_spec.rb +32 -0
  58. data/spec/unit/yardstick/config/for_rule_spec.rb +47 -0
  59. data/spec/unit/yardstick/config/initialize_spec.rb +21 -0
  60. data/spec/unit/yardstick/config/output_spec.rb +15 -0
  61. data/spec/unit/yardstick/config/output_writer_spec.rb +20 -0
  62. data/spec/unit/yardstick/config/path_spec.rb +13 -0
  63. data/spec/unit/yardstick/config/path_writer_spec.rb +11 -0
  64. data/spec/unit/yardstick/config/require_exact_threshold_predicate_spec.rb +19 -0
  65. data/spec/unit/yardstick/config/require_exact_threshold_writer_spec.rb +19 -0
  66. data/spec/unit/yardstick/config/set_defaults_spec.rb +42 -0
  67. data/spec/unit/yardstick/config/threshold_writer_spec.rb +15 -0
  68. data/spec/unit/yardstick/config/verbose_predicate_spec.rb +19 -0
  69. data/spec/unit/yardstick/config/verbose_writer_spec.rb +19 -0
  70. data/spec/unit/yardstick/document/api_predicate_spec.rb +25 -0
  71. data/spec/unit/yardstick/document/class_methods/measure_spec.rb +25 -0
  72. data/spec/unit/yardstick/document/class_methods/register_rule_spec.rb +19 -0
  73. data/spec/unit/yardstick/document/class_methods/registered_rules_spec.rb +9 -0
  74. data/spec/unit/yardstick/document/docstring_spec.rb +11 -0
  75. data/spec/unit/yardstick/document/file_spec.rb +14 -0
  76. data/spec/unit/yardstick/document/has_tag_predicate_spec.rb +15 -0
  77. data/spec/unit/yardstick/document/line_spec.rb +12 -0
  78. data/spec/unit/yardstick/document/null_tag/text_spec.rb +9 -0
  79. data/spec/unit/yardstick/document/null_tag/types_spec.rb +9 -0
  80. data/spec/unit/yardstick/document/path_spec.rb +12 -0
  81. data/spec/unit/yardstick/document/summary_text_spec.rb +23 -0
  82. data/spec/unit/yardstick/document/tag_text_spec.rb +17 -0
  83. data/spec/unit/yardstick/document/tag_types_spec.rb +18 -0
  84. data/spec/unit/yardstick/document/visibility_spec.rb +22 -0
  85. data/spec/unit/yardstick/document_set/measure_spec.rb +28 -0
  86. data/spec/unit/yardstick/measurement/description_spec.rb +12 -0
  87. data/spec/unit/yardstick/measurement/initialize_spec.rb +12 -0
  88. data/spec/unit/yardstick/measurement/ok_predicate_spec.rb +21 -0
  89. data/spec/unit/yardstick/measurement/puts_spec.rb +62 -0
  90. data/spec/unit/yardstick/measurement/skip_predicate_spec.rb +27 -0
  91. data/spec/unit/yardstick/measurement_set/coverage_spec.rb +23 -0
  92. data/spec/unit/yardstick/measurement_set/failed_spec.rb +28 -0
  93. data/spec/unit/yardstick/measurement_set/initialize_spec.rb +27 -0
  94. data/spec/unit/yardstick/measurement_set/puts_spec.rb +63 -0
  95. data/spec/unit/yardstick/measurement_set/successful_spec.rb +13 -0
  96. data/spec/unit/yardstick/measurement_set/total_spec.rb +12 -0
  97. data/spec/unit/yardstick/ordered_set/each_spec.rb +18 -0
  98. data/spec/unit/yardstick/ordered_set/empty_predicate_spec.rb +19 -0
  99. data/spec/unit/yardstick/ordered_set/include_predicate_spec.rb +21 -0
  100. data/spec/unit/yardstick/ordered_set/index_spec.rb +21 -0
  101. data/spec/unit/yardstick/ordered_set/left_shift_operator_spec.rb +16 -0
  102. data/spec/unit/yardstick/ordered_set/length_spec.rb +11 -0
  103. data/spec/unit/yardstick/ordered_set/merge_spec.rb +16 -0
  104. data/spec/unit/yardstick/parser/class_methods/parse_paths_spec.rb +28 -0
  105. data/spec/unit/yardstick/parser/class_methods/parse_string_spec.rb +28 -0
  106. data/spec/unit/yardstick/processor/process_spec.rb +17 -0
  107. data/spec/unit/yardstick/processor/process_string_spec.rb +17 -0
  108. data/spec/unit/yardstick/rake/measurement/initialize_spec.rb +64 -0
  109. data/spec/unit/yardstick/rake/measurement/yardstick_measure_spec.rb +22 -0
  110. data/spec/unit/yardstick/rake/verify/initialize_spec.rb +72 -0
  111. data/spec/unit/yardstick/rake/verify/verify_measurements_spec.rb +85 -0
  112. data/spec/unit/yardstick/report_output/class_methods/coerce_spec.rb +18 -0
  113. data/spec/unit/yardstick/report_output/initialize_spec.rb +11 -0
  114. data/spec/unit/yardstick/report_output/to_s_spec.rb +12 -0
  115. data/spec/unit/yardstick/report_output/write_spec.rb +31 -0
  116. data/spec/unit/yardstick/round_percentage_spec.rb +9 -0
  117. data/spec/unit/yardstick/rule/class_methods/coerce_spec.rb +21 -0
  118. data/spec/unit/yardstick/rule/class_methods/inherited_spec.rb +15 -0
  119. data/spec/unit/yardstick/rule/enabled_predicate_spec.rb +18 -0
  120. data/spec/unit/yardstick/rule/initialize_spec.rb +25 -0
  121. data/spec/unit/yardstick/rule/validatable_predicate_spec.rb +11 -0
  122. data/spec/unit/yardstick/rule_config/enabled_for_path_predicate_spec.rb +41 -0
  123. data/spec/unit/yardstick/rule_config/initialize_spec.rb +16 -0
  124. data/spec/unit/yardstick/rules/api_tag/inclusion/valid_predicate_spec.rb +27 -0
  125. data/spec/unit/yardstick/rules/api_tag/presence/valid_predicate_spec.rb +25 -0
  126. data/spec/unit/yardstick/rules/api_tag/private_method/valid_predicate_spec.rb +21 -0
  127. data/spec/unit/yardstick/rules/api_tag/private_method/validatable_predicate_spec.rb +21 -0
  128. data/spec/unit/yardstick/rules/api_tag/protected_method/valid_predicate_spec.rb +25 -0
  129. data/spec/unit/yardstick/rules/api_tag/protected_method/validatable_predicate_spec.rb +21 -0
  130. data/spec/unit/yardstick/rules/example_tag/valid_predicate_spec.rb +25 -0
  131. data/spec/unit/yardstick/rules/example_tag/validatable_predicate_spec.rb +32 -0
  132. data/spec/unit/yardstick/rules/return_tag/valid_predicate_spec.rb +21 -0
  133. data/spec/unit/yardstick/rules/summary/delimiter/valid_predicate_spec.rb +21 -0
  134. data/spec/unit/yardstick/rules/summary/length/valid_predicate_spec.rb +27 -0
  135. data/spec/unit/yardstick/rules/summary/presence/valid_predicate_spec.rb +21 -0
  136. data/spec/unit/yardstick/rules/summary/presence/validatable_predicate_spec.rb +21 -0
  137. data/spec/unit/yardstick/rules/summary/single_line/valid_predicate_spec.rb +21 -0
  138. data/yardstick.gemspec +7 -11
  139. metadata +222 -65
  140. data/.rvmrc +0 -1
  141. data/lib/yardstick/measurable.rb +0 -67
  142. data/lib/yardstick/method.rb +0 -113
  143. data/lib/yardstick/rule_set.rb +0 -22
  144. data/spec/support/config_alias.rb +0 -5
  145. data/spec/unit/yardstick/measurement_set_spec.rb +0 -266
  146. data/spec/unit/yardstick/measurement_spec.rb +0 -257
  147. data/spec/unit/yardstick/method_spec.rb +0 -357
  148. data/spec/unit/yardstick/rake/measurement_spec.rb +0 -175
  149. data/spec/unit/yardstick/rake/verify_spec.rb +0 -231
  150. data/spec/unit/yardstick/rule_spec.rb +0 -36
  151. data/spec/unit/yardstick_spec.rb +0 -71
  152. data/tasks/metrics/ci.rake +0 -9
  153. data/tasks/metrics/flay.rake +0 -53
  154. data/tasks/metrics/flog.rake +0 -44
  155. data/tasks/metrics/heckle.rake +0 -52
  156. data/tasks/metrics/metric_fu.rake +0 -31
  157. data/tasks/metrics/reek.rake +0 -21
  158. data/tasks/metrics/roodi.rake +0 -19
  159. data/tasks/metrics/yardstick.rake +0 -27
  160. data/tasks/spec.rake +0 -64
  161. data/tasks/yard.rake +0 -11
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ module Yardstick
4
+ module Rules
5
+ # Checks if method has @example tag
6
+ #
7
+ # This applies only for public methods
8
+ #
9
+ class ExampleTag < Rule
10
+ self.description = 'The public/semipublic method should have an example specified'
11
+
12
+ # @see class description
13
+ #
14
+ # @return [Boolean]
15
+ # true if method is not private and it returns something meaningful
16
+ #
17
+ # @api private
18
+ def validatable?
19
+ !api?(%w[ private ]) && tag_types('return') != %w[ undefined ]
20
+ end
21
+
22
+ # @see class description
23
+ #
24
+ # @return [Boolean]
25
+ # true if has example tag
26
+ #
27
+ # @api private
28
+ def valid?
29
+ has_tag?('example')
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ module Yardstick
4
+ module Rules
5
+ # Checks if method has a @return tag
6
+ #
7
+ class ReturnTag < Rule
8
+ self.description = 'The @return tag should be specified'
9
+
10
+ # @see class description
11
+ #
12
+ # @return [Boolean]
13
+ # true if has return tag
14
+ #
15
+ # @api private
16
+ def valid?
17
+ has_tag?('return')
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,87 @@
1
+ # encoding: utf-8
2
+
3
+ module Yardstick
4
+ module Rules
5
+ # Rules related to method summary
6
+ #
7
+ class Summary
8
+ # Checks if method summary is present
9
+ #
10
+ class Presence < Rule
11
+ self.description = 'The method summary should be specified'
12
+
13
+ # @see Rule::validatable?
14
+ #
15
+ # @return [Boolean]
16
+ # true if method does not have @see tag
17
+ #
18
+ # @api private
19
+ def validatable?
20
+ !has_tag?('see')
21
+ end
22
+
23
+ # @see class description
24
+ #
25
+ # @return [Boolean]
26
+ # true if summary text is not empty
27
+ #
28
+ # @api private
29
+ def valid?
30
+ !summary_text.empty?
31
+ end
32
+ end
33
+
34
+ # Checks that method summary length doesn't go over 80 characters
35
+ #
36
+ class Length < Rule
37
+ MAXIMUM_LINE_LENGTH = 80
38
+
39
+ self.description = 'The method summary should be less than 80 characters in length'
40
+
41
+ # @see class description
42
+ #
43
+ # @return [Boolean]
44
+ # true if summary length is below 80 characters
45
+ #
46
+ # @api private
47
+ def valid?
48
+ summary_text.split(//u).count <= MAXIMUM_LINE_LENGTH
49
+ end
50
+ end
51
+
52
+ # Checks that method summary doesn't end with a period
53
+ #
54
+ class Delimiter < Rule
55
+ self.description = 'The method summary should not end in a period'
56
+
57
+ # @see class description
58
+ #
59
+ # @return [Boolean]
60
+ # true if summary text does not end with a period
61
+ #
62
+ # @api private
63
+ def valid?
64
+ summary_text[-1, 1] != '.'
65
+ end
66
+ end
67
+
68
+ # Checks that method summary length is exactly one line
69
+ #
70
+ class SingleLine < Rule
71
+ LINE_BREAK_CHARACTER = "\n"
72
+
73
+ self.description = 'The method summary should be a single line'
74
+
75
+ # @see class description
76
+ #
77
+ # @return [Boolean]
78
+ # true if summary text does not include a new line
79
+ #
80
+ # @api private
81
+ def valid?
82
+ !summary_text.include?(LINE_BREAK_CHARACTER)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -3,6 +3,6 @@
3
3
  module Yardstick
4
4
 
5
5
  # Gem version
6
- VERSION = '0.9.6'.freeze
6
+ VERSION = '0.9.7'.freeze
7
7
 
8
8
  end # module Yardstick
@@ -4,13 +4,8 @@ module YARD #:nodoc: all
4
4
 
5
5
  # Test if JRuby head is being used
6
6
  JRUBY_19MODE = RUBY_VERSION >= '1.9' && RUBY_ENGINE == 'jruby'
7
- JRUBY_HEAD = JRUBY_19MODE && JRUBY_VERSION >= '1.7.4.dev'
8
7
 
9
8
  # Fix jruby-head to use the ruby 1.8 parser until their ripper port is working
10
- Parser::SourceParser.parser_type = :ruby18 if JRUBY_HEAD
9
+ Parser::SourceParser.parser_type = :ruby18 if JRUBY_19MODE
11
10
 
12
- # Extend docstring with yardstick methods
13
- class Docstring
14
- include Yardstick::Method
15
- end # class Docstring
16
11
  end # module YARD
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick, '.measure' do
6
+ describe 'with no arguments' do
7
+ before :all do
8
+ @measurements = Yardstick.measure
9
+ end
10
+
11
+ it_should_behave_like 'measured itself'
12
+ end
13
+
14
+ describe 'with a config' do
15
+ before :all do
16
+ config = Yardstick::Config.new(path: Yardstick::ROOT.join('lib', 'yardstick.rb'))
17
+ @measurements = Yardstick.measure(config)
18
+ end
19
+
20
+ it_should_behave_like 'measured itself'
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick, '.measure_string' do
6
+ context 'with a string' do
7
+ subject { described_class.measure_string('def test; end') }
8
+
9
+ it { should be_a(Yardstick::MeasurementSet) }
10
+
11
+ it { should_not be_empty }
12
+ end
13
+
14
+ describe 'with no arguments' do
15
+ it 'should raise an exception' do
16
+ expect { Yardstick.measure_string }
17
+ .to raise_error(ArgumentError)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::Document, '#file' do
6
+ subject { described_class.new(docstring).file }
7
+
8
+ let(:docstring) { YARD::Registry.all(:method).first.docstring }
9
+ let(:file) { Yardstick::ROOT.join('lib', 'yardstick.rb') }
10
+
11
+ before { YARD.parse([file.to_s], [], YARD::Logger::ERROR) }
12
+
13
+ it { should be_kind_of(Pathname) }
14
+
15
+ it { should == file }
16
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::Document, '#line' do
6
+ subject { described_class.new(docstring).line }
7
+
8
+ let(:docstring) { YARD::Registry.all(:method).first.docstring }
9
+
10
+ before do
11
+ YARD.parse_string(<<-RUBY)
12
+ module Foo
13
+ class Bar
14
+ # Instance method
15
+ #
16
+ # @api public
17
+ def baz(value)
18
+ end
19
+ end
20
+ end
21
+ RUBY
22
+ end
23
+
24
+ it { should be(6) }
25
+ end
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::Document, '#path' do
6
+ subject { described_class.new(docstring).path }
7
+
8
+ let(:docstring) { YARD::Registry.all(:method).first.docstring }
9
+
10
+ context 'when instance method' do
11
+ before do
12
+ YARD.parse_string(<<-RUBY)
13
+ module Foo
14
+ class Bar
15
+ # Instance method
16
+ #
17
+ # @api public
18
+ def baz(value)
19
+ end
20
+ end
21
+ end
22
+ RUBY
23
+ end
24
+
25
+ it { should == 'Foo::Bar#baz' }
26
+ end
27
+
28
+ context 'when class method' do
29
+ before do
30
+ YARD.parse_string(<<-RUBY)
31
+ module Foo
32
+ class Bar
33
+ # Instance method
34
+ #
35
+ # @api public
36
+ def self.baz(value)
37
+ end
38
+ end
39
+ end
40
+ RUBY
41
+ end
42
+
43
+ it { should == 'Foo::Bar.baz' }
44
+ end
45
+ end
@@ -0,0 +1,401 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::Document, '#process_string' do
6
+ subject(:measurements) { processor.process_string(method) }
7
+
8
+ let(:processor) { Yardstick::Processor.new(config) }
9
+ let(:config) { Yardstick::Config.new }
10
+
11
+ let(:valid_method) do
12
+ (<<-RUBY)
13
+ # This is a method summary that is the maximum --- exactly 80 characters in length
14
+ #
15
+ # @example
16
+ # test('Hello World') # => nil
17
+ #
18
+ # @param [#to_str] value
19
+ # the value
20
+ #
21
+ # @return [nil]
22
+ # returns nil
23
+ #
24
+ # @api public
25
+ def test(value)
26
+ end
27
+ RUBY
28
+ end
29
+
30
+ def measurement(description)
31
+ measurements.detect do |measurement|
32
+ measurement.description == description
33
+ end
34
+ end
35
+
36
+ describe 'with a method summary' do
37
+ let(:method) { valid_method }
38
+
39
+ it { should be_kind_of(Yardstick::MeasurementSet) }
40
+
41
+ it 'should have a correct measurement' do
42
+ expect(measurement('The method summary should be specified')).to be_ok
43
+ end
44
+ end
45
+
46
+ describe 'without a method summary' do
47
+ let(:method) { 'def test(value); end' }
48
+
49
+ it { should be_kind_of(Yardstick::MeasurementSet) }
50
+
51
+ it 'should have an incorrect measurement' do
52
+ expect(measurement('The method summary should be specified')).to_not be_ok
53
+ end
54
+ end
55
+
56
+ describe 'without a method summary when validations are turned off' do
57
+ let(:config) do
58
+ Yardstick::Config.new(rules: {
59
+ 'Summary::Presence'.to_sym => { enabled: false }
60
+ })
61
+ end
62
+ let(:method) { 'def test(value); end' }
63
+
64
+ it { should be_kind_of(Yardstick::MeasurementSet) }
65
+
66
+ it 'should have a correct measurement' do
67
+ expect(measurement('The method summary should be specified')).to be_ok
68
+ end
69
+ end
70
+
71
+ describe 'without a method summary when validations are turned off for given class' do
72
+ let(:config) do
73
+ Yardstick::Config.new(rules: {
74
+ 'Summary::Presence'.to_sym => { enabled: true, exclude: %w[World] }
75
+ })
76
+ end
77
+ let(:method) { 'class World; def test(value); end; end' }
78
+
79
+ it { should be_kind_of(Yardstick::MeasurementSet) }
80
+
81
+ it 'should have a correct measurement' do
82
+ expect(measurements.detect { |measurement| measurement.description == 'The method summary should be specified' }).to be_ok
83
+ end
84
+ end
85
+
86
+ describe 'with a method summary that is 80 characters in length' do
87
+ let(:method) { valid_method }
88
+
89
+ it { should be_kind_of(Yardstick::MeasurementSet) }
90
+
91
+ it 'should have a correct measurement' do
92
+ expect(measurement('The method summary should be less than 80 characters in length'))
93
+ .to be_ok
94
+ end
95
+ end
96
+
97
+ describe 'with a method summary that is 81 characters in length' do
98
+ let(:method) do
99
+ (<<-RUBY)
100
+ # This is a method summary greater than the maximum - it is 81 characters in length
101
+ def test(value)
102
+ end
103
+ RUBY
104
+ end
105
+
106
+ it { should be_kind_of(Yardstick::MeasurementSet) }
107
+
108
+ it 'should have an incorrect measurement' do
109
+ expect(measurement('The method summary should be less than 80 characters in length'))
110
+ .to_not be_ok
111
+ end
112
+ end
113
+
114
+ describe 'with a method summary that does not end in a period' do
115
+ let(:method) { valid_method }
116
+
117
+ it { should be_kind_of(Yardstick::MeasurementSet) }
118
+
119
+ it 'should have a correct measurement' do
120
+ expect(measurement('The method summary should not end in a period'))
121
+ .to be_ok
122
+ end
123
+ end
124
+
125
+ describe 'with a method summary that does end in a period' do
126
+ let(:method) do
127
+ <<-RUBY
128
+ # This method summary ends in a period.
129
+ def test(value)
130
+ end
131
+ RUBY
132
+ end
133
+
134
+ it { should be_kind_of(Yardstick::MeasurementSet) }
135
+
136
+ it 'should have an incorrect measurement' do
137
+ expect(measurement('The method summary should not end in a period'))
138
+ .to_not be_ok
139
+ end
140
+ end
141
+
142
+ describe 'with a method summary that is on one line' do
143
+ let(:method) { valid_method }
144
+
145
+ it { should be_kind_of(Yardstick::MeasurementSet) }
146
+
147
+ it 'should have a correct measurement' do
148
+ expect(measurement('The method summary should be a single line'))
149
+ .to be_ok
150
+ end
151
+ end
152
+
153
+ describe 'with a method summary that is not on one line' do
154
+ let(:method) do
155
+ <<-RUBY
156
+ # This method summary
157
+ # is on two lines
158
+ def test(value)
159
+ end
160
+ RUBY
161
+ end
162
+
163
+ it { should be_kind_of(Yardstick::MeasurementSet) }
164
+
165
+ it 'should have an incorrect measurement' do
166
+ expect(measurement('The method summary should be a single line'))
167
+ .to_not be_ok
168
+ end
169
+ end
170
+
171
+ describe 'with a method that has an @example tag' do
172
+ let(:method) { valid_method }
173
+
174
+ it { should be_kind_of(Yardstick::MeasurementSet) }
175
+
176
+ it 'should have a correct measurement' do
177
+ expect(measurement('The public/semipublic method should have an example specified'))
178
+ .to be_ok
179
+ end
180
+ end
181
+
182
+ describe 'with a method that is private' do
183
+ let(:method) do
184
+ <<-RUBY
185
+ # @api private
186
+ def test(value)
187
+ end
188
+ RUBY
189
+ end
190
+
191
+ it { should be_kind_of(Yardstick::MeasurementSet) }
192
+
193
+ it 'should be skipped' do
194
+ expect(measurement('The public/semipublic method should have an example specified'))
195
+ .to be_skip
196
+ end
197
+ end
198
+
199
+ describe 'with a method that does not have an @example tag, and has an undefined @return tag' do
200
+ let(:method) do
201
+ <<-RUBY
202
+ # @return [undefined]
203
+ #
204
+ # @api public
205
+ def test(value)
206
+ end
207
+ RUBY
208
+ end
209
+
210
+ it { should be_kind_of(Yardstick::MeasurementSet) }
211
+
212
+ it 'should be skipped' do
213
+ expect(measurement('The public/semipublic method should have an example specified'))
214
+ .to be_skip
215
+ end
216
+ end
217
+
218
+ describe 'with a method that has an @api tag' do
219
+ let(:method) { valid_method }
220
+
221
+ it { should be_kind_of(Yardstick::MeasurementSet) }
222
+
223
+ it 'should have a correct measurement' do
224
+ expect(measurement('The @api tag should be specified'))
225
+ .to be_ok
226
+ end
227
+ end
228
+
229
+ describe 'with a method that does not have an @api tag' do
230
+ let(:method) { 'def test(value); end' }
231
+
232
+ it { should be_kind_of(Yardstick::MeasurementSet) }
233
+
234
+ it 'should have an incorrect measurement' do
235
+ expect(measurement('The @api tag should be specified'))
236
+ .to_not be_ok
237
+ end
238
+ end
239
+
240
+ describe 'with a method that has a public @api tag' do
241
+ let(:method) { valid_method }
242
+
243
+ it { should be_kind_of(Yardstick::MeasurementSet) }
244
+
245
+ it 'should have a correct measurement' do
246
+ expect(measurement('The @api tag must be either public, semipublic or private'))
247
+ .to be_ok
248
+ end
249
+ end
250
+
251
+ describe 'with a method that has an invalid @api tag' do
252
+ let(:method) do
253
+ <<-RUBY
254
+ # @api invalid
255
+ def test(value)
256
+ end
257
+ RUBY
258
+ end
259
+
260
+ it { should be_kind_of(Yardstick::MeasurementSet) }
261
+
262
+ it 'should have an incorrect measurement' do
263
+ expect(measurement('The @api tag must be either public, semipublic or private'))
264
+ .to_not be_ok
265
+ end
266
+ end
267
+
268
+ describe 'with a protected method and a semipublic @api tag' do
269
+ let(:method) do
270
+ <<-RUBY
271
+ protected
272
+
273
+ # @api semipublic
274
+ def test(value)
275
+ end
276
+ RUBY
277
+ end
278
+
279
+ it { should be_kind_of(Yardstick::MeasurementSet) }
280
+
281
+ it 'should have a correct measurement' do
282
+ expect(measurement('A method with protected visibility must have an @api tag of semipublic or private'))
283
+ .to be_ok
284
+ end
285
+ end
286
+
287
+ describe 'with a protected method and a private @api tag' do
288
+ let(:method) do
289
+ <<-RUBY
290
+ protected
291
+
292
+ # @api private
293
+ def test(value)
294
+ end
295
+ RUBY
296
+ end
297
+
298
+ it { should be_kind_of(Yardstick::MeasurementSet) }
299
+
300
+ it 'should have a correct measurement' do
301
+ expect(measurement('A method with protected visibility must have an @api tag of semipublic or private'))
302
+ .to be_ok
303
+ end
304
+ end
305
+
306
+ describe 'with a protected method and a public @api tag' do
307
+ let(:method) do
308
+ <<-RUBY
309
+ protected
310
+
311
+ # @api public
312
+ def test(value)
313
+ end
314
+ RUBY
315
+ end
316
+
317
+ it { should be_kind_of(Yardstick::MeasurementSet) }
318
+
319
+ it 'should have an incorrect measurement' do
320
+ expect(measurement('A method with protected visibility must have an @api tag of semipublic or private'))
321
+ .to_not be_ok
322
+ end
323
+ end
324
+
325
+ describe 'with a private method and a private @api tag' do
326
+ let(:method) do
327
+ <<-RUBY
328
+ private
329
+
330
+ # @api private
331
+ def test(value)
332
+ end
333
+ RUBY
334
+ end
335
+
336
+ it { should be_kind_of(Yardstick::MeasurementSet) }
337
+
338
+ it 'should have a correct measurement' do
339
+ expect(measurement('A method with private visibility must have an @api tag of private'))
340
+ .to be_ok
341
+ end
342
+ end
343
+
344
+ describe 'with a private method and a public @api tag' do
345
+ let(:method) do
346
+ <<-RUBY
347
+ private
348
+
349
+ # @api public
350
+ def test(value)
351
+ end
352
+ RUBY
353
+ end
354
+
355
+ it { should be_kind_of(Yardstick::MeasurementSet) }
356
+
357
+ it 'should have an incorrect measurement' do
358
+ expect(measurement('A method with private visibility must have an @api tag of private'))
359
+ .to_not be_ok
360
+ end
361
+ end
362
+
363
+ describe 'with a private method and a semipublic @api tag' do
364
+ let(:method) do
365
+ <<-RUBY
366
+ private
367
+
368
+ # @api semipublic
369
+ def test(value)
370
+ end
371
+ RUBY
372
+ end
373
+
374
+ it { should be_kind_of(Yardstick::MeasurementSet) }
375
+
376
+ it 'should have an incorrect measurement' do
377
+ expect(measurement('A method with private visibility must have an @api tag of private'))
378
+ .to_not be_ok
379
+ end
380
+ end
381
+
382
+ describe 'with a method that has a @return tag' do
383
+ let(:method) { valid_method }
384
+
385
+ it { should be_kind_of(Yardstick::MeasurementSet) }
386
+
387
+ it 'should have a correct measurement' do
388
+ expect(measurement('The @return tag should be specified')).to be_ok
389
+ end
390
+ end
391
+
392
+ describe 'with a method that does not have a @return tag' do
393
+ let(:method) { 'def test(value); end' }
394
+
395
+ it { should be_kind_of(Yardstick::MeasurementSet) }
396
+
397
+ it 'should have an incorrect measurement' do
398
+ expect(measurement('The @return tag should be specified')).to_not be_ok
399
+ end
400
+ end
401
+ end