jscruggs-metric_fu 0.9.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. data/HISTORY +10 -0
  2. data/README +1 -154
  3. data/Rakefile +37 -2
  4. data/TODO +2 -1
  5. data/lib/base/base_template.rb +134 -0
  6. data/lib/base/configuration.rb +187 -0
  7. data/lib/base/generator.rb +144 -0
  8. data/lib/{metric_fu → base}/md5_tracker.rb +0 -0
  9. data/lib/base/report.rb +100 -0
  10. data/lib/{metric_fu → generators}/churn.rb +20 -22
  11. data/lib/generators/flay.rb +29 -0
  12. data/lib/generators/flog.rb +130 -0
  13. data/lib/generators/rcov.rb +74 -0
  14. data/lib/generators/reek.rb +31 -0
  15. data/lib/generators/roodi.rb +28 -0
  16. data/lib/generators/saikuro.rb +201 -0
  17. data/lib/generators/stats.rb +43 -0
  18. data/lib/metric_fu.rb +20 -3
  19. data/lib/templates/{churn.html.erb → standard/churn.html.erb} +12 -4
  20. data/lib/templates/{default.css → standard/default.css} +20 -1
  21. data/lib/templates/{flay.html.erb → standard/flay.html.erb} +12 -9
  22. data/lib/templates/standard/flog.html.erb +52 -0
  23. data/lib/templates/standard/index.html.erb +38 -0
  24. data/lib/templates/standard/rcov.html.erb +42 -0
  25. data/lib/templates/standard/reek.html.erb +41 -0
  26. data/lib/templates/{roodi.html.erb → standard/roodi.html.erb} +10 -8
  27. data/lib/templates/standard/saikuro.html.erb +83 -0
  28. data/lib/templates/standard/standard_template.rb +26 -0
  29. data/lib/templates/standard/stats.html.erb +54 -0
  30. data/spec/base/base_template_spec.rb +140 -0
  31. data/spec/base/configuration_spec.rb +303 -0
  32. data/spec/base/generator_spec.rb +159 -0
  33. data/spec/{md5_tracker_spec.rb → base/md5_tracker_spec.rb} +1 -1
  34. data/spec/base/report_spec.rb +139 -0
  35. data/spec/generators/churn_spec.rb +152 -0
  36. data/spec/generators/flay_spec.rb +101 -0
  37. data/spec/generators/flog_spec.rb +189 -0
  38. data/spec/generators/reek_spec.rb +47 -0
  39. data/spec/generators/saikuro_spec.rb +35 -0
  40. data/spec/generators/stats_spec.rb +74 -0
  41. data/spec/spec_helper.rb +24 -7
  42. data/tasks/metric_fu.rake +14 -0
  43. data/{lib/tasks → tasks}/railroad.rake +0 -0
  44. data/{lib/metric_fu → vendor}/saikuro/saikuro.rb +0 -0
  45. metadata +58 -47
  46. data/lib/metric_fu/base.rb +0 -160
  47. data/lib/metric_fu/flay.rb +0 -17
  48. data/lib/metric_fu/flog.rb +0 -129
  49. data/lib/metric_fu/reek.rb +0 -17
  50. data/lib/metric_fu/roodi.rb +0 -17
  51. data/lib/tasks/churn.rake +0 -9
  52. data/lib/tasks/coverage.rake +0 -54
  53. data/lib/tasks/flay.rake +0 -6
  54. data/lib/tasks/flog.rake +0 -69
  55. data/lib/tasks/metric_fu.rake +0 -24
  56. data/lib/tasks/metric_fu.rb +0 -6
  57. data/lib/tasks/reek.rake +0 -6
  58. data/lib/tasks/roodi.rake +0 -7
  59. data/lib/tasks/saikuro.rake +0 -35
  60. data/lib/tasks/stats.rake +0 -14
  61. data/lib/templates/flog.html.erb +0 -38
  62. data/lib/templates/flog_page.html.erb +0 -25
  63. data/lib/templates/reek.html.erb +0 -30
  64. data/spec/base_spec.rb +0 -57
  65. data/spec/churn_spec.rb +0 -117
  66. data/spec/config_spec.rb +0 -110
  67. data/spec/flay_spec.rb +0 -19
  68. data/spec/flog_spec.rb +0 -208
  69. data/spec/reek_spec.rb +0 -26
