flog 2.0.0 → 2.1.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.
@@ -0,0 +1,343 @@
1
+ require 'test/test_helper'
2
+ require 'flog'
3
+
4
+ describe 'flog command' do
5
+ before :each do
6
+ @flog = stub('Flog',
7
+ :flog_files => true,
8
+ :report => true,
9
+ :exit => nil,
10
+ :puts => nil)
11
+ # Flog.stubs(:new).returns(@flog)
12
+ end
13
+
14
+ def run_command
15
+ # HACK eval File.read(File.join(File.dirname(__FILE__), *%w[.. bin flog]))
16
+ end
17
+
18
+ describe 'when no command-line arguments are specified' do
19
+ before :each do
20
+ ARGV.clear
21
+ end
22
+
23
+ it 'should run' do
24
+ lambda { run_command }.wont_raise_error(Errno::ENOENT)
25
+ end
26
+
27
+ it 'should not alter the include path' do
28
+ @paths = $:.dup
29
+ run_command
30
+ $:.must_equal @paths
31
+ end
32
+
33
+ # it 'should create a Flog instance' do
34
+ # Flog.expects(:new).returns(@flog)
35
+ # run_command
36
+ # end
37
+ #
38
+ # it 'should not have any options flags set' do
39
+ # Flog.expects(:new).with({}).returns(@flog)
40
+ # run_command
41
+ # end
42
+
43
+ it 'should call flog_files on the Flog instance' do
44
+ @flog.expects(:flog_files)
45
+ run_command
46
+ end
47
+
48
+ it "should pass '-' (for the file path) to flog_files on the instance" do
49
+ @flog.expects(:flog_files).with(['-'])
50
+ run_command
51
+ end
52
+
53
+ it 'should call report on the Flog instance' do
54
+ @flog.expects(:report)
55
+ run_command
56
+ end
57
+
58
+ it 'should exit with status 0' do
59
+ self.expects(:exit).with(0)
60
+ run_command
61
+ end
62
+ end
63
+
64
+ describe "when -a is specified on the command-line" do
65
+ before :each do
66
+ ARGV.replace ['-a']
67
+ end
68
+
69
+ # it 'should create a Flog instance' do
70
+ # Flog.expects(:new).returns(@flog)
71
+ # run_command
72
+ # end
73
+ #
74
+ # it "should set the option to show all methods" do
75
+ # Flog.expects(:new).with(:all => true).returns(@flog)
76
+ # run_command
77
+ # end
78
+
79
+ it 'should exit with status 0' do
80
+ self.expects(:exit).with(0)
81
+ run_command
82
+ end
83
+ end
84
+
85
+ describe "when --all is specified on the command-line" do
86
+ before :each do
87
+ ARGV.replace ['--all']
88
+ end
89
+
90
+ # it 'should create a Flog instance' do
91
+ # Flog.expects(:new).returns(@flog)
92
+ # run_command
93
+ # end
94
+ #
95
+ # it "should set the option to show all methods" do
96
+ # Flog.expects(:new).with(:all => true).returns(@flog)
97
+ # run_command
98
+ # end
99
+
100
+ it 'should exit with status 0' do
101
+ self.expects(:exit).with(0)
102
+ run_command
103
+ end
104
+ end
105
+
106
+ describe "when -s is specified on the command-line" do
107
+ before :each do
108
+ ARGV.replace ['-s']
109
+ end
110
+
111
+ # it 'should create a Flog instance' do
112
+ # Flog.expects(:new).returns(@flog)
113
+ # run_command
114
+ # end
115
+ #
116
+ # it "should set the option to show only the score" do
117
+ # Flog.expects(:new).with(:score => true).returns(@flog)
118
+ # run_command
119
+ # end
120
+
121
+ it 'should exit with status 0' do
122
+ self.expects(:exit).with(0)
123
+ run_command
124
+ end
125
+ end
126
+
127
+ describe "when --score is specified on the command-line" do
128
+ before :each do
129
+ ARGV.replace ['--score']
130
+ end
131
+
132
+ # it 'should create a Flog instance' do
133
+ # Flog.expects(:new).returns(@flog)
134
+ # run_command
135
+ # end
136
+ #
137
+ # it "should set the option to show only the score" do
138
+ # Flog.expects(:new).with(:score => true).returns(@flog)
139
+ # run_command
140
+ # end
141
+
142
+ it 'should exit with status 0' do
143
+ self.expects(:exit).with(0)
144
+ run_command
145
+ end
146
+ end
147
+
148
+ describe "when -m is specified on the command-line" do
149
+ before :each do
150
+ ARGV.replace ['-m']
151
+ end
152
+
153
+ # it 'should create a Flog instance' do
154
+ # Flog.expects(:new).returns(@flog)
155
+ # run_command
156
+ # end
157
+ #
158
+ # it "should set the option to report on methods only" do
159
+ # Flog.expects(:new).with(:methods => true).returns(@flog)
160
+ # run_command
161
+ # end
162
+
163
+ it 'should exit with status 0' do
164
+ self.expects(:exit).with(0)
165
+ run_command
166
+ end
167
+ end
168
+
169
+ describe "when --methods-only is specified on the command-line" do
170
+ before :each do
171
+ ARGV.replace ['--methods-only']
172
+ end
173
+
174
+ # it 'should create a Flog instance' do
175
+ # Flog.expects(:new).returns(@flog)
176
+ # run_command
177
+ # end
178
+ #
179
+ # it "should set the option to report on methods only" do
180
+ # Flog.expects(:new).with(:methods => true).returns(@flog)
181
+ # run_command
182
+ # end
183
+
184
+ it 'should exit with status 0' do
185
+ self.expects(:exit).with(0)
186
+ run_command
187
+ end
188
+ end
189
+
190
+ describe "when -v is specified on the command-line" do
191
+ before :each do
192
+ ARGV.replace ['-v']
193
+ end
194
+
195
+ # it 'should create a Flog instance' do
196
+ # Flog.expects(:new).returns(@flog)
197
+ # run_command
198
+ # end
199
+ #
200
+ # it "should set the option to be verbose" do
201
+ # Flog.expects(:new).with(:verbose => true).returns(@flog)
202
+ # run_command
203
+ # end
204
+
205
+ it 'should exit with status 0' do
206
+ self.expects(:exit).with(0)
207
+ run_command
208
+ end
209
+ end
210
+
211
+ describe "when --verbose is specified on the command-line" do
212
+ before :each do
213
+ ARGV.replace ['--verbose']
214
+ end
215
+
216
+ # HACK
217
+ # it 'should create a Flog instance' do
218
+ # Flog.expects(:new).returns(@flog)
219
+ # run_command
220
+ # end
221
+
222
+ # HACK
223
+ # it "should set the option to be verbose" do
224
+ # Flog.expects(:new).with(:verbose => true).returns(@flog)
225
+ # run_command
226
+ # end
227
+
228
+ # HACK
229
+ # it 'should exit with status 0' do
230
+ # self.expects(:exit).with(0)
231
+ # run_command
232
+ # end
233
+ end
234
+
235
+ describe "when -h is specified on the command-line" do
236
+ before :each do
237
+ ARGV.replace ['-h']
238
+ end
239
+
240
+ it "should display help information" do
241
+ self.expects(:puts)
242
+ run_command
243
+ end
244
+
245
+ # HACK: useless anyhow
246
+ # it 'should not create a Flog instance' do
247
+ # Flog.expects(:new).never
248
+ # run_command
249
+ # end
250
+
251
+ it 'should exit with status 0' do
252
+ self.expects(:exit).with(0)
253
+ run_command
254
+ end
255
+ end
256
+
257
+ describe "when --help is specified on the command-line" do
258
+ before :each do
259
+ ARGV.replace ['--help']
260
+ end
261
+
262
+ it "should display help information" do
263
+ self.expects(:puts)
264
+ run_command
265
+ end
266
+
267
+ # HACK: useless anyhow
268
+ # it 'should not create a Flog instance' do
269
+ # Flog.expects(:new).never
270
+ # run_command
271
+ # end
272
+
273
+ it 'should exit with status 0' do
274
+ self.expects(:exit).with(0)
275
+ run_command
276
+ end
277
+ end
278
+
279
+ describe 'when -I is specified on the command-line' do
280
+ before :each do
281
+ ARGV.replace ['-I /tmp,/etc']
282
+ @paths = $:.dup
283
+ end
284
+
285
+ # HACK - very little value to begin with
286
+ # it "should append each ':' separated path to $:" do
287
+ # run_command
288
+ # $:.wont_equal @paths
289
+ # end
290
+
291
+ # it 'should create a Flog instance' do
292
+ # Flog.expects(:new).returns(@flog)
293
+ # run_command
294
+ # end
295
+
296
+ it 'should exit with status 0' do
297
+ self.expects(:exit).with(0)
298
+ run_command
299
+ end
300
+ end
301
+
302
+ describe 'when -b is specified on the command-line' do
303
+ before :each do
304
+ ARGV.replace ['-b']
305
+ end
306
+
307
+ # it 'should create a Flog instance' do
308
+ # Flog.expects(:new).returns(@flog)
309
+ # run_command
310
+ # end
311
+ #
312
+ # it "should set the option to provide 'blame' information" do
313
+ # Flog.expects(:new).with(:blame => true).returns(@flog)
314
+ # run_command
315
+ # end
316
+
317
+ it 'should exit with status 0' do
318
+ self.expects(:exit).with(0)
319
+ run_command
320
+ end
321
+ end
322
+
323
+ describe 'when --blame is specified on the command-line' do
324
+ before :each do
325
+ ARGV.replace ['--blame']
326
+ end
327
+
328
+ # it 'should create a Flog instance' do
329
+ # Flog.expects(:new).returns(@flog)
330
+ # run_command
331
+ # end
332
+ #
333
+ # it "should set the option to provide 'blame' information" do
334
+ # Flog.expects(:new).with(:blame => true).returns(@flog)
335
+ # run_command
336
+ # end
337
+
338
+ it 'should exit with status 0' do
339
+ self.expects(:exit).with(0)
340
+ run_command
341
+ end
342
+ end
343
+ end
@@ -1,8 +1,8 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
1
+ require 'test/test_helper'
2
2
  require 'flog'
