Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Switching Data Sources: Dual-Class Test
require 'rails_helper'
RSpec.describe ReceiptDataSourceTransition do
describe "get_receipts" do
before do
Receipt.delete_all
end
it "gets similarly structured responses from both repository and service" do
#Subjects Under Test
@repository = Repositories::ReceiptDataSource.new
@service = Services::ReceiptDataSource.new
@data_sources = [@repository, @service]
#Given
FactoryGirl.create(:receipt, number: 11.40)
FactoryGirl.create(:receipt, number: 22.50)
stub_request(:get, "#{ENV['RECEIPT_ENDPOINT']}/receipts.json").
to_return(body: [
{"uuid": "324-asd-423-fsd", "relational_id": 1, "number": 11.40},
{"uuid": "asd-ewr-456-676", "relational_id": 2, "number": 22.50}
].to_json)
#When
@results = @data_sources.map {|ds| ds.get_receipts }
#Then
@results.each do |result|
expect(result).to respond_to(:each)
expect(result.length).to eq(2)
expect(result.first).to respond_to(:number)
end
end
...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment