yardstick 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +10 -0
- data/LICENSE +20 -0
- data/README.markdown +117 -0
- data/Rakefile +24 -0
- data/VERSION +1 -0
- data/bin/yardstick +7 -0
- data/deps.rip +1 -0
- data/lib/yardstick/autoload.rb +16 -0
- data/lib/yardstick/cli.rb +76 -0
- data/lib/yardstick/core_ext/object.rb +13 -0
- data/lib/yardstick/measurable.rb +78 -0
- data/lib/yardstick/measurement.rb +217 -0
- data/lib/yardstick/measurement_set.rb +130 -0
- data/lib/yardstick/method.rb +111 -0
- data/lib/yardstick/ordered_set.rb +115 -0
- data/lib/yardstick/processor.rb +65 -0
- data/lib/yardstick/rake/measurement.rb +101 -0
- data/lib/yardstick/rake/verify.rb +179 -0
- data/lib/yardstick/rule.rb +61 -0
- data/lib/yardstick/rule_set.rb +18 -0
- data/lib/yardstick/yard_ext.rb +20 -0
- data/lib/yardstick.rb +52 -0
- data/spec/public/yardstick/cli_spec.rb +108 -0
- data/spec/public/yardstick/measurement_set_spec.rb +265 -0
- data/spec/public/yardstick/measurement_spec.rb +256 -0
- data/spec/public/yardstick/method_spec.rb +356 -0
- data/spec/public/yardstick/rake/measurement_spec.rb +173 -0
- data/spec/public/yardstick/rake/verify_spec.rb +229 -0
- data/spec/public/yardstick_spec.rb +70 -0
- data/spec/rcov.opts +6 -0
- data/spec/semipublic/yardstick/rule_spec.rb +28 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +45 -0
- data/tasks/ci.rake +1 -0
- data/tasks/heckle.rake +52 -0
- data/tasks/metrics.rake +5 -0
- data/tasks/rdoc.rake +15 -0
- data/tasks/spec.rake +22 -0
- data/tasks/yardstick.rake +9 -0
- data/yardstick.gemspec +90 -0
- metadata +113 -0
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).dirname.expand_path.join('..', '..', '..', 'spec_helper')
|
3
|
+
|
4
|
+
shared_examples_for 'set default name for measurement task' do
|
5
|
+
it 'should set name to :yardstick_measure' do
|
6
|
+
@task.instance_variable_get(:@name).should == :yardstick_measure
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
shared_examples_for 'set default path for measurement task' do
|
11
|
+
path = 'lib/**/*.rb'
|
12
|
+
|
13
|
+
it "should set path to #{path.inspect}" do
|
14
|
+
@task.instance_variable_get(:@path).should == path
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
shared_examples_for 'set default output for measurement task' do
|
19
|
+
it 'should set output to "measurements/report.txt"' do
|
20
|
+
@task.instance_variable_get(:@output).should == @output
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
shared_examples_for 'report writer' do
|
25
|
+
it 'should write the report' do
|
26
|
+
@task.path = 'lib/yardstick.rb' # speed up execution
|
27
|
+
execute_action
|
28
|
+
@output.read.should == "\nCoverage: 100.0% Success: 20 Failed: 0 Total: 20\n"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Yardstick::Rake::Measurement do
|
33
|
+
before do
|
34
|
+
@output = Pathname('measurements/report.txt')
|
35
|
+
@output.dirname.rmtree if @output.dirname.exist?
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.new' do
|
39
|
+
describe 'with no arguments' do
|
40
|
+
before do
|
41
|
+
@task = Yardstick::Rake::Measurement.new
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should initialize a Measurement instance' do
|
45
|
+
@task.should be_kind_of(Yardstick::Rake::Measurement)
|
46
|
+
end
|
47
|
+
|
48
|
+
it_should_behave_like 'set default name for measurement task'
|
49
|
+
it_should_behave_like 'set default path for measurement task'
|
50
|
+
it_should_behave_like 'set default output for measurement task'
|
51
|
+
|
52
|
+
it 'should create a task named yardstick_measure' do
|
53
|
+
Rake::Task['yardstick_measure'].should be_kind_of(Rake::Task)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should include the path in the task name' do
|
57
|
+
Rake::Task['yardstick_measure'].comment.should == 'Measure docs in lib/**/*.rb with yardstick'
|
58
|
+
end
|
59
|
+
|
60
|
+
def execute_action
|
61
|
+
Rake::Task['yardstick_measure'].execute
|
62
|
+
end
|
63
|
+
|
64
|
+
it_should_behave_like 'report writer'
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'with name provided' do
|
68
|
+
before do
|
69
|
+
@task = Yardstick::Rake::Measurement.new(:custom_task_name)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should initialize a Measurement instance' do
|
73
|
+
@task.should be_kind_of(Yardstick::Rake::Measurement)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should set name to :custom_task_name' do
|
77
|
+
@task.instance_variable_get(:@name).should == :custom_task_name
|
78
|
+
end
|
79
|
+
|
80
|
+
it_should_behave_like 'set default path for measurement task'
|
81
|
+
it_should_behave_like 'set default output for measurement task'
|
82
|
+
|
83
|
+
it 'should create a task named custom_task_name' do
|
84
|
+
Rake::Task['custom_task_name'].should be_kind_of(Rake::Task)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should include the path in the task name' do
|
88
|
+
Rake::Task['custom_task_name'].comment.should == 'Measure docs in lib/**/*.rb with yardstick'
|
89
|
+
end
|
90
|
+
|
91
|
+
def execute_action
|
92
|
+
Rake::Task['custom_task_name'].execute
|
93
|
+
end
|
94
|
+
|
95
|
+
it_should_behave_like 'report writer'
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'with block provided' do
|
99
|
+
before do
|
100
|
+
@task = Yardstick::Rake::Measurement.new do |*args|
|
101
|
+
@yield = args
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should initialize a Measurement instance' do
|
106
|
+
@task.should be_kind_of(Yardstick::Rake::Measurement)
|
107
|
+
end
|
108
|
+
|
109
|
+
it_should_behave_like 'set default name for measurement task'
|
110
|
+
it_should_behave_like 'set default path for measurement task'
|
111
|
+
it_should_behave_like 'set default output for measurement task'
|
112
|
+
|
113
|
+
it 'should yield to self' do
|
114
|
+
@yield.should == [ @task ]
|
115
|
+
@yield.first.should equal(@task)
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should create a task named yardstick_measure' do
|
119
|
+
Rake::Task['yardstick_measure'].should be_kind_of(Rake::Task)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should include the path in the task name' do
|
123
|
+
Rake::Task['yardstick_measure'].comment.should == 'Measure docs in lib/**/*.rb with yardstick'
|
124
|
+
end
|
125
|
+
|
126
|
+
def execute_action
|
127
|
+
Rake::Task['yardstick_measure'].execute
|
128
|
+
end
|
129
|
+
|
130
|
+
it_should_behave_like 'report writer'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#path=' do
|
135
|
+
before do
|
136
|
+
@path = 'lib/yardstick.rb'
|
137
|
+
|
138
|
+
@task = Yardstick::Rake::Measurement.new do |measurement|
|
139
|
+
measurement.path = @path
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should set path' do
|
144
|
+
@task.instance_variable_get(:@path).should equal(@path)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe '#output=' do
|
149
|
+
before do
|
150
|
+
@task = Yardstick::Rake::Measurement.new do |measurement|
|
151
|
+
measurement.output = @output
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should set output' do
|
156
|
+
@task.instance_variable_get(:@output).should eql(@output)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe '#yardstick_measure' do
|
161
|
+
before do
|
162
|
+
@task = Yardstick::Rake::Measurement.new do |task|
|
163
|
+
task.output = @output
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def execute_action
|
168
|
+
@task.yardstick_measure
|
169
|
+
end
|
170
|
+
|
171
|
+
it_should_behave_like 'report writer'
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,229 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).dirname.expand_path.join('..', '..', '..', 'spec_helper')
|
3
|
+
|
4
|
+
shared_examples_for 'set default name for verify task' do
|
5
|
+
it 'should set name to :verify_measurements' do
|
6
|
+
@task.instance_variable_get(:@name).should == :verify_measurements
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
shared_examples_for 'set default require_exact_threshold for verify task' do
|
11
|
+
it 'should set require_exact_threshold to true' do
|
12
|
+
@task.instance_variable_get(:@require_exact_threshold).should be_true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
shared_examples_for 'set default path for verify task' do
|
17
|
+
path = 'lib/**/*.rb'
|
18
|
+
|
19
|
+
it "should set path to #{path.inspect}" do
|
20
|
+
@task.instance_variable_get(:@path).should == path
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
shared_examples_for 'set default verbose for verify task' do
|
25
|
+
it 'should set verbose to true' do
|
26
|
+
@task.instance_variable_get(:@verbose).should be_true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe Yardstick::Rake::Verify do
|
31
|
+
describe '.new' do
|
32
|
+
describe 'with no arguments' do
|
33
|
+
before do
|
34
|
+
@task = Yardstick::Rake::Verify.new do |verify|
|
35
|
+
verify.threshold = 100
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should initialize a Verify instance' do
|
40
|
+
@task.should be_kind_of(Yardstick::Rake::Verify)
|
41
|
+
end
|
42
|
+
|
43
|
+
it_should_behave_like 'set default name for verify task'
|
44
|
+
it_should_behave_like 'set default require_exact_threshold for verify task'
|
45
|
+
it_should_behave_like 'set default path for verify task'
|
46
|
+
it_should_behave_like 'set default verbose for verify task'
|
47
|
+
|
48
|
+
it 'should create a task named verify_measurements' do
|
49
|
+
Rake::Task['verify_measurements'].should be_kind_of(Rake::Task)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should include the threshold in the task name' do
|
53
|
+
Rake::Task['verify_measurements'].comment.should == 'Verify that yardstick coverage is at least 100%'
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should display coverage summary when executed' do
|
57
|
+
@task.path = 'lib/yardstick.rb' # speed up execution
|
58
|
+
|
59
|
+
capture_stdout { Rake::Task['verify_measurements'].execute }
|
60
|
+
|
61
|
+
@output.should == "Coverage: 100.0% (threshold: 100%)\n"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'with name provided' do
|
66
|
+
before do
|
67
|
+
@task = Yardstick::Rake::Verify.new(:custom_task_name) do |verify|
|
68
|
+
verify.threshold = 100
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should initialize a Verify instance' do
|
73
|
+
@task.should be_kind_of(Yardstick::Rake::Verify)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should set name to :custom_task_name' do
|
77
|
+
@task.instance_variable_get(:@name).should == :custom_task_name
|
78
|
+
end
|
79
|
+
|
80
|
+
it_should_behave_like 'set default require_exact_threshold for verify task'
|
81
|
+
it_should_behave_like 'set default path for verify task'
|
82
|
+
it_should_behave_like 'set default verbose for verify task'
|
83
|
+
|
84
|
+
it 'should create a task named custom_task_name' do
|
85
|
+
Rake::Task['custom_task_name'].should be_kind_of(Rake::Task)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should include the threshold in the task name' do
|
89
|
+
Rake::Task['custom_task_name'].comment.should == 'Verify that yardstick coverage is at least 100%'
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should display coverage summary when executed' do
|
93
|
+
@task.path = 'lib/yardstick.rb' # speed up execution
|
94
|
+
|
95
|
+
capture_stdout { Rake::Task['custom_task_name'].execute }
|
96
|
+
|
97
|
+
@output.should == "Coverage: 100.0% (threshold: 100%)\n"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'with threshold not provided' do
|
102
|
+
it 'should raise an exception' do
|
103
|
+
lambda {
|
104
|
+
Yardstick::Rake::Verify.new {}
|
105
|
+
}.should raise_error(RuntimeError, 'threshold must be set')
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe 'with no block provided' do
|
110
|
+
it 'should raise an exception' do
|
111
|
+
lambda {
|
112
|
+
Yardstick::Rake::Verify.new
|
113
|
+
}.should raise_error(LocalJumpError)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '#threshold=' do
|
119
|
+
before do
|
120
|
+
@task = Yardstick::Rake::Verify.new do |verify|
|
121
|
+
verify.threshold = 100
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should set threshold' do
|
126
|
+
@task.instance_variable_get(:@threshold).should == 100
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe '#require_exact_threshold=' do
|
131
|
+
before do
|
132
|
+
@task = Yardstick::Rake::Verify.new do |verify|
|
133
|
+
verify.threshold = 100
|
134
|
+
verify.require_exact_threshold = false
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should set require_exact_threshold' do
|
139
|
+
@task.instance_variable_get(:@require_exact_threshold).should == false
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '#path=' do
|
144
|
+
before do
|
145
|
+
@path = 'lib/yardstick.rb'
|
146
|
+
|
147
|
+
@task = Yardstick::Rake::Verify.new do |verify|
|
148
|
+
verify.threshold = 100
|
149
|
+
verify.path = @path
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'should set path' do
|
154
|
+
@task.instance_variable_get(:@path).should equal(@path)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#verbose=' do
|
159
|
+
before do
|
160
|
+
@task = Yardstick::Rake::Verify.new do |verify|
|
161
|
+
verify.threshold = 100
|
162
|
+
verify.verbose = false
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should set verbose' do
|
167
|
+
@task.instance_variable_get(:@verbose).should be_false
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe '#verify_measurements' do
|
172
|
+
describe 'with threshold met' do
|
173
|
+
before do
|
174
|
+
@task = Yardstick::Rake::Verify.new do |verify|
|
175
|
+
verify.threshold = 100
|
176
|
+
verify.path = 'lib/yardstick.rb'
|
177
|
+
end
|
178
|
+
|
179
|
+
capture_stdout do
|
180
|
+
@task.verify_measurements
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should output coverage summary' do
|
185
|
+
@output.should == "Coverage: 100.0% (threshold: 100%)\n"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe 'with threshold not met' do
|
190
|
+
before do
|
191
|
+
@task = Yardstick::Rake::Verify.new do |verify|
|
192
|
+
verify.threshold = 0.1
|
193
|
+
verify.path = 'spec/spec_helper.rb'
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should raise an exception' do
|
198
|
+
lambda {
|
199
|
+
capture_stdout do
|
200
|
+
@task.verify_measurements
|
201
|
+
end
|
202
|
+
}.should raise_error(RuntimeError, 'Coverage must be at least 0.1% but was 0.0%')
|
203
|
+
|
204
|
+
# check the stdout output
|
205
|
+
@output.should == "Coverage: 0.0% (threshold: 0.1%)\n"
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe 'with threshold met, but not equal to coverage' do
|
210
|
+
before do
|
211
|
+
@task = Yardstick::Rake::Verify.new do |verify|
|
212
|
+
verify.threshold = 99.9
|
213
|
+
verify.path = 'lib/yardstick.rb'
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'should raise an exception' do
|
218
|
+
lambda {
|
219
|
+
capture_stdout do
|
220
|
+
@task.verify_measurements
|
221
|
+
end
|
222
|
+
}.should raise_error(RuntimeError, 'Coverage has increased above the threshold of 99.9% to 100.0%. You should update your threshold value.')
|
223
|
+
|
224
|
+
# check the stdout output
|
225
|
+
@output.should == "Coverage: 100.0% (threshold: 99.9%)\n"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).dirname.expand_path.join('..', 'spec_helper')
|
3
|
+
|
4
|
+
describe Yardstick do
|
5
|
+
describe '.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 String path' do
|
15
|
+
before :all do
|
16
|
+
@measurements = Yardstick.measure(Yardstick::ROOT.join('lib', 'yardstick.rb').to_s)
|
17
|
+
end
|
18
|
+
|
19
|
+
it_should_behave_like 'measured itself'
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'with a Pathname' do
|
23
|
+
before :all do
|
24
|
+
@measurements = Yardstick.measure(Yardstick::ROOT.join('lib', 'yardstick.rb'))
|
25
|
+
end
|
26
|
+
|
27
|
+
it_should_behave_like 'measured itself'
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'with an Array of String objects' do
|
31
|
+
before :all do
|
32
|
+
@measurements = Yardstick.measure([ Yardstick::ROOT.join('lib', 'yardstick.rb').to_s ])
|
33
|
+
end
|
34
|
+
|
35
|
+
it_should_behave_like 'measured itself'
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'with an Array of Pathname objects' do
|
39
|
+
before :all do
|
40
|
+
@measurements = Yardstick.measure([ Yardstick::ROOT.join('lib', 'yardstick.rb') ])
|
41
|
+
end
|
42
|
+
|
43
|
+
it_should_behave_like 'measured itself'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.measure_string' do
|
48
|
+
describe 'with a String' do
|
49
|
+
before do
|
50
|
+
@measurements = Yardstick.measure_string('def test; end')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should return a MeasurementSet' do
|
54
|
+
@measurements.should be_kind_of(Yardstick::MeasurementSet)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should be non-empty' do
|
58
|
+
@measurements.should_not be_empty
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'with no arguments' do
|
63
|
+
it 'should raise an exception' do
|
64
|
+
lambda {
|
65
|
+
Yardstick.measure_string
|
66
|
+
}.should raise_error(ArgumentError)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/rcov.opts
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).dirname.expand_path.join('..', '..', 'spec_helper')
|
3
|
+
|
4
|
+
describe Yardstick::Rule do
|
5
|
+
describe '#eql?' do
|
6
|
+
describe 'when rules are equal' do
|
7
|
+
before do
|
8
|
+
@rule = Yardstick::Rule.new('test rule') { true }
|
9
|
+
@other = Yardstick::Rule.new('test rule') { true }
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should return true' do
|
13
|
+
@rule.eql?(@other).should be_true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'when rules are not equal' do
|
18
|
+
before do
|
19
|
+
@rule = Yardstick::Rule.new('test rule') { true }
|
20
|
+
@other = Yardstick::Rule.new('other rule') { true }
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should return false' do
|
24
|
+
@rule.eql?(@other).should be_false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'spec/autorun'
|
4
|
+
|
5
|
+
require Pathname(__FILE__).dirname.expand_path.join('..', 'lib', 'yardstick')
|
6
|
+
|
7
|
+
Pathname.glob(Yardstick::ROOT.join('lib', '**', '*.rb').to_s).sort.each do |file|
|
8
|
+
require file.to_s.chomp('.rb')
|
9
|
+
end
|
10
|
+
|
11
|
+
Spec::Runner.configure do |config|
|
12
|
+
clear_tasks = lambda { Rake::Task.clear }
|
13
|
+
|
14
|
+
config.before(:all, &clear_tasks)
|
15
|
+
config.before( &clear_tasks)
|
16
|
+
|
17
|
+
clear_yard_registry = lambda { YARD::Registry.clear }
|
18
|
+
|
19
|
+
config.before(:all, &clear_yard_registry)
|
20
|
+
config.before( &clear_yard_registry)
|
21
|
+
|
22
|
+
|
23
|
+
def capture_stdout
|
24
|
+
$stdout = StringIO.new
|
25
|
+
yield
|
26
|
+
ensure
|
27
|
+
$stdout.rewind
|
28
|
+
@output = $stdout.read
|
29
|
+
$stdout = STDOUT
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
shared_examples_for 'measured itself' do
|
34
|
+
it 'should return a MeasurementSet' do
|
35
|
+
@measurements.should be_kind_of(Yardstick::MeasurementSet)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should be non-empty' do
|
39
|
+
@measurements.should_not be_empty
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should all be correct' do
|
43
|
+
@measurements.each { |measurement| measurement.should be_ok }
|
44
|
+
end
|
45
|
+
end
|
data/tasks/ci.rake
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
task :ci => [ :verify_measurements, :heckle, 'metrics:all' ]
|
data/tasks/heckle.rake
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# original code by Ashley Moran:
|
2
|
+
# http://aviewfromafar.net/2007/11/1/rake-task-for-heckling-your-specs
|
3
|
+
desc 'Heckle each module and class'
|
4
|
+
task :heckle => :verify_rcov do
|
5
|
+
root_module = 'Yardstick'
|
6
|
+
spec_files = FileList['spec/**/*_spec.rb']
|
7
|
+
|
8
|
+
current_module = nil
|
9
|
+
current_method = nil
|
10
|
+
|
11
|
+
heckle_caught_modules = Hash.new { |hash, key| hash[key] = [] }
|
12
|
+
unhandled_mutations = 0
|
13
|
+
|
14
|
+
IO.popen("spec --heckle #{root_module} #{spec_files} 2>/dev/null") do |pipe|
|
15
|
+
while line = pipe.gets
|
16
|
+
case line = line.chomp
|
17
|
+
when /\A\*\*\*\s+(#{root_module}(?:::)?(?:\w+(?:::)?)*)#(\S+)/
|
18
|
+
current_module, current_method = $1, $2
|
19
|
+
when "The following mutations didn't cause test failures:"
|
20
|
+
heckle_caught_modules[current_module] << current_method
|
21
|
+
when '+++ mutation'
|
22
|
+
unhandled_mutations += 1
|
23
|
+
end
|
24
|
+
|
25
|
+
puts line
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if unhandled_mutations > 0
|
30
|
+
error_message_lines = [ "*************\n" ]
|
31
|
+
|
32
|
+
error_message_lines << "Heckle found #{unhandled_mutations} " \
|
33
|
+
"mutation#{"s" unless unhandled_mutations == 1} " \
|
34
|
+
"that didn't cause spec violations\n"
|
35
|
+
|
36
|
+
heckle_caught_modules.each do |mod, methods|
|
37
|
+
error_message_lines << "#{mod} contains the following " \
|
38
|
+
'poorly-specified methods:'
|
39
|
+
methods.each do |method|
|
40
|
+
error_message_lines << " - #{method}"
|
41
|
+
end
|
42
|
+
error_message_lines << ''
|
43
|
+
end
|
44
|
+
|
45
|
+
error_message_lines << 'Get your act together and come back ' \
|
46
|
+
'when your specs are doing their job!'
|
47
|
+
|
48
|
+
raise error_message_lines.join("\n")
|
49
|
+
else
|
50
|
+
puts 'Well done! Your code withstood a heckling.'
|
51
|
+
end
|
52
|
+
end
|
data/tasks/metrics.rake
ADDED
data/tasks/rdoc.rake
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rake/rdoctask'
|
2
|
+
|
3
|
+
Rake::RDocTask.new do |rdoc|
|
4
|
+
version = if File.exist?('VERSION.yml')
|
5
|
+
config = YAML.load(File.read('VERSION.yml'))
|
6
|
+
"#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
7
|
+
else
|
8
|
+
''
|
9
|
+
end
|
10
|
+
|
11
|
+
rdoc.rdoc_dir = 'rdoc'
|
12
|
+
rdoc.title = "yardstick #{version}"
|
13
|
+
rdoc.rdoc_files.include('README*')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
data/tasks/spec.rake
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec/rake/spectask'
|
2
|
+
require 'spec/rake/verify_rcov'
|
3
|
+
|
4
|
+
spec_defaults = lambda do |spec|
|
5
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
6
|
+
spec.libs << 'lib' << 'spec'
|
7
|
+
spec.spec_opts << '--options' << 'spec/spec.opts'
|
8
|
+
end
|
9
|
+
|
10
|
+
Spec::Rake::SpecTask.new(:spec, &spec_defaults)
|
11
|
+
|
12
|
+
Spec::Rake::SpecTask.new(:rcov) do |rcov|
|
13
|
+
spec_defaults.call(rcov)
|
14
|
+
rcov.rcov = true
|
15
|
+
rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/)
|
16
|
+
end
|
17
|
+
|
18
|
+
RCov::VerifyTask.new(:verify_rcov => :rcov) do |rcov|
|
19
|
+
rcov.threshold = 100
|
20
|
+
end
|
21
|
+
|
22
|
+
task :default => :spec
|