Skip to content

Commit 82c2867

Browse files
author
Shane da Silva
committed
Upgrade to RSpec 3
As part of this upgrade, the following changes were made to fix some deprecation warnings and unsupported syntax: * Replacement of `its` with an `it` block equivalent * Renaming of `failure_message_for_should` -> `failure_message` and similar for negated form * Replacing `be_true` with `== true` and `be_false` with `== false` We've elected to keep the `should` syntax because it is convenient to do so; we may switch entirely to `expect` at some point in the future. Change-Id: I936bb63e33a301264c48185e7d91ba7ad04a87bf Reviewed-on: http://gerrit.causes.com/38489 Tested-by: jenkins <jenkins@causes.com> Reviewed-by: Shane da Silva <shane@causes.com>
1 parent 21e70c1 commit 82c2867

11 files changed

+50
-32
lines changed

overcommit.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ Gem::Specification.new do |s|
2929
s.add_dependency 'childprocess', '>= 0.5.1'
3030
s.add_dependency 'json', '>= 1.8' # For 1.8.7. support only
3131

32-
s.add_development_dependency 'rspec', '2.14.1'
32+
s.add_development_dependency 'rspec', '~> 3.0'
3333
s.add_development_dependency 'image_optim', '~> 0.13.0'
3434
end

spec/integration/committing_spec.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@
2828
`git config --local user.name ''`
2929
end
3030

31-
its(:status) { should_not be_zero }
31+
it 'exits with a non-zero status' do
32+
subject.status.should_not == 0
33+
end
3234
end
3335

3436
context 'when no hooks fail' do
3537
before do
3638
`git config --local user.name 'John Doe'`
3739
end
3840

39-
its(:status) { should be_zero }
41+
it 'exits successfully' do
42+
subject.status.should == 0
43+
end
4044
end
4145
end

spec/integration/resolving_cherry_pick_conflict_spec.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
end
3838
end
3939

40-
its(:status) { should == 1 }
40+
it 'exits with a non-zero status' do
41+
subject.status.should_not == 0
42+
end
4143

4244
it 'does not remove the CHERRY_PICK_HEAD file' do
4345
subject

spec/integration/resolving_merge_conflict_spec.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@
3737
end
3838
end
3939

40-
its(:status) { should be_zero }
40+
it 'exits successfully' do
41+
subject.status.should == 0
42+
end
4143

42-
# User should not get an error about MERGE_HEAD not existing
43-
its(:stderr) { should_not include 'MERGE_HEAD' }
44+
it 'does not display an error about MERGE_HEAD missing' do
45+
subject.stderr.should_not include 'MERGE_HEAD'
46+
end
4447
end

spec/overcommit/configuration_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@
9393
subject { config.for_hook('SomeHook', 'PreCommit') }
9494

9595
it 'returns the subset of the config for the specified hook' do
96-
subject['enabled'].should be_true
97-
subject['quiet'].should be_false
96+
subject['enabled'].should == true
97+
subject['quiet'].should == false
9898
end
9999

100100
it 'merges the the hook config with the ALL section' do
101-
subject['required'].should be_false
101+
subject['required'].should == false
102102
end
103103
end
104104

@@ -213,22 +213,22 @@
213213
let(:env) { { 'SKIP' => 'AuthorName' } }
214214

215215
it 'sets the skip option of the hook to true' do
216-
subject.for_hook('AuthorName', 'PreCommit')['skip'].should be_true
216+
subject.for_hook('AuthorName', 'PreCommit')['skip'].should == true
217217
end
218218

219219
context 'and the hook is spelt with underscores' do
220220
let(:env) { { 'SKIP' => 'author_name' } }
221221

222222
it 'sets the skip option of the hook to true' do
223-
subject.for_hook('AuthorName', 'PreCommit')['skip'].should be_true
223+
subject.for_hook('AuthorName', 'PreCommit')['skip'].should == true
224224
end
225225
end
226226

227227
context 'and the hook is spelt with hyphens' do
228228
let(:env) { { 'SKIP' => 'author-name' } }
229229

230230
it 'sets the skip option of the hook to true' do
231-
subject.for_hook('AuthorName', 'PreCommit')['skip'].should be_true
231+
subject.for_hook('AuthorName', 'PreCommit')['skip'].should == true
232232
end
233233
end
234234
end
@@ -237,14 +237,14 @@
237237
let(:env) { { 'SKIP' => 'all' } }
238238

239239
it 'sets the skip option of the ALL section to true' do
240-
subject.for_hook('ALL', 'PreCommit')['skip'].should be_true
240+
subject.for_hook('ALL', 'PreCommit')['skip'].should == true
241241
end
242242

