Last active
August 29, 2015 13:58
-
-
Save carmstrong/9938879 to your computer and use it in GitHub Desktop.
RSpec mock test error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config | |
RSpec.configure do |config| | |
config.before(:each) do | |
etcd = double | |
require 'etcd' | |
Etcd.client.stub(:new).and_return(etcd) | |
allow(etcd).to receive(:get).and_raise(Net::HTTPFatalError) | |
end | |
end | |
# Code | |
require 'etcd' | |
ruby_block 'etcd-stuff' do | |
block do | |
client = Etcd.client(host: 'some.host', port: 1234) | |
client.set('/foo/bar', 'someval') | |
end | |
not_if do | |
begin | |
client = Etcd.client(host: 'some.host', port: 1234) | |
client.get('/foo/bar') | |
true | |
rescue Net::HTTPServerException, Net::HTTPFatalError | |
false | |
end | |
end | |
end | |
# Test | |
it 'does etcd stuff' do | |
expect(chef_run).to run_ruby_block('etcd-stuff') | |
end | |
# Error | |
# Each test produces this: | |
ArgumentError: | |
wrong number of arguments (0 for 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment