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,11 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::OrderedSet, 'length' do
6
+ subject { described_class.new(items).length }
7
+
8
+ let(:items) { [double('item'), double('item')] }
9
+
10
+ it { should be(2) }
11
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::OrderedSet, '#merge' do
6
+ subject { set.merge(other) }
7
+
8
+ let(:set) { described_class.new([item1]) }
9
+ let(:other) { described_class.new([item2]) }
10
+ let(:item1) { double('item') }
11
+ let(:item2) { double('item') }
12
+
13
+ it { should be(set) }
14
+
15
+ it { should include(item1, item2) }
16
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::Parser, '.parse_paths' do
6
+ subject(:document_set) { described_class.parse_paths(paths) }
7
+
8
+ let(:paths) { double('paths') }
9
+ let(:method_object) { double(file: 'foo.rb', line: 4, docstring: docstring) }
10
+ let(:docstring) { double('docstring') }
11
+
12
+ before do
13
+ YARD.should_receive(:parse).with(paths, [], YARD::Logger::ERROR)
14
+ YARD::Registry.stub(:all).with(:method).and_return([method_object])
15
+ end
16
+
17
+ it { should be_a(Yardstick::DocumentSet) }
18
+
19
+ its(:length) { should be(1) }
20
+
21
+ context 'first document' do
22
+ subject { document_set.first }
23
+
24
+ it { should be_a(Yardstick::Document) }
25
+
26
+ its(:docstring) { should eq(docstring) }
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::Parser, '.parse_string' do
6
+ subject(:document_set) { described_class.parse_string(string) }
7
+
8
+ let(:string) { double('string', to_str: 'body') }
9
+ let(:method_object) { double(file: 'foo.rb', line: 4, docstring: docstring) }
10
+ let(:docstring) { double('docstring') }
11
+
12
+ before do
13
+ YARD.should_receive(:parse_string).with('body')
14
+ YARD::Registry.stub(:all).with(:method).and_return([method_object])
15
+ end
16
+
17
+ it { should be_a(Yardstick::DocumentSet) }
18
+
19
+ its(:length) { should be(1) }
20
+
21
+ context 'first document' do
22
+ subject { document_set.first }
23
+
24
+ it { should be_a(Yardstick::Document) }
25
+
26
+ its(:docstring) { should eq(docstring) }
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::Processor, '#process' do
6
+ subject { described_class.new(config).process }
7
+
8
+ let(:config) { double('config', path: path) }
9
+ let(:path) { Pathname('foo/bar.rb') }
10
+ let(:documents) { double('document set') }
11
+
12
+ it 'measures files specified in the config' do
13
+ Yardstick::Parser.should_receive(:parse_paths).with(['foo/bar.rb']) { documents }
14
+ documents.should_receive(:measure).with(config)
15
+ subject
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::Processor, '#process_string' do
6
+ subject { described_class.new(config).process_string(string) }
7
+
8
+ let(:config) { double('config') }
9
+ let(:string) { double('string') }
10
+ let(:documents) { double('document set') }
11
+
12
+ it 'measures specified string' do
13
+ Yardstick::Parser.should_receive(:parse_string).with(string) { documents }
14
+ documents.should_receive(:measure).with(config)
15
+ subject
16
+ end
17
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'yardstick/rake/measurement'
5
+
6
+ describe Yardstick::Rake::Measurement, '#initialize' do
7
+ context 'with custom arguments' do
8
+ subject(:task) { described_class.new(:measure, options) }
9
+
10
+ let(:config) { Yardstick::Config.new }
11
+ let(:options) { double('options') }
12
+
13
+ before do
14
+ Yardstick::Config.stub(:coerce).with(options) { config }
15
+ end
16
+
17
+ context 'when valid options' do
18
+ it { should be_a(described_class) }
19
+
20
+ it 'creates rake task with given name' do
21
+ subject
22
+ expect(Rake::Task['measure']).to be_kind_of(Rake::Task)
23
+ end
24
+
25
+ it 'calls yardstick_measure when rake task is executed' do
26
+ subject
27
+ task.should_receive(:yardstick_measure)
28
+ Rake::Task['measure'].execute
29
+ end
30
+
31
+ it 'should include the threshold in the task name' do
32
+ task
33
+ expect(Rake.application.last_description)
34
+ .to eql('Measure docs in lib/**/*.rb with yardstick')
35
+ end
36
+ end
37
+ end
38
+
39
+ context 'when with default arguments' do
40
+ subject { described_class.new }
41
+
42
+ it { should be_a(described_class) }
43
+
44
+ it 'assigns yardstick_measure as the name' do
45
+ subject
46
+ expect(Rake::Task['yardstick_measure']).to be_kind_of(Rake::Task)
47
+ end
48
+ end
49
+
50
+ context 'when block provided' do
51
+ subject(:task) do
52
+ described_class.new do |config|
53
+ @yield = config
54
+ end
55
+ end
56
+
57
+ it { should be_a(described_class) }
58
+
59
+ it 'should yield to Config' do
60
+ task
61
+ expect(@yield).to be_instance_of(Yardstick::Config)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'yardstick/rake/measurement'
5
+
6
+ describe Yardstick::Rake::Measurement, '#yardstick_measure' do
7
+ subject { described_class.new(:yardstick_measure, options).yardstick_measure }
8
+
9
+ let(:config) { double('config', path: 'tmp', output: report_writer) }
10
+ let(:report_writer) { double('report writer') }
11
+ let(:options) { double('options') }
12
+ let(:measurements) { double('measurements') }
13
+ let(:io) { double('io') }
14
+
15
+ it 'writes yardstick results' do
16
+ Yardstick::Config.stub(:coerce).with(options) { config }
17
+ Yardstick.stub(:measure).with(config) { measurements }
18
+ report_writer.stub(:write).and_yield(io)
19
+ measurements.should_receive(:puts).with(io)
20
+ subject
21
+ end
22
+ end
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'yardstick/rake/verify'
5
+
6
+ describe Yardstick::Rake::Verify, '#initialize' do
7
+ context 'with custom arguments' do
8
+ subject(:task) { described_class.new(:verify, options) }
9
+
10
+ let(:config) { Yardstick::Config.new(threshold: 90) }
11
+ let(:options) { double('options') }
12
+
13
+ before do
14
+ Yardstick::Config.stub(:coerce).with(options) { config }
15
+ end
16
+
17
+ context 'when valid options' do
18
+ it { should be_a(described_class) }
19
+
20
+ it 'creates rake task with given name' do
21
+ subject
22
+ expect(Rake::Task['verify']).to be_kind_of(Rake::Task)
23
+ end
24
+
25
+ it 'calls verify_measurements when rake task is executed' do
26
+ subject
27
+ task.should_receive(:verify_measurements)
28
+ Rake::Task['verify'].execute
29
+ end
30
+
31
+ it 'should include the threshold in the task name' do
32
+ task
33
+ expect(Rake.application.last_description)
34
+ .to eql('Verify that yardstick coverage is at least 90%')
35
+ end
36
+ end
37
+
38
+ context 'when threshold is not specified' do
39
+ before { config.threshold = nil }
40
+
41
+ it 'raises error' do
42
+ expect { task }.to raise_error(RuntimeError, 'threshold must be set')
43
+ end
44
+ end
45
+ end
46
+
47
+ context 'when with default arguments' do
48
+ subject { described_class.new }
49
+
50
+ it { should be_a(described_class) }
51
+
52
+ it 'assigns verify_measurements as the name' do
53
+ subject
54
+ expect(Rake::Task['verify_measurements']).to be_kind_of(Rake::Task)
55
+ end
56
+ end
57
+
58
+ context 'when block provided' do
59
+ subject(:task) do
60
+ described_class.new do |config|
61
+ @yield = config
62
+ end
63
+ end
64
+
65
+ it { should be_a(described_class) }
66
+
67
+ it 'should yield to Config' do
68
+ task
69
+ expect(@yield).to be_instance_of(Yardstick::Config)
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'yardstick/rake/verify'
5
+
6
+ describe Yardstick::Rake::Verify, '#verify_measurements' do
7
+ subject(:measure) do
8
+ capture_stdout { described_class.new(:verify, options).verify_measurements }
9
+ end
10
+
11
+ let(:config) { Yardstick::Config.new(threshold: 90) }
12
+ let(:options) { double('options') }
13
+
14
+ before do
15
+ Yardstick::Config.stub(:coerce).with(options) { config }
16
+ Yardstick.stub(:measure).with(config) { measurements }
17
+ end
18
+
19
+ context 'when verbose' do
20
+ let(:measurements) { double('measurements', coverage: 0.9) }
21
+
22
+ it 'outputs coverage' do
23
+ measure
24
+ expect(@output).to eq("YARD-Coverage: 90.0% (threshold: 90%)\n")
25
+ end
26
+ end
27
+
28
+ context 'when not verbose' do
29
+ let(:measurements) { double('measurements', coverage: 0.9) }
30
+
31
+ before do
32
+ config.verbose = false
33
+ end
34
+
35
+ it 'outputs nothing' do
36
+ measure
37
+ expect(@output).to eq('')
38
+ end
39
+ end
40
+
41
+ context 'when lower coverage' do
42
+ let(:measurements) { double('measurements', coverage: 0.434) }
43
+
44
+ it 'outputs coverage' do
45
+ expect { measure }.to raise_error
46
+ expect(@output).to eq("YARD-Coverage: 43.4% (threshold: 90%)\n")
47
+ end
48
+
49
+ it 'raises error about low coverage' do
50
+ expect { measure }
51
+ .to raise_error(RuntimeError, 'YARD-Coverage must be at least 90% but was 43.4%')
52
+ end
53
+ end
54
+
55
+ context 'when higher coverage' do
56
+ let(:measurements) { double('measurements', coverage: 0.9989) }
57
+
58
+ it 'outputs coverage' do
59
+ expect { measure }.to raise_error
60
+ expect(@output).to eq("YARD-Coverage: 99.8% (threshold: 90%)\n")
61
+ end
62
+
63
+ it 'raises error about high coverage' do
64
+ expect { measure }
65
+ .to raise_error(RuntimeError, 'YARD-Coverage has increased above the threshold of 90% to 99.8%. You should update your threshold value.')
66
+ end
67
+ end
68
+
69
+ context 'when higher coverage without exact threshold requirement' do
70
+ let(:measurements) { double('measurements', coverage: 1) }
71
+
72
+ before do
73
+ config.require_exact_threshold = false
74
+ end
75
+
76
+ it 'outputs coverage' do
77
+ measure
78
+ expect(@output).to eq("YARD-Coverage: 100.0% (threshold: 90%)\n")
79
+ end
80
+
81
+ it 'passes' do
82
+ expect { measure }.to_not raise_error
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::ReportOutput, '.coerce' do
6
+ subject { described_class.coerce(target) }
7
+
8
+ let(:target) { '/foo/bar.rb' }
9
+
10
+ it { should be_a(described_class) }
11
+
12
+ its(:to_s) { should eq(target) }
13
+
14
+ it 'coerces target to Pathname' do
15
+ target = subject.instance_variable_get(:@target)
16
+ expect(target).to be_a(Pathname)
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::ReportOutput, '#initialize' do
6
+ subject { described_class.new(target) }
7
+
8
+ let(:target) { Pathname('/foo/bar') }
9
+
10
+ it { should be_instance_of(described_class) }
11
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::ReportOutput, '#to_s' do
6
+ subject { described_class.new(pathname).to_s }
7
+
8
+ let(:pathname) { Pathname(path) }
9
+ let(:path) { '/foo/bar' }
10
+
11
+ it { should == path }
12
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Yardstick::ReportOutput, 'write' do
6
+ subject do
7
+ described_class.new(target).write do |io|
8
+ io.puts 'content'
9
+ end
10
+ end
11
+
12
+ let(:target) { double('Pathname', dirname: dirname) }
13
+ let(:dirname) { double }
14
+
15
+ before do
16
+ dirname.stub(:mkpath)
17
+ target.stub(:open)
18
+ end
19
+
20
+ it 'should create directory' do
21
+ dirname.should_receive(:mkpath)
22
+ subject
23
+ end
24
+
25
+ it 'should write content' do
26
+ io = double
27
+ io.should_receive(:puts).with('content')
28
+ target.should_receive(:open).with('w').and_yield(io)
29
+ subject
30
+ end
31
+ end