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,22 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'yardstick/rake/measurement'
5
+
6
+ describe Yardstick::Rake::Measurement do
7
+ let(:output) { Pathname('measurements/report.txt') }
8
+
9
+ before do
10
+ output.dirname.rmtree if output.dirname.exist?
11
+
12
+ Yardstick::Rake::Measurement.new do |config|
13
+ config.path = 'lib/yardstick.rb'
14
+ end
15
+ end
16
+
17
+ it 'should write the report' do
18
+ Rake::Task['yardstick_measure'].execute
19
+ expect(output.read)
20
+ .to eql("\nYARD-Coverage: 100.0% Success: 30 Failed: 0 Total: 30\n")
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'yardstick/rake/verify'
5
+
6
+ describe Yardstick::Rake::Verify do
7
+ before do
8
+ Yardstick::Rake::Verify.new do |verify|
9
+ verify.threshold = 100
10
+ verify.path = 'lib/yardstick.rb'
11
+ end
12
+ end
13
+
14
+ it 'should display coverage summary when executed' do
15
+ capture_stdout { Rake::Task['verify_measurements'].execute }
16
+
17
+ expect(@output).to eql("YARD-Coverage: 100.0% (threshold: 100%)\n")
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ shared_examples_for 'measured itself' do
4
+ it 'should return a MeasurementSet' do
5
+ expect(@measurements).to be_kind_of(Yardstick::MeasurementSet)
6
+ end
7
+
8
+ it 'should be non-empty' do
9
+ expect(@measurements).to_not be_empty
10
+ end
11
+
12
+ it 'should all be correct' do
13
+ @measurements.each { |measurement| expect(measurement).to be_ok }
14
+ end
15
+ end
data/spec/spec_helper.rb CHANGED
@@ -10,32 +10,33 @@ if ENV['COVERAGE'] == 'true'
10
10
  ]
11
11
 
12
12
  SimpleCov.start do
13
- command_name 'spec:unit'
14
- add_filter 'config'
15
- add_filter 'spec'
13
+ command_name 'spec:unit'
14
+
15
+ add_filter 'config'
16
+ add_filter 'spec'
17
+ add_filter 'vendor'
18
+
16
19
  minimum_coverage 100
17
20
  end
18
21
  end
19
22
 
20
23
  require 'yardstick'
21
- require 'spec'
22
- require 'spec/autorun' if RUBY_VERSION < '1.9'
24
+ require 'devtools/spec_helper'
23
25
 
24
- # require spec support files and shared behavior
25
- Dir[File.expand_path('../{support,shared}/**/*.rb', __FILE__)].each do |file|
26
- require file
27
- end
26
+ RSpec.configure do |config|
27
+ config.expect_with :rspec do |expect_with|
28
+ expect_with.syntax = :expect
29
+ end
28
30
 
29
- Spec::Runner.configure do |config|
30
31
  clear_tasks = proc { Rake::Task.clear }
31
32
 
32
33
  config.before(:all, &clear_tasks)
33
- config.before( &clear_tasks)
34
+ config.before(&clear_tasks)
34
35
 
35
36
  clear_yard_registry = proc { YARD::Registry.clear }
36
37
 
37
38
  config.before(:all, &clear_yard_registry)
38
- config.before( &clear_yard_registry)
39
+ config.before(&clear_yard_registry)
39
40
 
40
41
  def capture_stdout
41
42
  $stdout = StringIO.new
@@ -46,17 +47,3 @@ Spec::Runner.configure do |config|
46
47
  $stdout = STDOUT
47
48
  end
48
49
  end