@@ -0,0 +1,303 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper.rb"
2
+
3
+ describe MetricFu::Configuration do
4
+
5
+ def get_new_config
6
+ @config = Configuration.new
7
+ end
8
+
9
+ def base_directory
10
+ @config.instance_variable_get(:@base_directory)
11
+ end
12
+
13
+ def output_directory
14
+ @config.instance_variable_get(:@output_directory)
15
+ end
16
+
17
+ def scratch_directory
18
+ @config.instance_variable_get(:@scratch_directory)
19
+ end
20
+
21
+ def template_directory
22
+ @config.instance_variable_get(:@template_directory)
23
+ end
24
+
25
+ def template_class
26
+ @config.instance_variable_get(:@template_class)
27
+ end
28
+
29
+ def metric_fu_root
30
+ @config.instance_variable_get(:@metric_fu_root_directory)
31
+ end
32
+
33
+ describe '#warn_about_deprecated_config_options' do
34
+
35
+ def get_new_config_and_raise_runtime_error
36
+ lambda { get_new_config }.should raise_error
37
+ end
38
+
39
+ describe 'when ::MetricFu::CHURN_OPTIONS is present' do
40
+ before(:each) { ::MetricFu::CHURN_OPTIONS = 'option' }
41
+ after(:each) { ::MetricFu.send(:remove_const, 'CHURN_OPTIONS') }
42
+
43
+ it 'should raise a RuntimeError with "Use config.churn '+
44
+ 'instead of MetricFu::CHURN_OPTIONS"' do
45
+ get_new_config_and_raise_runtime_error
46
+ end
47
+ end
48
+
49
+ describe 'when ::MetricFu::DIRECTORIES_TO_FLOG is present' do
50
+ before(:each) { ::MetricFu::DIRECTORIES_TO_FLOG = 'option' }
51
+ after(:each) { ::MetricFu.send(:remove_const,'DIRECTORIES_TO_FLOG')}
52
+
53
+ it 'should raise a RuntimeError with "Use config.flog '+
54
+ '[:dirs_to_flog] instead of MetricFu::DIRECTORIES_TO_FLOG' do
55
+ get_new_config_and_raise_runtime_error
56
+ end
57
+ end
58
+
59
+ describe 'when ::MetricFu::SAIKURO_OPTIONS is present' do
60
+ before(:each) { ::MetricFu::SAIKURO_OPTIONS = 'option' }
61
+ after(:each) { ::MetricFu.send(:remove_const,'SAIKURO_OPTIONS')}
62
+
63
+ it 'should raise a RuntimeError with "Use config.saikuro '+
64
+ 'instead of MetricFu::SAIKURO_OPTIONS' do
65
+ get_new_config_and_raise_runtime_error
66
+ end
67
+ end
68
+
69
+ describe 'when SAIKURO_OPTIONS is present' do
70
+ before(:each) { SAIKURO_OPTIONS = 'option' }
71
+ after(:each) { Object.send(:remove_const,'SAIKURO_OPTIONS')}
72
+
73
+ it 'should raise a RuntimeError with "Use config.saikuro '+
74
+ 'instead of SAIKURO_OPTIONS' do
75
+ get_new_config_and_raise_runtime_error
76
+ end
77
+ end
78
+ end
79
+
80
+ describe "#reset" do
81
+
82
+ before(:each) { get_new_config }
83
+
84
+ describe 'when there is a CC_BUILD_ARTIFACTS environment variable' do
85
+ before(:each) { ENV['CC_BUILD_ARTIFACTS'] = 'foo' }
86
+
87
+ it 'should return the CC_BUILD_ARTIFACTS environment variable' do
88
+ get_new_config
89
+ base_directory.should == ENV['CC_BUILD_ARTIFACTS']
90
+ end
91
+ end
92
+
93
+ describe 'when there is no CC_BUILD_ARTIFACTS environment variable' do
94
+ before(:each) { ENV['CC_BUILD_ARTIFACTS'] = nil }
95
+
96
+ it 'should return "tmp/metric_fu"' do
97
+ get_new_config
98
+ base_directory.should == "tmp/metric_fu"
99
+ end
100
+ end
101
+
102
+ it 'should set @metric_fu_root_directory to the base of the '+
103
+ 'metric_fu application' do
104
+ app_root = File.join(File.dirname(__FILE__), '..', '..')
105
+ app_root_absolute_path = File.expand_path(app_root)
106
+ metric_fu_absolute_path = File.expand_path(metric_fu_root)
107
+ metric_fu_absolute_path.should == app_root_absolute_path
108
+ end
109
+
110
+ it 'should set @template_directory to the lib/templates relative '+
111
+ 'to @metric_fu_root_directory' do
112
+ template_dir = File.join(File.dirname(__FILE__),
113
+ '..', '..', 'lib','templates')
114
+ template_dir_abs_path = File.expand_path(template_dir)
115
+ calc_template_dir_abs_path = File.expand_path(template_directory)
116
+ calc_template_dir_abs_path.should == template_dir_abs_path
117
+ end
118
+
119
+ it 'should set @scratch_directory to scratch relative '+
120
+ 'to @base_directory' do
121
+ scratch_dir = File.join(base_directory, 'scratch')
122
+ scratch_directory.should == scratch_dir
123
+ end
124
+
125
+ it 'should set @output_directory to output relative '+
126
+ 'to @base_directory' do
127
+ output_dir = File.join(base_directory, 'output')
128
+ output_directory.should == output_dir
129
+ end
130
+
131
+ it 'should set @template_class to StandardTemplate' do
132
+ template_class.should == StandardTemplate
133
+ end
134
+
135
+ it 'should set @flay to {:dirs_to_flay => @code_dirs}' do
136
+ @config.instance_variable_get(:@flay).
137
+ should == {:dirs_to_flay => ['lib']}
138
+ end
139
+
140
+ it 'should set @flog to {:dirs_to_flog => @code_dirs}' do
141
+ @config.instance_variable_get(:@flog).
142
+ should == {:dirs_to_flog => ['lib']}
143
+ end
144
+
145
+ it 'should set @reek to {:dirs_to_reek => @code_dirs}' do
146
+ @config.instance_variable_get(:@reek).
147
+ should == {:dirs_to_reek => ['lib']}
148
+ end
149
+
150
+ it 'should set @roodi to {:dirs_to_roodi => @code_dirs}' do
151
+ @config.instance_variable_get(:@roodi).
152
+ should == {:dirs_to_roodi => ['lib']}
153
+ end
154
+
155
+ it 'should set @churn to {}' do
156
+ @config.instance_variable_get(:@churn).
157
+ should == {}
158
+ end
159
+
160
+ it 'should set @stats to {}' do
161
+ @config.instance_variable_get(:@stats).
162
+ should == {}
163
+ end
164
+
165
+ it 'should set @rcov to { :test_files => ["test/**/*_test.rb",
166
+ "spec/**/*_spec.rb"]
167
+ :rcov_opts => ["--sort coverage",
168
+ "--no-html",
169
+ "--text-coverage",
170
+ "--no-color",
171
+ "--profile",
172
+ "--rails",
173
+ "--exclude /gems/,/Library/,spec"]}' do
174
+ @config.instance_variable_get(:@rcov).
175
+ should == { :test_files => ['test/**/*_test.rb',
176
+ 'spec/**/*_spec.rb'],
177
+ :rcov_opts => ["--sort coverage",
178
+ "--no-html",
179
+ "--text-coverage",
180
+ "--no-color",
181
+ "--profile",
182
+ "--rails",
183
+ "--exclude /gems/,/Library/,spec"]}
184
+ end
185
+
186
+ it 'should set @saikuro to { :output_directory => @scratch_directory + "/saikuro",
187
+ :input_directory => @code_dirs,
188
+ :cyclo => "",
189
+ :filter_cyclo => "0",
190
+ :warn_cyclo => "5",
191
+ :error_cyclo => "7",
192
+ :formater => "text" }' do
193
+ @config.instance_variable_get(:@saikuro).
194
+ should == { :output_directory => 'tmp/metric_fu/scratch/saikuro',
195
+ :input_directory => ['lib'],
196
+ :cyclo => "",
197
+ :filter_cyclo => "0",
198
+ :warn_cyclo => "5",
199
+ :error_cyclo => "7",
200
+ :formater => "text"}
201
+ end
202
+
203
+ describe 'if #rails? is true ' do
204
+ before(:each) do
205
+ @config.stub!(:rails?).and_return(true)
206
+ end
207
+
208
+ describe '#set_metrics ' do
209
+ it 'should set the @metrics instance var to AVAILABLE_METRICS + '\
210
+ +'[:stats]' do
211
+ @config.instance_variable_get(:@metrics).
212
+ should == MetricFu::AVAILABLE_METRICS << [:stats]
213
+ end
214
+ end
215
+
216
+ describe '#set_code_dirs ' do
217
+ it 'should set the @code_dirs instance var to ["app", "lib"]' do
218
+ # This is hard to spec properly because the @code_dirs variable
219
+ # is set during the reset process.
220
+ #@config.instance_variable_get(:@code_dirs).
221
+ # should == ['app','lib']
222
+ end
223
+ end
224
+ end
225
+
226
+ describe 'if #rails? is false ' do
227
+ before(:each) do
228
+ @config.stub!(:rails?).and_return(false)
229
+ end
230
+
231
+ describe '#set_metrics ' do
232
+ it 'should set the @metrics instance var to AVAILABLE_METRICS' do
233
+ @config.instance_variable_get(:@metrics).
234
+ should == MetricFu::AVAILABLE_METRICS
235
+ end
236
+ end
237
+
238
+ describe '#set_code_dirs ' do
239
+ it 'should set the @code_dirs instance var to ["lib"]' do
240
+ @config.instance_variable_get(:@code_dirs).should == ['lib']
241
+ end
242
+ end
243
+ end
244
+ end
245
+
246
+ describe '#add_attr_accessors_to_self' do
247
+
248
+ before(:each) { get_new_config }
249
+
250
+ MetricFu::AVAILABLE_METRICS.each do |metric|
251
+ it "should have a reader for #{metric}" do
252
+ @config.respond_to?(metric).should be_true
253
+ end
254
+
255
+ it "should have a writer for #{metric}=" do
256
+ @config.respond_to?((metric.to_s + '=').to_sym).should be_true
257
+ end
258
+ end
259
+ end
260
+
261
+ describe '#add_class_methods_to_metric_fu' do
262
+
263
+ before(:each) { get_new_config }
264
+
265
+ MetricFu::AVAILABLE_METRICS.each do |metric|
266
+ it "should add a #{metric} class method to the MetricFu module " do
267
+ MetricFu.respond_to?(metric).should be_true
268
+ end
269
+ end
270
+ end
271
+
272
+ describe '#platform' do
273
+
274
+ before(:each) { get_new_config }
275
+
276
+ it 'should return the value of the PLATFORM constant' do
277
+ this_platform = PLATFORM
278
+ @config.platform.should == this_platform
279
+ end
280
+ end
281
+
282
+ describe '#is_cruise_control_rb? ' do
283
+
284
+ before(:each) { get_new_config }
285
+ describe "when the CC_BUILD_ARTIFACTS env var is not nil" do
286
+
287
+ before(:each) { ENV['CC_BUILD_ARTIFACTS'] = 'is set' }
288
+
289
+ it 'should return true' do
290
+ @config.is_cruise_control_rb?.should be_true
291
+ end
292
+
293
+ end
294
+
295
+ describe "when the CC_BUILD_ARTIFACTS env var is nil" do
296
+ before(:each) { ENV['CC_BUILD_ARTIFACTS'] = nil }
297
+
298
+ it 'should return false' do
299
+ @config.is_cruise_control_rb?.should be_false
300
+ end
301
+ end
302
+ end
303
+ end
@@ -0,0 +1,159 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper.rb"
2
+
3
+ describe MetricFu::Generator do
4
+
5
+ MetricFu::Configuration.run do |config|
6
+ end
7
+
8
+ class ConcreteClass < MetricFu::Generator
9
+ def emit
10
+ end
11
+
12
+ def analyze
13
+ end
14
+
15
+ def to_h
16
+ end
17
+ end
18
+
19
+ before(:each) do
20
+ @concrete_class = ConcreteClass.new
21
+ end
22
+
23
+ describe "ConcreteClass#class_name" do
24
+ it "should be 'concreteclass'" do
25
+ ConcreteClass.class_name.should == 'concreteclass'
26
+ end
27
+ end
28
+
29
+ describe "ConcreteClass#metric_directory" do
30
+ it "should be 'tmp/metric_fu/scratch/concreteclass'" do
31
+ ConcreteClass.metric_directory.
32
+ should == "tmp/metric_fu/scratch/concreteclass"
33
+ end
34
+ end
35
+
36
+ describe "#create_metric_dir_if_missing " do
37
+ describe "when the metric_dir exists " do
38
+ it 'should not call mkdir_p on FileUtils' do
39
+ File.stub!(:directory?).and_return(true)
40
+ FileUtils.should_not_receive(:mkdir_p)
41
+ @concrete_class.create_metric_dir_if_missing
42
+ end
43
+ end
44
+
45
+ describe "when the metric_dir does not exist " do
46
+ it 'should call mkdir_p on FileUtils' do
47
+ File.stub!(:directory?).and_return(false)
48
+ FileUtils.should_receive(:mkdir_p)
49
+ @concrete_class.create_metric_dir_if_missing
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "#create_output_dir_if_missing" do
55
+ describe "when the output_dir exists " do
56
+ it 'should not call mkdir_p on FileUtils' do
57
+ File.stub!(:directory?).and_return(true)
58
+ FileUtils.should_not_receive(:mkdir_p)
59
+ @concrete_class.create_output_dir_if_missing
60
+ end
61
+ end
62
+
63
+ describe "when the output_dir does not exist " do
64
+ it 'should call mkdir_p on FileUtils' do
65
+ File.stub!(:directory?).and_return(false)
66
+ FileUtils.should_receive(:mkdir_p)
67
+ @concrete_class.create_output_dir_if_missing
68
+ end
69
+ end
70
+ end
71
+
72
+ describe '#metric_directory' do
73
+ it 'should return the results of ConcreteClass#metric_directory' do
74
+ ConcreteClass.stub!(:metric_directory).and_return('foo')
75
+ @concrete_class.metric_directory.should == 'foo'
76
+ end
77
+ end
78
+
79
+ describe 'ConcreteClass#generate_report' do
80
+ it 'should create a new instance of ConcreteClass' do
81
+ ConcreteClass.should_receive(:new).and_return(@concrete_class)
82
+ @concrete_class.should_receive(:generate_report).and_return(true)
83
+ ConcreteClass.generate_report
84
+ end
85
+
86
+ it 'should call #generate_report on the new ConcreteClass' do
87
+ ConcreteClass.should_receive(:new).and_return(@concrete_class)
88
+ @concrete_class.should_receive(:generate_report).and_return(true)
89
+ ConcreteClass.generate_report
90
+ end
91
+ end
92
+
93
+ describe '@concrete_class should have hook methods for '\
94
+ +'[before|after]_[emit|analyze|to_h]' do
95
+
96
+ %w[emit analyze].each do |meth|
97
+
98
+ it "should respond to #before_#{meth}" do
99
+ @concrete_class.respond_to?("before_#{meth}".to_sym).should be_true
100
+ end
101
+
102
+ it "should respond to #after_#{meth}" do
103
+ @concrete_class.respond_to?("after_#{meth}".to_sym).should be_true
104
+ end
105
+ end
106
+
107
+ it "should respond to #before_to_h" do
108
+ @concrete_class.respond_to?("before_to_h".to_sym).should be_true
109
+ end
110
+ end
111
+
112
+ describe "#generate_report" do
113
+ it 'should raise an error when calling #emit' do
114
+ @abstract_class = MetricFu::Generator.new
115
+ lambda { @abstract_class.generate_report }.should raise_error
116
+ end
117
+
118
+ it 'should call #analyze' do
119
+ @abstract_class = MetricFu::Generator.new
120
+ lambda { @abstract_class.generate_report }.should raise_error
121
+ end
122
+
123
+ it 'should call #to_h' do
124
+ @abstract_class = MetricFu::Generator.new
125
+ lambda { @abstract_class.generate_report }.should raise_error
126
+ end
127
+ end
128
+
129
+ describe "#generate_report (in a concrete class)" do
130
+
131
+ %w[emit analyze].each do |meth|
132
+ it "should call #before_#{meth}" do
133
+ @concrete_class.should_receive("before_#{meth}")
134
+ @concrete_class.generate_report
135
+ end
136
+
137
+ it "should call ##{meth}" do
138
+ @concrete_class.should_receive("#{meth}")
139
+ @concrete_class.generate_report
140
+ end
141
+
142
+ it "should call #after_#{meth}" do
143
+ @concrete_class.should_receive("after_#{meth}")
144
+ @concrete_class.generate_report
145
+ end
146
+ end
147
+
148
+ it "should call #before_to_h" do
149
+ @concrete_class.should_receive("before_to_h")
150
+ @concrete_class.generate_report
151
+ end
152
+
153
+ it "should call #to_h" do
154
+ @concrete_class.should_receive(:to_h)
155
+ @concrete_class.generate_report
156
+ end
157
+
158
+ end
159
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
2
 
