Skip to content

Commit

Permalink
Prepare for upgrade to rspec 3.0.0.rc1
Browse files Browse the repository at this point in the history
* remove rspec-instafail, it is not compatible
* convert some uses of `should`'s to `expect`

Signed-off-by: John Foley <[email protected]>
  • Loading branch information
Aram Price committed May 30, 2014
1 parent 2db5307 commit 87a23ab
Show file tree
Hide file tree
Showing 55 changed files with 145 additions and 222 deletions.
3 changes: 0 additions & 3 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
--color
--format progress
--profile
--require rspec/instafail
--format RSpec::Instafail
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ group :development, :test do

gem 'rspec', '3.0.0.beta1'
gem 'rspec-its'
gem 'rspec-instafail'

gem 'rubocop', require: false
gem 'parallel_tests'
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,9 @@ GEM
rspec-expectations (3.0.0.beta1)
diff-lcs (>= 1.1.3, < 2.0)
rspec-support (= 3.0.0.beta1)
rspec-instafail (0.2.4)
rspec-its (1.0.0.pre)
rspec-its (1.0.1)
rspec-core (>= 2.99.0.beta1)
rspec-expectations (>= 2.99.0.beta1)
rspec-mocks (3.0.0.beta1)
rspec-support (= 3.0.0.beta1)
rspec-support (3.0.0.beta1)
Expand Down Expand Up @@ -494,7 +495,6 @@ DEPENDENCIES
redis
rest-client
rspec (= 3.0.0.beta1)
rspec-instafail
rspec-its
rubocop
ruby_gntp
Expand Down
3 changes: 0 additions & 3 deletions agent_client/.rspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
--color
--format progress
--profile
--require rspec/instafail
--format RSpec::Instafail
3 changes: 0 additions & 3 deletions bat/.rspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
--color
--format progress
--profile
--require rspec/instafail
--format RSpec::Instafail
4 changes: 2 additions & 2 deletions bat/spec/bat/bosh_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
end

it 'returns the result of Bosh::Exec' do
bosh_exec.stub(sh: bosh_exec_result)
allow(bosh_exec).to receive(sh).and_return(bosh_exec_result)

expect(subject.bosh('FAKE_ARGS')).to eq(bosh_exec_result)
end
Expand Down Expand Up @@ -60,7 +60,7 @@

context 'when a block is passed' do
it 'yields the Bosh::Exec result' do
bosh_exec.stub(sh: bosh_exec_result)
allow(bosh_exec).to receive(sh).and_return(bosh_exec_result)