49
-
50
- shared_examples_for 'measured itself' do
51
- it 'should return a MeasurementSet' do
52
- @measurements.should be_kind_of(Yardstick::MeasurementSet)
53
- end
54
-
55
- it 'should be non-empty' do
56
- @measurements.should_not be_empty
57
- end
58
-
59
- it 'should all be correct' do
60
- @measurements.each { |measurement| measurement.should be_ok }
61
- end
62
- end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ # Mock Document object
4
+ class DocumentMock
5
+ def path
6
+ 'Foo#bar'
7
+ end
8
+
9
+ def file
10
+ '(stdin)'
11
+ end
12
+
13
+ def line
14
+ 2
15
+ end
16
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ class ValidRule
4
+ class << self
5
+ attr_accessor :description
6
+ end
7
+
8
+ attr_reader :document
9
+
10
+ def initialize(document, *)
11
+ @document = document
12
+ end
13
+
14
+ self.description = 'successful'
15
+
16
+ def enabled?
17
+ true
18
+ end
19
+
20
+ def valid?
21
+ true
22
+ end
23
+
24
+ def validatable?
25
+ true
26
+ end
27
+ end
28
+
29
+ class NotValidatableRule < ValidRule
30
+ self.description = 'skipped'
31
+
32
+ def validatable?
33
+ false
34
+ end
35
+ end
36
+
37
+ class InvalidRule < ValidRule
38
+ self.description = 'not successful'
39
+
40
+ def valid?
41
+ false
42
+ end
43
+ end
44
+
45
+ class DisabledRule < ValidRule
46
+ self.description = 'not enabled'
47
+
48
+ def enabled?
49
+ false
50
+ end
51
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick, '.measure' do
6
+ context 'when no arguments' do
7
+ subject { described_class.measure }
8
+
9
+ it 'delegates to Processor' do
10
+ processor = double('processor')
11
+ Yardstick::Processor.stub(:new).with(instance_of(Yardstick::Config)) do
12
+ processor
13
+ end
14
+ processor.should_receive(:process)
15
+ subject
16
+ end
17
+ end
18
+
19
+ context 'when custom config' do
20
+ subject { described_class.measure(config) }
21
+
22
+ let(:config) { double('config') }
23
+
24
+ it 'delegates to Processor' do
25
+ processor = double('processor')
26
+ Yardstick::Processor.stub(:new).with(config) { processor }
27
+ processor.should_receive(:process)
28
+ subject
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick, '.measure' do
6
+ let(:string) { double('string') }
7
+
8
+ context 'when no arguments' do
9
+ subject { described_class.measure_string(string) }
10
+
11
+ it 'delegates to Processor' do
12
+ processor = double('processor')
13
+ Yardstick::Processor.stub(:new).with(instance_of(Yardstick::Config)) do
14
+ processor
15
+ end
16
+ processor.should_receive(:process_string).with(string)
17
+ subject
18
+ end
19
+ end
20
+
21
+ context 'when custom config' do
22
+ subject { described_class.measure_string(string, config) }
23
+
24
+ let(:config) { double('config') }
25
+
26
+ it 'delegates to Processor' do
27
+ processor = double('processor')
28
+ Yardstick::Processor.stub(:new).with(config) { processor }
29
+ processor.should_receive(:process_string).with(string)
30
+ subject
31
+ end
32
+ end
33
+ end
@@ -5,30 +5,33 @@ require 'yardstick/cli'
5
5
 
6
6
  shared_examples_for 'displays help' do
7
7
  it 'should display the help message' do
8
- @output.should == <<-OUTPUT.gsub(/^\s{6}/, '')
8
+ expect(@output).to eql(<<-OUTPUT.gsub(/^\s{6}/, '')
9
9
  Usage: #{OptionParser.new.program_name} [options]
10
10
  -v, --version print version information and exit
11
11
  -h, --help display this help and exit
12
- OUTPUT
12
+ OUTPUT
13
+ )
13
14
  end
14
15
  end
15
16
 
16
17
  shared_examples_for 'displays version' do
17
18
  it 'should display the program and version' do
18
- @output.should == "#{OptionParser.new.program_name} #{Yardstick::VERSION}\n"
19
+ expect(@output)
20
+ .to eql("#{OptionParser.new.program_name} #{Yardstick::VERSION}\n")
19
21
  end
20
22
  end
21
23
 
22
24
  shared_examples_for 'displays coverage summary' do
23
25
  it 'should output the coverage summary' do
24
- @output.should == "\nYARD-Coverage: 100.0% Success: 20 Failed: 0 Total: 20\n"
26
+ expect(@output)
27
+ .to eql("\nYARD-Coverage: 100.0% Success: 30 Failed: 0 Total: 30\n")
25
28
  end
26
29
  end
27
30
 
28
31
  describe Yardstick::CLI do
29
32
  def capture_display(&block)
30
33
  capture_stdout do
31
- block.should raise_error(SystemExit)
34
+ expect(block).to raise_error(SystemExit)
32
35
  end
33
36
  end
34
37
 
@@ -81,7 +84,7 @@ describe Yardstick::CLI do
81
84
 
82
85
  describe 'with an Array of String objects' do