243243
context 'and "all" is capitalized' do
244244
let(:env) { { 'SKIP' => 'ALL' } }
245245

246246
it 'sets the skip option of the special ALL config to true' do
247-
subject.for_hook('ALL', 'PreCommit')['skip'].should be_true
247+
subject.for_hook('ALL', 'PreCommit')['skip'].should == true
248248
end
249249
end
250250
end

spec/overcommit/hook_context/post_checkout_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
context 'when the flag is 0' do
2929
let(:branch_flag) { '0' }
3030

31-
it { should be_false }
31+
it { should == false }
3232
end
3333

3434
context 'when the flag is 1' do
35-
it { should be_true }
35+
it { should == true }
3636
end
3737
end
3838

@@ -42,11 +42,11 @@
4242
context 'when the flag is 0' do
4343
let(:branch_flag) { '0' }
4444

45-
it { should be_true }
45+
it { should == true }
4646
end
4747

4848
context 'when the flag is 1' do
49-
it { should be_false }
49+
it { should == false }
5050
end
5151
end
5252
end

spec/overcommit/hook_context/pre_commit_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146

147147
it 'deletes the file' do
148148
subject
149-
File.exist?('tracked-file').should be_false
149+
File.exist?('tracked-file').should == false
150150
end
151151
end
152152
end

spec/overcommit/hook_signer_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ def run
4444
end
4545

4646
context 'when the hook code and config are the same' do
47-
it { should be_false }
47+
it { should == false }
4848

4949
context 'and the user has specified they wish to skip the hook' do
5050
let(:modified_hook_config) { hook_config.merge('skip' => true) }
5151

52-
it { should be_false }
52+
it { should == false }
5353
end
5454
end
5555

@@ -64,13 +64,13 @@ def run
6464
end
6565
RUBY
6666

67-
it { should be_true }
67+
it { should == true }
6868
end
6969

7070
context 'when the hook config has changed' do
7171
let(:modified_hook_config) { { 'enabled' => true } }
7272

73-
it { should be_true }
73+
it { should == true }
7474
end
7575
end
7676
end

spec/overcommit/installer_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
context 'and Overcommit hooks were not previously installed' do
3333
it 'installs the master hook into the hooks directory' do
3434
subject
35-
File.file?(File.join(hooks_dir, 'overcommit-hook')).should be_true
35+
File.file?(File.join(hooks_dir, 'overcommit-hook')).should == true
3636
end
3737

3838
it 'symlinks all supported hooks to the master hook' do
@@ -50,7 +50,7 @@
5050

5151
it 'keeps the master hook' do
5252
expect { subject }.to_not change {
53-
File.file?(File.join(hooks_dir, 'overcommit-hook')).should be_true
53+
File.file?(File.join(hooks_dir, 'overcommit-hook')).should == true
5454
}
5555
end
5656

spec/spec_helper.rb

+9
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,13 @@
1919
config.include GitSpecHelpers
2020
config.include OutputHelpers
2121
config.include ShellHelpers
22+
23+
# Continue to enable the older `should` syntax for expectations
24+
config.expect_with :rspec do |c|
25+
c.syntax = [:expect, :should]
26+
end
27+
28+
config.mock_with :rspec do |c|
29+
c.syntax = :should
30+
end
2231
end

spec/support/matchers/hook.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ def failure_message(actual, error_message)
4646
check_matcher.matches?(actual)
4747
end
4848

49-
failure_message_for_should do
49+
failure_message do
5050
check_matcher.failure_message(
5151
actual,
5252
'expected that the hook would fail'
5353
)
5454
end
5555

56-
failure_message_for_should_not do
56+
failure_message_when_negated do
5757
'expected that the hook would not fail'
5858
end
5959

@@ -67,14 +67,14 @@ def failure_message(actual, error_message)
6767
check_matcher.matches?(actual)
6868
end
6969

70-
failure_message_for_should do
70+
failure_message do
7171
check_matcher.failure_message(
7272
actual,
7373
'expected that the check would pass'
7474
)
7575
end
7676

77-
failure_message_for_should_not do
77+
failure_message_when_negated do
7878
'expected that the check would not pass'
7979
end
8080

@@ -88,14 +88,14 @@ def failure_message(actual, error_message)
8888
check_matcher.matches?(check)
8989
end
9090

91-
failure_message_for_should do
91+
failure_message do
9292
check_matcher.failure_message(
9393
actual,
9494
'expected that the check would report a warning'
9595
)
9696
end
9797

98-
failure_message_for_should_not do
98+
failure_message_when_negated do
9999
'expected that the check would not report a warning'
100100
end
101101

0 commit comments

Comments
 (0)