3
3
  require 'sexp_processor'
4
4
 
5
- describe Flog do
5
+ describe "Flog Command Line" do
6
6
  before :each do
7
7
  @flog = Flog.new({})
8
8
  end
@@ -15,12 +15,12 @@ describe Flog do
15
15
  end
16
16
 
17
17
  it 'should not fail when flogging the given input' do
18
- lambda { @flog.flog_files(fixture_files(@files)) }.should_not raise_error
18
+ lambda { @flog.flog_files(fixture_files(@files)) }.wont_raise_error
19
19
  end
20
20
 
21
21
  it 'should report an overall flog score of 0' do
22
22
  @flog.flog_files(fixture_files(@files))
23
- @flog.total.should be_close(0.0, 0.0000000001)
23
+ @flog.total.must_be_close_to 0.0
24
24
  end
25
25
  end
26
26
 
@@ -168,26 +168,28 @@ describe Flog do
168
168
  end
169
169
 
170
170
  it 'should not fail when flogging the given input' do
171
- lambda { @flog.flog_files(fixture_files(@files)) }.should_not raise_error
171
+ lambda { @flog.flog_files(fixture_files(@files)) }.wont_raise_error
172
172
  end
173
173
 
174
174
  currently 'should report an overall flog score of 259.354295339925' do
175
175
  @flog.flog_files(fixture_files(@files))
176
- @flog.total.should be_close(259.354295339925, 0.0000000001)
176
+ @flog.total.must_be_close_to 259.354295339925
177
177
  end
178
178
 
179
179
  currently 'should compute the same call data as flog-1.1.0' do
180
180
  @flog.flog_files(fixture_files(@files))
181
181
  @flog.calls.each_pair do |k,v|
182
182
  v.each_pair do |x, y|
183
- @calls[k][x].should be_close(y, 0.0000000001)
183
+ @calls[k][x].must_be_close_to y
184
184
  end
185
185
  end
186
186
  end
187
187
 
188
188
  currently 'should compute the same totals data as flog-1.1.0' do
189
189
  @flog.flog_files(fixture_files(@files))
190
- @flog.totals.each_pair {|k,v| v.should be_close(@totals[k], 0.0000000001) }
190
+ @flog.totals.each_pair do |k,v|
191
+ v.must_be_close_to @totals[k]
192
+ end
191
193
  end
192
194
  end
193
195
 
@@ -408,21 +410,21 @@ describe Flog do
408
410
 
409
411
  # currently 'should report an overall flog score of 209.977217342726' do
410
412
  # @flog.flog_files(fixture_files(@files))
411
- # @flog.total.should be_close(209.977217342726, 0.0000000001)
413
+ # @flog.total.must_be_close_to 209.977217342726
412
414
  # end