83
86
  before :all do
84
- @measurements = capture_stdout { Yardstick::CLI.run(*[ Yardstick::ROOT.join('lib', 'yardstick.rb').to_s ]) }
87
+ @measurements = capture_stdout { Yardstick::CLI.run(*[Yardstick::ROOT.join('lib', 'yardstick.rb').to_s]) }
85
88
  end
86
89
 
87
90
  it_should_behave_like 'measured itself'
@@ -90,7 +93,7 @@ describe Yardstick::CLI do
90
93
 
91
94
  describe 'with an Array of Pathname objects' do
92
95
  before :all do
93
- @measurements = capture_stdout { Yardstick::CLI.run(*[ Yardstick::ROOT.join('lib', 'yardstick.rb') ]) }
96
+ @measurements = capture_stdout { Yardstick::CLI.run(*[Yardstick::ROOT.join('lib', 'yardstick.rb')]) }
94
97
  end
95
98
 
96
99
  it_should_behave_like 'measured itself'
@@ -103,7 +106,7 @@ describe Yardstick::CLI do
103
106
  end
104
107
 
105
108
  it 'should display the invalid option message' do
106
- @output.should == "invalid option: --invalid\n"
109
+ expect(@output).to eql("invalid option: --invalid\n")
107
110
  end
108
111
  end
109
112
  end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::Config, '.coerce' do
6
+ let(:hash) { { 'rules' => { 'foo' => 'bar' } } }
7
+
8
+ context 'when without block' do
9
+ subject { described_class.coerce(hash) }
10
+
11
+ it { should be_instance_of(described_class) }
12
+
13
+ it 'coerces hash' do
14
+ rules = subject.instance_variable_get(:@rules)
15
+ expect(rules).to eql(foo: 'bar')
16
+ end
17
+ end
18
+
19
+ context 'when block provided' do
20
+ subject do
21
+ described_class.coerce(hash) { |config| config.path = new_path }
22
+ end
23
+
24
+ let(:new_path) { 'custom' }
25
+
26
+ it { should be_instance_of(described_class) }
27
+
28
+ it 'executes block as config' do
29
+ expect(subject.path).to eql(new_path)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ require 'spec_helper'
5
+
6
+ describe Yardstick::Config, '#for_rule' do
7
+ subject { described_class.new(options).for_rule(rule_class) }
8
+
9
+ let(:options) do
10
+ { rules: { 'Summary::Presence'.to_sym => { enabled: false } } }
11
+ end
12
+
13
+ let(:rule_config) { double('RuleConfig') }
14
+
15
+ context 'when rule is present' do
16
+ let(:rule_class) { Yardstick::Rules::Summary::Presence }
17
+
18
+ before do
19
+ allow(Yardstick::RuleConfig).to receive(:new).with(enabled: false)
20
+ .and_return(rule_config)
21
+ end
22
+
23
+ it { should be(rule_config) }
24
+ end
25
+
26
+ context 'when config does not have given rule' do
27
+ let(:rule_class) { Yardstick::Rules::Summary::Length }
28
+
29
+ before do
30
+ allow(Yardstick::RuleConfig).to receive(:new).with({})
31
+ .and_return(rule_config)
32
+ end
33
+
34
+ it { should be(rule_config) }
35
+ end
36
+
37
+ context 'when invalid rule given' do
38
+ let(:rule_class) { Object }
39
+
40
+ it 'raises InvalidRule error' do
41
+ msg = 'every rule must begin with Yardstick::Rules::'
42
+
43
+ expect { subject }
44
+ .to raise_error(described_class::InvalidRule, msg)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::Config, '#initialize' do
6
+ it { should be_instance_of(described_class) }
7
+
8
+ context 'when block provided' do
9
+ subject do
10
+ described_class.new { |config| config.path = new_path }
11
+ end
12
+
13
+ let(:new_path) { 'custom' }
14
+
15
+ it { should be_instance_of(described_class) }
16
+
17
+ it 'executes block as config' do
18
+ expect(subject.path).to eql(new_path)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::Config, '#output' do
6
+ subject { described_class.new(options).output }
7
+
8
+ context 'when default options' do
9
+ let(:options) { {} }
10
+
11
+ it { should be_instance_of(Yardstick::ReportOutput) }
12
+
13
+ its(:to_s) { should == 'measurements/report.txt' }
14
+ end
15
+ end