Skip to content

Instantly share code, notes, and snippets.

@carmstrong
Last active August 29, 2015 13:58
Show Gist options
  • Save carmstrong/9938879 to your computer and use it in GitHub Desktop.
Save carmstrong/9938879 to your computer and use it in GitHub Desktop.
RSpec mock test error
# 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