expect { |b|
subject.bosh('fake arg', &b)
Expand Down
3 changes: 0 additions & 3 deletions blobstore_client/.rspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
--color
--format progress
--profile
--require rspec/instafail
--format RSpec::Instafail
--tag ~s3_credentials
--tag ~nginx
3 changes: 0 additions & 3 deletions bosh-core/.rspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
--color
--format progress
--profile
--require rspec/instafail
--format RSpec::Instafail
3 changes: 0 additions & 3 deletions bosh-dev/.rspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
--color
--format progress
--profile
--require rspec/instafail
--format RSpec::Instafail
3 changes: 0 additions & 3 deletions bosh-director-core/.rspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
--color
--format progress
--profile
--require rspec/instafail
--format RSpec::Instafail
3 changes: 0 additions & 3 deletions bosh-director/.rspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
--color
--format progress
--profile
--require rspec/instafail
--format RSpec::Instafail
4 changes: 2 additions & 2 deletions bosh-director/spec/unit/deployment_plan/assembler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,14 @@ module DeploymentPlan
deployment_plan.stub(:network).with('bar').and_return(bar_network)

foo_reservation = nil
foo_network.should_receive(:reserve).and_return do |reservation|
foo_network.should_receive(:reserve) do |reservation|
reservation.ip.should == NetAddr::CIDR.create('1.2.3.4').to_i
reservation.reserved = true
foo_reservation = reservation
true
end

bar_network.should_receive(:reserve).and_return do |reservation|
bar_network.should_receive(:reserve) do |reservation|
reservation.ip.should == NetAddr::CIDR.create('10.20.30.40').to_i
reservation.reserved = false
false
Expand Down
3 changes: 1 addition & 2 deletions bosh-director/spec/unit/deployment_plan/dns_binder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ module Bosh::Director

it "should create the domain if it doesn't exist" do
domain = nil
deployment.should_receive(:dns_domain=).
and_return { |*args| domain = args.first }
deployment.should_receive(:dns_domain=) { |*args| domain = args.first }
subject.bind_deployment

Models::Dns::Domain.count.should == 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@

it 'enqueues all given jobs to run in parallel' do
enqueued = []
expect(thread_pool).to receive(:process).twice.and_return { |&blk| enqueued << blk }
expect(thread_pool).to receive(:process).twice { |&blk| enqueued << blk }

expect(thread_pool).to receive(:wrap).and_return do |&blk|
expect(thread_pool).to receive(:wrap) do |&blk|
blk.call(thread_pool)
# all jobs were enqueued by the time wrap block executes
expect(enqueued.size).to eq(2)
Expand Down
2 changes: 1 addition & 1 deletion bosh-director/spec/unit/jobs/update_release_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def create_package(files)
it 'should create a proper template and upload job bits to blobstore' do
File.open(@tarball, 'w') { |f| f.write(@job_bits) }

blobstore.should_receive(:create).and_return do |f|
blobstore.should_receive(:create) do |f|
f.rewind
Digest::SHA1.hexdigest(f.read).should == Digest::SHA1.hexdigest(@job_bits)

Expand Down
6 changes: 3 additions & 3 deletions bosh-director/spec/unit/jobs/update_stemcell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
end

it "should upload a local stemcell" do
@cloud.should_receive(:create_stemcell).with(anything(), {"ram" => "2gb"}).and_return do |image, _|
@cloud.should_receive(:create_stemcell).with(anything(), {"ram" => "2gb"}) do|image, _|
contents = File.open(image) { |f| f.read }
contents.should eql("image contents")
"stemcell-cid"
Expand All @@ -45,7 +45,7 @@
end

it "should upload a remote stemcell" do
@cloud.should_receive(:create_stemcell).with(anything(), {"ram" => "2gb"}).and_return do |image, _|
@cloud.should_receive(:create_stemcell).with(anything(), {"ram" => "2gb"}) do|image, _|
contents = File.open(image) { |f| f.read }
contents.should eql("image contents")
"stemcell-cid"
Expand All @@ -62,7 +62,7 @@
end

it "should cleanup the stemcell file" do
@cloud.should_receive(:create_stemcell).with(anything(), {"ram" => "2gb"}).and_return do |image, _|
@cloud.should_receive(:create_stemcell).with(anything(), {"ram" => "2gb"}) do|image, _|
contents = File.open(image) { |f| f.read }
contents.should eql("image contents")
"stemcell-cid"
Expand Down
20 changes: 9 additions & 11 deletions bosh-director/spec/unit/lock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Bosh::Director
started = Time.now.to_f

stored_value = nil
redis.should_receive(:setnx).with('foo', anything).and_return do |_, value|
redis.should_receive(:setnx).with('foo', anything) do |_, value|
stored_value = value
timestamp = stored_value.split(':')[0].to_f
timestamp.should be_within(2.0).of(started + 10)
Expand All @@ -20,15 +20,15 @@ module Bosh::Director
redis.stub(:watch).with('foo')
redis.stub(:multi).and_yield

redis.stub(:get).with('foo').and_return do
redis.stub(:get).with('foo') do
stored_value
end

redis.stub(:set).with('foo', anything()) do |_, value|
stored_value = value
end

redis.should_receive(:del).with('foo').and_return do
redis.should_receive(:del).with('foo') do
stored_value = nil
nil
end
Expand All @@ -48,8 +48,7 @@ module Bosh::Director
Config.stub(:redis).and_return(redis)

stored_value = nil
redis.stub(:setnx).with('foo', anything).
and_return do |_, value|
redis.stub(:setnx).with('foo', anything) do |_, value|
timestamp = value.split(':')[0].to_f
timestamp.should be_within(2.0).of(Time.now.to_f + 10)
if stored_value.nil?
Expand All @@ -63,13 +62,13 @@ module Bosh::Director
redis.stub(:watch).with('foo')
redis.stub(:multi).and_yield

redis.stub(:get).with('foo').and_return { stored_value }
redis.stub(:get).with('foo') { stored_value }

redis.should_receive(:set).with('foo', anything()) do |_, value|
stored_value = value
end

redis.should_receive(:del).with('foo').and_return do
redis.should_receive(:del).with('foo') do
stored_value = nil
nil
end
Expand All @@ -91,8 +90,7 @@ module Bosh::Director
Config.stub(:redis).and_return(redis)

stored_value = nil
redis.stub(:setnx).with('foo', anything).
and_return do |_, value|
redis.stub(:setnx).with('foo', anything) do |_, value|
timestamp = value.split(':')[0].to_f
timestamp.should be_within(2.0).of(Time.now.to_f + 10)
if stored_value.nil?
Expand All @@ -106,11 +104,11 @@ module Bosh::Director
redis.stub(:watch).with('foo')
redis.stub(:multi).and_yield

redis.stub(:get).with('foo').and_return do
redis.stub(:get).with('foo') do
stored_value
end

redis.should_receive(:del).with('foo').and_return do
redis.should_receive(:del).with('foo') do
stored_value = nil
nil
end
Expand Down
13 changes: 5 additions & 8 deletions bosh-director/spec/unit/nats_rpc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@

it "should fire callback when message is received" do
subscribe_callback = nil
@nats.should_receive(:subscribe).with("director.123.>").
and_return do |&block|
@nats.should_receive(:subscribe).with("director.123.>") do |&block|
subscribe_callback = block
end
@nats.should_receive(:publish).and_return do
@nats.should_receive(:publish) do
subscribe_callback.call("", nil, "director.123.req1")
end

Expand All @@ -53,11 +52,10 @@

it "should fire once even if two messages were received" do
subscribe_callback = nil
@nats.should_receive(:subscribe).with("director.123.>").
and_return do |&block|
@nats.should_receive(:subscribe).with("director.123.>") do |&block|
subscribe_callback = block
end
@nats.should_receive(:publish).and_return do
@nats.should_receive(:publish) do
subscribe_callback.call("", nil, "director.123.req1")
subscribe_callback.call("", nil, "director.123.req1")
end
Expand All @@ -79,8 +77,7 @@

it "should not fire after cancel was called" do
subscribe_callback = nil
@nats.should_receive(:subscribe).with("director.123.>").
and_return do |&block|
@nats.should_receive(:subscribe).with("director.123.>") do |&block|
subscribe_callback = block
end
@nats.should_receive(:publish)
Expand Down
2 changes: 1 addition & 1 deletion bosh-director/spec/unit/problem_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def inactive_disk(id, deployment_id = nil)
job2 = make_job(@deployment)

messages = []
job2.should_receive(:track_and_log).exactly(3).times.and_return { |message| messages << message }
job2.should_receive(:track_and_log).exactly(3).times { |message| messages << message }
job2.apply_resolutions({
problems[0].id.to_s => 'ignore',
problems[1].id.to_s => 'ignore',
Expand Down
2 changes: 1 addition & 1 deletion bosh-director/spec/unit/resource_pool_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module Bosh::Director
unbound_vm.stub(:bound_instance).and_return(nil)

called = false
resource_pool_updater.should_receive(:create_missing_vms).and_return do |&block|
resource_pool_updater.should_receive(:create_missing_vms) do |&block|
called = true
block.call(bound_vm).should == true
block.call(unbound_vm).should == false
Expand Down
3 changes: 0 additions & 3 deletions bosh-monitor/.rspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
--color
--format progress
--profile
--require rspec/instafail
--format RSpec::Instafail
4 changes: 0 additions & 4 deletions bosh-monitor/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,3 @@ def make_heartbeat(attrs = {})
}
Bhm::Events::Heartbeat.new(defaults.merge(attrs))
end

RSpec.configure do |c|
c.color_enabled = true
end
3 changes: 0 additions & 3 deletions bosh-registry/.rspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
--color
--format progress
--profile
--require rspec/instafail
--format RSpec::Instafail
3 changes: 0 additions & 3 deletions bosh-release/.rspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
--color
--format progress
--profile
--require rspec/instafail
--format RSpec::Instafail
3 changes: 0 additions & 3 deletions bosh-stemcell/.rspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
--color
--format progress
--profile
--require rspec/instafail
--format RSpec::Instafail
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ module SpecInfra::Backend

describe '#run_command' do
context 'when #chroot_dir is NOT set' do
before { exec.stub(chroot_dir: nil) }
before { allow(exec).to receive(:chroot_dir).and_return(nil) }

it 'runs the provided command as expected' do
exec.should_receive(:`).with('echo "FOO" 2>&1')
expect(exec).to receive(:`).with('echo "FOO" 2>&1')
exec.run_command('echo "FOO"')
end
end

context 'when #chroot_dir is set' do
before { exec.stub(chroot_dir: '/path/to/chroot') }
before { allow(exec).to receive(:chroot_dir).and_return('/path/to/chroot') }

it 'runs the provided command within the chroot' do
chroot_command = %Q{
sudo chroot /path/to/chroot /bin/bash <<CHROOT_CMD
echo "FOO" 2>&1; echo EXIT_CODE=\\$?
CHROOT_CMD
2>&1}
exec.should_receive(:`).with(chroot_command).and_return("FOO\nEXIT_CODE=0\n")
expect(exec).to receive(:`).with(chroot_command).and_return("FOO\nEXIT_CODE=0\n")
exec.run_command('echo "FOO"')
end

it 'extracts the exit code returned from within the chroot into an Integer' do
exec.stub(:` => "ATTENTION\nDO NOT CARE\nEXIT_CODE=8675309\n")
allow(exec).to receive(:`).and_return("ATTENTION\nDO NOT CARE\nEXIT_CODE=8675309\n")
result = exec.run_command('do_not_care')
expect(result[:exit_status]).to eq(867_5309)
end
Expand Down
8 changes: 4 additions & 4 deletions bosh-stemcell/spec/bosh/stemcell/archive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ module Bosh::Stemcell

describe '#extract' do
it 'extracts stemcell' do
Rake::FileUtilsExt.should_receive(:sh).with(
/tar xzf .*#{stemcell_path} --directory/)
expect(Rake::FileUtilsExt).to receive(:sh).with(/tar xzf .*#{stemcell_path} --directory/)

subject.extract {}
end

it 'extracts stemcell and excludes files' do
Rake::FileUtilsExt.should_receive(:sh).with(
/tar xzf .*#{stemcell_path} --directory .* --exclude=image/)
expect(Rake::FileUtilsExt).to receive(:sh).with(/tar xzf .*#{stemcell_path} --directory .* --exclude=image/)

subject.extract(exclude: 'image') {}
end
end
Expand Down
Loading

0 comments on commit 87a23ab

Please sign in to comment.