rake-builder 0.9.2 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,27 +15,25 @@ describe Rake::Builder do
15
15
  end
16
16
  end
17
17
  let(:installer) do
18
- stub(
19
- 'Rake::Builder::Installer',
20
- :install => nil
21
- )
18
+ double(Rake::Builder::Installer, install: nil, uninstall: nil)
22
19
  end
23
20
 
24
21
  before do
25
- Rake::Path.stub(:find_files).and_return(source_paths)
22
+ allow(Rake::Path).to receive(:find_files) { source_paths }
23
+ allow(builder).to receive(:system)
26
24
  end
27
25
 
28
26
  context '.create_autoconf' do
29
- let(:version) { stub('Rake::Builder::Autoconf::Autoconf::Version', :decide => 'qux') }
30
- let(:presenter) { stub('Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter', :save => nil) }
31
- let(:configure_ac) { stub('Rake::Builder::ConfigureAc', :save => nil) }
27
+ let(:version) { double('Rake::Builder::Autoconf::Autoconf::Version', :decide => 'qux') }
28
+ let(:presenter) { double('Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter', :save => nil) }
29
+ let(:configure_ac) { double('Rake::Builder::ConfigureAc', :save => nil) }
32
30
 
33
31
  before do
34
- Rake::Builder::Autoconf::Version.stub(:new).and_return(version)
35
- File.stub(:exist?).with('configure.ac').and_return(false)
36
- File.stub(:exist?).with('Makefile.am').and_return(false)
37
- Rake::Builder::ConfigureAc.stub(:new => configure_ac)
38
- Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter.stub(:new).and_return(presenter)
32
+ allow(Rake::Builder::Autoconf::Version).to receive(:new) { version }
33
+ allow(File).to receive(:exist?).with('configure.ac') { false }
34
+ allow(File).to receive(:exist?).with('Makefile.am') { false }
35
+ allow(Rake::Builder::ConfigureAc).to receive(:new) { configure_ac }
36
+ allow(Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter).to receive(:new) { presenter }
39
37
  end
40
38
 
41
39
  it 'fails if project_title is nil' do
@@ -44,16 +42,20 @@ describe Rake::Builder do
44
42
  }.to raise_error(RuntimeError, 'Please supply a project_title parameter')
45
43
  end
46
44
 
47
- it 'fails if Version fails' do
48
- Rake::Builder::Autoconf::Version.stub(:new).and_raise('foo')
45
+ context 'if Version fails' do
46
+ before do
47
+ allow(Rake::Builder::Autoconf::Version).to receive(:new).and_raise('foo')
48
+ end
49
49
 
50
- expect {
51
- Rake::Builder.create_autoconf('foo', 'bar', 'baz')
52
- }.to raise_error(RuntimeError, 'foo')
50
+ it 'fails' do
51
+ expect {
52
+ Rake::Builder.create_autoconf('foo', 'bar', 'baz')
53
+ }.to raise_error(RuntimeError, 'foo')
54
+ end
53
55
  end
54
56
 
55
57
  it 'fails if configure.ac exists' do
56
- File.should_receive(:exist?).with('configure.ac').and_return(true)
58
+ allow(File).to receive(:exist?).with('configure.ac') { true }
57
59
 
58
60
  expect {
59
61
  Rake::Builder.create_autoconf('foo', 'bar', 'baz')
@@ -61,7 +63,7 @@ describe Rake::Builder do
61
63
  end
62
64
 
63
65
  it 'fails if Makefile.am exists' do
64
- File.should_receive(:exist?).with('Makefile.am').and_return(true)
66
+ allow(File).to receive(:exist?).with('Makefile.am') { true }
65
67
 
66
68
  expect {
67
69
  Rake::Builder.create_autoconf('foo', 'bar', 'baz')
@@ -69,13 +71,13 @@ describe Rake::Builder do
69
71
  end
70
72
 
71
73
  it 'creates configure.ac' do
72
- Rake::Builder::ConfigureAc.should_receive(:new).and_return(configure_ac)
74
+ allow(Rake::Builder::ConfigureAc).to receive(:new) { configure_ac }
73
75
 
74
76
  Rake::Builder.create_autoconf('foo', 'bar', 'baz')
75
77
  end
76
78
 
77
79
  it 'creates Makefile.am' do
78
- Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter.should_receive(:new).and_return(presenter)
80
+ allow(Rake::Builder::Presenters::MakefileAm::BuilderCollectionPresenter).to receive(:new) { presenter }
79
81
 
80
82
  Rake::Builder.create_autoconf('foo', 'bar', 'baz')
81
83
  end
@@ -107,7 +109,7 @@ describe Rake::Builder do
107
109
  end
108
110
 
109
111
  it 'remembers the Rakefile path' do
110
- Rake::Path.stub(:find_files => ['main.cpp'])
112
+ allow(Rake::Path).to receive(:find_files) { ['main.cpp'] }
111
113
  here = File.dirname(File.expand_path(__FILE__))
112
114
 
113
115
  builder = Rake::Builder.new {}
@@ -119,13 +121,12 @@ describe Rake::Builder do
119
121
  context '#build' do
120
122
  before do
121
123
  @target_exists = [false, true]
122
- File.stub(:exist?).with(builder.target) { @target_exists.shift }
123
- builder.stub(:system => nil)
124
+ allow(File).to receive(:exist?).with(builder.target) { @target_exists.shift }
124
125
  `(exit 0)` # set $? to a successful Process::Status
125
126
  end
126
127
 
127
128
  it 'checks if the old target exists' do
128
- File.should_receive(:exist?).with(builder.target) { @target_exists.shift }
129
+ allow(File).to receive(:exist?).with(builder.target) { @target_exists.shift }
129
130
 
130
131
  builder.build
131
132
  end
@@ -133,7 +134,7 @@ describe Rake::Builder do
133
134
  it 'deletes the old target' do
134
135
  @target_exists = [true, true]
135
136
 
136
- File.should_receive(:unlink).with(builder.target)
137
+ allow(File).to receive(:unlink).with(builder.target)
137
138
 
138
139
  builder.build
139
140
  end
@@ -158,15 +159,14 @@ describe Rake::Builder do
158
159
  context '#run' do
159
160
  before do
160
161
  @old_dir = Dir.pwd
161
- Dir.stub(:chdir).with(builder.rakefile_path)
162
- builder.stub(:system)
163
- Dir.stub(:chdir).with(@old_dir)
162
+ allow(Dir).to receive(:chdir).with(builder.rakefile_path)
163
+ allow(Dir).to receive(:chdir).with(@old_dir)
164
164
  # Run a successful command, so Process:Status $? gets set to success
165
165
  `ls`
166
166
  end
167
167
 
168
168
  it 'changes directory to the Rakefile path' do
169
- Dir.should_receive(:chdir).with(builder.rakefile_path)
169
+ allow(Dir).to receive(:chdir).with(builder.rakefile_path)
170
170
 
171
171
  capturing_output do
172
172
  builder.run
@@ -174,27 +174,27 @@ describe Rake::Builder do
174
174
  end
175
175
 
176
176
  it 'runs the executable' do
177
- builder.should_receive(:system).with('./' + builder.target, anything)
178
-
179
177
  capturing_output do
180
178
  builder.run
181
179
  end
180
+
181
+ expect(builder).to have_received(:system).with('./' + builder.target, anything)
182
182
  end
183
183
 
184
184
  context 'target_parameters' do
185
185
  let(:target_parameters) { %w(--ciao) }
186
186
 
187
187
  it 'are passed as command line options to the target' do
188
- builder.should_receive(:system).with("./#{builder.target} --ciao", anything)
189
-
190
188
  capturing_output do
191
189
  builder.run
192
190
  end
191
+
192
+ expect(builder).to have_received(:system).with("./#{builder.target} --ciao", anything)
193
193
  end
194
194
  end
195
195
 
196
196
  it 'outputs the stdout results, then the stderr results' do
197
- builder.stub(:system) do |command|
197
+ allow(builder).to receive(:system) do |command|
198
198
  $stdout.puts 'standard output'
199
199
  $stderr.puts 'error output'
200
200
  end
@@ -208,7 +208,7 @@ describe Rake::Builder do
208
208
  end
209
209
 
210
210
  it 'raises and error is the program does not run successfully' do
211
- builder.stub(:system) { `(exit 1)` } # set $? to a failing Process::Status
211
+ allow(builder).to receive(:system) { `(exit 1)` } # set $? to a failing Process::Status
212
212
 
213
213
  expect {
214
214
  builder.run
@@ -216,18 +216,18 @@ describe Rake::Builder do
216
216
  end
217
217
 
218
218
  it 'restores the preceding working directory, even after errors' do
219
- builder.stub(:system).and_raise('foo')
220
-
221
- Dir.should_receive(:chdir).with(@old_dir)
219
+ allow(builder).to receive(:system).and_raise('foo')
222
220
 
223
221
  builder.run rescue nil
222
+
223
+ expect(Dir).to have_received(:chdir).with(@old_dir)
224
224
  end
225
225
  end
226
226
 
227
227
  context '#clean' do
228
228
  it 'checks if files exist' do
229
229
  exists = []
230
- File.stub(:exist?) { |file| exists << file; false }
230
+ allow(File).to receive(:exist?) { |file| exists << file; false }
231
231
 
232
232
  builder.clean
233
233
 
@@ -236,8 +236,8 @@ describe Rake::Builder do
236
236
 
237
237
  it 'deletes generated files' do
238
238
  deletes = []
239
- File.stub(:exist? => true)
240
- File.stub(:unlink) { |file| deletes << file }
239
+ allow(File).to receive(:exist?) { true }
240
+ allow(File).to receive(:unlink) { |file| deletes << file }
241
241
 
242
242
  builder.clean
243
243
 
@@ -267,7 +267,7 @@ describe Rake::Builder do
267
267
 
268
268
  context '#target' do
269
269
  it "defaults to 'a.out'" do
270
- Rake::Path.stub(:find_files => ['main.cpp'])
270
+ allow(Rake::Path).to receive(:find_files) { ['main.cpp'] }
271
271
 
272
272
  builder = Rake::Builder.new {}
273
273
 
@@ -296,7 +296,7 @@ describe Rake::Builder do
296
296
  ['libshared.so', :shared_library],
297
297
  ].each do |name, type|
298
298
  it "recognises '#{name}' as '#{type}'" do
299
- Rake::Path.stub(:find_files).and_return(['file'])
299
+ allow(Rake::Path).to receive(:find_files) { ['file'] }
300
300
 
301
301
  builder = Rake::Builder.new { |b| b.target = name }
302
302
 
@@ -322,17 +322,17 @@ describe Rake::Builder do
322
322
 
323
323
  context '#source_files' do
324
324
  it 'finds files with the .cpp extension' do
325
- Rake::Path.should_receive(:find_files).with(anything, 'cpp').and_return(['a.cpp'])
325
+ allow(Rake::Path).to receive(:find_files).with(anything, 'cpp') { ['a.cpp'] }
326
326
 
327
327
  builder
328
328
  end
329
329
 
330
330
  it 'should allow configuration of source extension' do
331
- Rake::Path.should_receive(:find_files).with(anything, 'cc').and_return(['a.cc'])
332
-
333
331
  Rake::Builder.new do |b|
334
332
  b.source_file_extension = 'cc'
335
333
  end
334
+
335
+ expect(Rake::Path).to have_received(:find_files).with(anything, 'cc') { ['a.cc'] }
336
336
  end
337
337
  end
338
338
 
@@ -362,15 +362,15 @@ describe Rake::Builder do
362
362
 
363
363
  context '#create_makedepend_file' do
364
364
  before do
365
- builder.stub(:system).with('which makedepend >/dev/null') do
365
+ allow(builder).to receive(:system).with('which makedepend >/dev/null') do
366
366
  `(exit 0)` # set $? to a successful Process::Status
367
367
  end
368
368
 
369
- builder.stub(:system).with(/makedepend -f-/, anything)
369
+ allow(builder).to receive(:system).with(/makedepend -f-/, anything)
370
370
  end
371
371
 
372
372
  it 'fails if makedepend is missing' do
373
- builder.stub(:system).with('which makedepend >/dev/null') do
373
+ allow(builder).to receive(:system).with('which makedepend >/dev/null') do
374
374
  `(exit 1)` # set $? to a successful Process::Status
375
375
  end
376
376
 
@@ -380,9 +380,9 @@ describe Rake::Builder do
380
380
  end
381
381
 
382
382
  it 'calls makedepend' do
383
- builder.should_receive(:system).with(/makedepend -f-/, anything)
384
-
385
383
  builder.create_makedepend_file
384
+
385
+ expect(builder).to have_received(:system).with(/makedepend -f-/, anything)
386
386
  end
387
387
  end
388
388
 
@@ -398,13 +398,7 @@ describe Rake::Builder do
398
398
  end
399
399
 
400
400
  before do
401
- File.stub(:read).with(builder.makedepend_file).and_return(content)
402
- end
403
-
404
- it 'opens the file' do
405
- File.should_receive(:read).with(builder.makedepend_file).and_return(content)
406
-
407
- builder.load_makedepend
401
+ allow(File).to receive(:read).with(builder.makedepend_file) { content }
408
402
  end
409
403
 
410
404
  it 'returns a map of sources to headers' do
@@ -421,7 +415,7 @@ describe Rake::Builder do
421
415
  let(:config_include_paths) { ['/path/one', '/path/two'] }
422
416
  let(:config_compilation_options) { ['opt1', 'opt2'] }
423
417
  let(:local_config) do
424
- stub(
418
+ double(
425
419
  'Rake::Builder::LocalConfig',
426
420
  :load => nil,
427
421
  :include_paths => config_include_paths,
@@ -429,14 +423,15 @@ describe Rake::Builder do
429
423
  )
430
424
  end
431
425
 
432
- before { Rake::Builder::LocalConfig.stub(:new => local_config) }
426
+ before { allow(Rake::Builder::LocalConfig).to receive(:new) { local_config } }
433
427
 
434
428
  it 'loads local config' do
435
- Rake::Builder::LocalConfig.should_receive(:new).
436
- with(/\.rake-builder/).and_return(local_config)
437
- local_config.should_receive(:load).with()
429
+ allow(Rake::Builder::LocalConfig).to receive(:new).
430
+ with(/\.rake-builder/) { local_config }
438
431
 
439
432
  builder.load_local_config
433
+
434
+ expect(local_config).to have_received(:load).with(no_args)
440
435
  end
441
436
 
442
437
  it 'adds include paths' do
@@ -458,7 +453,7 @@ describe Rake::Builder do
458
453
 
459
454
  context '#create_local_config' do
460
455
  let(:compiler) do
461
- stub(
456
+ double(
462
457
  'Compiler',
463
458
  :default_include_paths => [],
464
459
  :missing_headers => [],
@@ -466,7 +461,7 @@ describe Rake::Builder do
466
461
  )
467
462
  end
468
463
  let(:local_config) do
469
- stub(
464
+ double(
470
465
  'Rake::Builder::LocalConfig',
471
466
  :include_paths= => nil,
472
467
  :save => nil
@@ -474,39 +469,28 @@ describe Rake::Builder do
474
469
  end
475
470
 
476
471
  before do
477
- Compiler::Base.stub(:for).with(:gcc).and_return(compiler)
478
- Rake::Builder::LocalConfig.stub(:new).and_return(local_config)
479
- end
480
-
481
- it 'gets extra paths for missing headers' do
482
- compiler.should_receive(:missing_headers).
483
- with(['./include'], source_paths).
484
- and_return([])
485
-
486
- builder.create_local_config
472
+ allow(Compiler::Base).to receive(:for).with(:gcc) { compiler }
473
+ allow(Rake::Builder::LocalConfig).to receive(:new) { local_config }
487
474
  end
488
475
 
489
476
  it 'saves a LocalConfig' do
490
- local_config.should_receive(:save)
491
-
492
477
  builder.create_local_config
478
+
479
+ expect(local_config).to have_received(:save)
493
480
  end
494
481
  end
495
482
 
496
483
  context '#install' do
497
- before { Rake::Builder::Installer.stub(:new).and_return(installer) }
484
+ before { allow(Rake::Builder::Installer).to receive(:new) { installer } }
498
485
 
499
486
  it 'installs the target' do
500
- Rake::Builder::Installer.should_receive(:new).and_return(installer)
501
- installer.should_receive(:install).with(builder.target, anything)
502
-
503
487
  builder.install
488
+
489
+ expect(Rake::Builder::Installer).to have_received(:new) { installer }
504
490
  end
505
491
 
506
492
  it 'installs headers for static libraries' do
507
- installer.stub(:install).with(builder.target, anything)
508
- File.should_receive(:file?).with('header.h').and_return(true)
509
- installer.should_receive(:install).with('header.h', anything)
493
+ allow(File).to receive(:file?).with('header.h') { true }
510
494
 
511
495
  builder = Rake::Builder.new do |b|
512
496
  b.target = 'libthe_static_library.a'
@@ -514,18 +498,21 @@ describe Rake::Builder do
514
498
  end
515
499
 
516
500
  builder.install
501
+
502
+ expect(installer).to have_received(:install).with(builder.target, anything)
503
+ expect(installer).to have_received(:install).with('header.h', anything)
517
504
  end
518
505
  end
519
506
 
520
507
  context '#uninstall' do
521
- before { Rake::Builder::Installer.stub(:new).and_return(installer) }
508
+ before { allow(Rake::Builder::Installer).to receive(:new) { installer } }
522
509
 
523
510
  it 'uninstalls' do
524
511
  installed_path = File.join(builder.install_path, builder.target_basename)
525
- installer.should_receive(:uninstall).with(installed_path)
526
512
 
527
513
  builder.uninstall
514
+
515
+ expect(installer).to have_received(:uninstall).with(installed_path)
528
516
  end
529
517
  end
530
518
  end
531
-
@@ -2,61 +2,70 @@ require 'spec_helper'
2
2
 
3
3
  describe Rake::Microsecond::DirectoryTask do
4
4
  let(:path) { '/a/path' }
5
- let(:task) do
6
- task = Rake::Microsecond::DirectoryTask.define_task(path)
7
- task.stub(:mkdir_p => nil)
8
- task
9
- end
5
+
6
+ subject { described_class.define_task(path) }
10
7
 
11
8
  before do
9
+ allow(subject).to receive(:mkdir_p)
12
10
  Rake::Task.clear
13
11
  end
14
12
 
15
13
  context '#needed?' do
16
- let(:base_time) { Time.now }
17
- let(:task1) { Rake::Microsecond::DirectoryTask.define_task('/path1') }
18
- let(:task2) { Rake::Microsecond::DirectoryTask.define_task('/path2') }
19
- let(:needed_task) { Rake::Task.define_task('needed') }
20
- let(:unneeded_task) { Rake::Task.define_task('unneeded') }
14
+ let(:directory_task) { instance_double(Rake::Microsecond::DirectoryTask) }
15
+ let(:file_task) { instance_double(Rake::FileTask, timestamp: file_timestamp) }
16
+ let(:needed_task) { double(Rake::Task, needed?: true) }
17
+ let(:unneeded_task) { double(Rake::Task, needed?: false) }
18
+ let(:directory_mtime) { 33 }
19
+ let(:file_timestamp) { directory_mtime + 1 }
21
20
 
22
21
  context 'when the directory exists' do
22
+ let(:exists) { true }
23
+ let(:stat) { double(mtime: directory_mtime) }
24
+
23
25
  before do
24
- File.stub(:directory? => true)
25
- File.stub_chain(:stat, :mtime).and_return(33)
26
+ allow(File).to receive(:directory?) { exists }
27
+ allow(File).to receive(:stat) { stat }
28
+ allow(Rake.application).to receive(:[]).with(:directory_task) { directory_task }
29
+ allow(directory_task).to receive(:is_a?).with(described_class) { true }
30
+ allow(Rake.application).to receive(:[]).with(:file_task) { file_task }
31
+ allow(file_task).to receive(:is_a?).with(Rake::FileTask) { true }
32
+ allow(file_task).to receive(:is_a?).with(described_class) { false }
33
+ allow(Rake.application).to receive(:[]).with(:needed) { needed_task }
34
+ allow(Rake.application).to receive(:[]).with(:unneeded) { unneeded_task }
26
35
  end
27
36
 
28
- it 'true if a prerequisite FileTask is more recent' do
29
- task1.timestamp = base_time - 10
30
- task2.timestamp = base_time - 1
31
- task1.enhance([task2])
37
+ context 'if a prerequisite FileTask is more recent' do
38
+
39
+ it 'is needed' do
40
+ subject.enhance([:file_task])
32
41
 
33
- expect(task1).to be_needed
42
+ expect(subject).to be_needed
43
+ end
34
44
  end
35
45
 
36
46
  it 'true if a prerequisite non-FileTask is needed?' do
37
- task.enhance([needed_task])
47
+ subject.enhance([:needed])
38
48
 
39
- expect(task).to be_needed
49
+ expect(subject).to be_needed
40
50
  end
41
51
 
42
52
  it 'false otherwise' do
43
- task.enhance([unneeded_task])
44
- unneeded_task.stub(:needed? => false)
53
+ subject.enhance([:unneeded])
45
54
 
46
- expect(task).to_not be_needed
55
+ expect(subject).to_not be_needed
47
56
  end
48
57
  end
49
58
  end
50
59
 
51
60
  context '#execute' do
52
- let(:stub_time) { stub('Time') }
61
+ let(:now) { 12345 }
53
62
 
54
63
  it 'memorizes the directory creation time including fractional seconds' do
55
- Time.stub(:now => stub_time)
64
+ allow(Time).to receive(:now) { now }
56
65
 
57
- task.execute
66
+ subject.execute
58
67
 
59
- expect(task.timestamp).to eq(stub_time)
68
+ expect(subject.timestamp).to eq(now)
60
69
  end
61
70
  end
62
71
  end