diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2020-01-20 11:57:33 +0100 |
---|---|---|
committer | David RodrÃguez <deivid.rodriguez@riseup.net> | 2020-01-20 12:10:51 +0100 |
commit | 477cf41fc11461792fae293f7267081014dfa431 (patch) | |
tree | ede39eee189af24caf23c591f75acf665ee0a6ce /spec/bundler/compact_index_client/updater_spec.rb | |
parent | 482e752e515c701b371d706ed7a1db0ee48f26a0 (diff) | |
download | bundler-477cf41fc11461792fae293f7267081014dfa431.tar.gz |
Fix running updater specs in isolation
In particular,
```
$ bin/rspec ./spec/bundler/compact_index_client/updater_spec.rb:47
Randomized with seed 40401
/home/deivid/.rbenv/versions/2.7.0/lib/ruby/2.7.0/tmpdir.rb:81: warning: method redefined; discarding old mktmpdir
/home/deivid/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/method_double.rb:63: warning: previous definition of mktmpdir was here
F
Retried examples: 0
Failures:
1) Bundler::CompactIndexClient::Updater when bundler doesn't have permissions on Dir.tmpdir Errno::EACCES is raised
Failure/Error:
expect do
updater.update(local_path, remote_path)
end.to raise_error(Bundler::PermissionError)
expected Bundler::PermissionError, got #<RSpec::Mocks::MockExpectationError: #<Double :fetcher> received unexpected message :call with (#<Double :remote_path>, {"Accept-Encoding"=>"gzip"})> with backtrace:
# ./spec/bundler/compact_index_client/updater_spec.rb:51:in `block (4 levels) in <top (required)>'
# ./spec/bundler/compact_index_client/updater_spec.rb:50:in `block (3 levels) in <top (required)>'
# ./spec/spec_helper.rb:109:in `block (3 levels) in <top (required)>'
# ./spec/spec_helper.rb:109:in `block (2 levels) in <top (required)>'
# ./spec/spec_helper.rb:76:in `block (2 levels) in <top (required)>'
# ./spec/support/rubygems_ext.rb:98:in `load'
# ./spec/support/rubygems_ext.rb:98:in `gem_load_and_activate'
# ./spec/support/rubygems_ext.rb:45:in `gem_load'
# ./spec/bundler/compact_index_client/updater_spec.rb:50:in `block (3 levels) in <top (required)>'
# ./spec/spec_helper.rb:109:in `block (3 levels) in <top (required)>'
# ./spec/spec_helper.rb:109:in `block (2 levels) in <top (required)>'
# ./spec/spec_helper.rb:76:in `block (2 levels) in <top (required)>'
# ./spec/support/rubygems_ext.rb:98:in `load'
# ./spec/support/rubygems_ext.rb:98:in `gem_load_and_activate'
# ./spec/support/rubygems_ext.rb:45:in `gem_load'
Finished in 0.24158 seconds (files took 0.21522 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/bundler/compact_index_client/updater_spec.rb:47 # Bundler::CompactIndexClient::Updater when bundler doesn't have permissions on Dir.tmpdir Errno::EACCES is raised
Randomized with seed 40401
```
It's the `Updater#initialize` method that requires `tmpdir` making
`Dir.mktmpdir` available. In the offending spec, first we stub
`Dir.mktmpdir`, and then we initialize the updater, requiring `tmpdir`,
and "undoing the stub". That means the test no longer does what it's
supposed to.
So, my fix is to early instantiate the update, so that by the time we
stub `Dir.mktmpdir`, `tmpdir` has already been required, so the stub is
not reverted.
Diffstat (limited to 'spec/bundler/compact_index_client/updater_spec.rb')
-rw-r--r-- | spec/bundler/compact_index_client/updater_spec.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/spec/bundler/compact_index_client/updater_spec.rb b/spec/bundler/compact_index_client/updater_spec.rb index cbbfba7cb8..1abe7a3213 100644 --- a/spec/bundler/compact_index_client/updater_spec.rb +++ b/spec/bundler/compact_index_client/updater_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Bundler::CompactIndexClient::Updater do let(:local_path) { Pathname("/tmp/localpath") } let(:remote_path) { double(:remote_path) } - subject(:updater) { described_class.new(fetcher) } + let!(:updater) { described_class.new(fetcher) } context "when the ETag header is missing" do # Regression test for https://github.com/rubygems/bundler/issues/5463 |