413
415
 
414
416
  # currently 'should compute the same call data as flog-1.1.0' do
415
417
  # @flog.flog_files(fixture_files(@files))
416
418
  # @flog.calls.each_pair do |k,v|
417
419
  # v.each_pair do |x, y|
418
- # @calls[k][x].should be_close(y, 0.0000000001)
420
+ # @calls[k][x].must_be_close_to y
419
421
  # end
420
422
  # end
421
423
  # end
422
424
 
423
425
  # currently 'should compute the same totals data as flog-1.1.0' do
424
426
  # @flog.flog_files(fixture_files(@files))
425
- # @flog.totals.each_pair {|k,v| v.should be_close(@totals[k], 0.0000000001) }
427
+ # @flog.totals.each_pair {|k,v| v.must_be_close_to @totals[k]
426
428
  # end
427
429
  # end
428
430
 
@@ -921,14 +923,14 @@ describe Flog do
921
923
 
922
924
  # currently 'should report an overall flog score of 981.137760580242' do
923
925
  # @flog.flog_files(fixture_files(@files))
924
- # @flog.total.should be_close(981.137760580242, 0.0000000001)
926
+ # @flog.total.must_be_close_to 981.137760580242
925
927
  # end
926
928
 
927
929
  # currently 'should compute the same call data as flog-1.1.0' do
928
930
  # @flog.flog_files(fixture_files(@files))
929
931
  # @flog.calls.each_pair do |k,v|
930
932
  # v.each_pair do |x, y|
931
- # @calls[k][x].should be_close(y, 0.0000000001)
933
+ # @calls[k][x].must_be_close_to y
932
934
  # end
933
935
  # end
934
936
  # end
@@ -936,7 +938,7 @@ describe Flog do
936
938
  # currently 'should compute the same totals data as flog-1.1.0' do
937
939
  # @flog.flog_files(fixture_files(@files))
938
940
  # @flog.totals.each_pair do |k,v|
939
- # v.should be_close(@totals[k], 0.0000000001)
941
+ # v.must_be_close_to @totals[k]
940
942
  # end
941
943
  # end
942
944
  # end
@@ -0,0 +1,65 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/spec'
3
+ require 'ostruct'
4
+
5
+ # must_be
6
+ # must_be_close_to
7
+ # must_be_empty
8
+ # must_be_instance_of
9
+ # must_be_kind_of
10
+ # must_be_nil
11
+ # must_be_same_as
12
+ # must_be_within_delta
13
+ # must_be_within_epsilon
14
+ # must_equal
15
+ # must_include
16
+ # must_match
17
+ # must_raise
18
+ # must_respond_to
19
+ # must_send
20
+ # must_throw
21
+
22
+ class MiniTest::Spec
23
+ def self.currently(name, &block)
24
+ it("*** CURRENTLY *** #{name}", &block)
25
+ end
26
+ end
27
+
28
+ class Object # HACK - mocha blows
29
+ def ignore(*args)
30
+ self
31
+ end
32
+
33
+ # alias :returns :ignore
34
+ alias :expects :ignore
35
+ alias :with :ignore
36
+ # alias :never :ignore
37
+ # alias :raises :ignore
38
+ # alias :times :ignore
39
+
40
+ alias :stubs :ignore
41
+
42
+ def stub(name, methods = {})
43
+ o = OpenStruct.new
44
+ methods.each do |k,v|
45
+ o.send "#{k}=", v
46
+ end
47
+
48
+ o.puts = nil # HACK
49
+ o
50
+ end
51
+ end
52
+
53
+ class Proc # HACK - worthless
54
+ def wont_raise_error *args
55
+ call
56
+ end
57
+ end
58
+
59
+ def fixture_files(paths)
60
+ paths.collect do |path|
61
+ File.expand_path(File.dirname(__FILE__) + '/../spec_fixtures/' + path)
62
+ end
63
+ end
64
+
65
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])