3
3
  describe MetricFu::MD5Tracker do
4
4
  before do
@@ -0,0 +1,139 @@
1
+ require File.dirname(__FILE__) + "/../spec_helper.rb"
2
+
3
+ describe MetricFu do
4
+
5
+ describe "#report" do
6
+ it 'should return an instance of Report' do
7
+ MetricFu.report.instance_of?(Report).should be(true)
8
+ end
9
+ end
10
+ end
11
+
12
+ describe MetricFu::Report do
13
+
14
+ before(:each) do
15
+ @report = MetricFu::Report.new
16
+ end
17
+
18
+ describe "#to_yaml" do
19
+ it 'should call #report_hash' do
20
+ report_hash = mock('report_hash')
21
+ report_hash.should_receive(:to_yaml)
22
+ @report.should_receive(:report_hash).and_return(report_hash)
23
+ @report.to_yaml
24
+ end
25
+ end
26
+
27
+ describe "#report_hash" do
28
+ end
29
+
30
+ describe "#save_templatized_report" do
31
+ it 'should create a new template class assign a report_hash '\
32
+ 'to the template class, and ask it to write itself out' do
33
+ template_class = mock('template_class')
34
+ template_class.should_receive(:new).and_return(template_class)
35
+ MetricFu.should_receive(:template_class).and_return(template_class)
36
+ template_class.should_receive(:report=)
37
+ template_class.should_receive(:write)
38
+ @report.save_templatized_report
39
+ end
40
+ end
41
+
42
+ describe "#add" do
43
+ it 'should add a passed hash to the report_hash instance variable' do
44
+ report_type = mock('report_type')
45
+ report_type.should_receive(:to_s).and_return('type')
46
+ report_type.should_receive(:generate_report).and_return({:a => 'b'})
47
+ MetricFu.should_receive(:const_get).
48
+ with('Type').and_return(report_type)
49
+ report_hash = mock('report_hash')
50
+ report_hash.should_receive(:merge!).with({:a => 'b'})
51
+ @report.should_receive(:report_hash).and_return(report_hash)
52
+ @report.add(report_type)
53
+ end
54
+ end
55
+
56
+ describe "#save_output" do
57
+ it 'should write the passed content to dir/index.html' do
58
+ f = mock('file')
59
+ content = 'content'
60
+ @report.should_receive(:open).with('dir/file', 'w').and_yield(f)
61
+ f.should_receive(:puts).with(content)
62
+ @report.save_output(content, 'dir', 'file')
63
+ end
64
+ end
65
+
66
+ describe '#open_in_browser? ' do
67
+
68
+ before(:each) do
69
+ @config = mock('configuration')
70
+ end
71
+
72
+ describe 'when the platform is os x ' do
73
+
74
+ before(:each) do
75
+ @config.should_receive(:platform).and_return('darwin')
76
+ end
77
+
78
+ describe 'and we are in cruise control ' do
79
+
80
+ before(:each) do
81
+ @config.should_receive(:is_cruise_control_rb?).and_return(true)
82
+ MetricFu.stub!(:configuration).and_return(@config)
83
+ end
84
+
85
+ it 'should return false' do
86
+ @report.open_in_browser?.should be_false
87
+ end
88
+ end
89
+
90
+ describe 'and we are not in cruise control' do
91
+
92
+ before(:each) do
93
+ @config.should_receive(:is_cruise_control_rb?).and_return(false)
94
+ MetricFu.stub!(:configuration).and_return(@config)
95
+ end
96
+
97
+ it 'should return true' do
98
+ @report.open_in_browser?.should be_true
99
+ end
100
+ end
101
+ end
102
+
103
+ describe 'when the platform is not os x ' do
104
+ before(:each) do
105
+ @config.should_receive(:platform).and_return('other')
106
+ end
107
+
108
+ describe 'and we are in cruise control' do
109
+ before(:each) do
110
+ MetricFu.stub!(:configuration).and_return(@config)
111
+ end
112
+
113
+ it 'should return false' do
114
+ @report.open_in_browser?.should be_false
115
+ end
116
+ end
117
+
118
+ describe 'and we are not in cruise control' do
119
+ before(:each) do
120
+ MetricFu.stub!(:configuration).and_return(@config)
121
+ end
122
+
123
+ it 'should return false' do
124
+ @report.open_in_browser?.should be_false
125
+ end
126
+ end
127
+ end
128
+ end
129
+
130
+
131
+ describe '#show_in_browser' do
132
+ it 'should call open with the passed directory' do
133
+ @report.should_receive(:open_in_browser?).and_return(true)
134
+ @report.should_receive(:system).with("open my_dir/index.html")
135
+ @report.show_in_browser('my_dir')
136
+ end
137
+
138
+ end
139
+ end