Created
July 10, 2018 08:51
-
-
Save reggieb/d5fc57f616890cc34875fc0a4dd7db6f to your computer and use it in GitHub Desktop.
Using spys in rspec to mock connections to services
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
# Set up the spy object | |
let(:chargebee_site) { spy(ChargebeeSite) } | |
# Hook it into the work flow | |
before do | |
allow(ChargebeeSite).to receive(:new).and_return(chargebee_site) | |
end | |
# use `have_received` to test connection | |
it 'creates a chargebee coupon' do | |
subject | |
expect(chargebee_site). | |
to have_received(:create_coupon). | |
with( | |
id: customer.coupon, | |
name: customer.coupon, | |
meta_data: { | |
referrer_shopify_customer_id: customer.shopify_id | |
}.to_json | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://relishapp.com/rspec/rspec-mocks/docs/basics/spies