Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Switching Data Sources: Testing Data Equivalence
RSpec.describe ReceiptDataSourceEquivalence do
before(:suite) do
@repository_receipt_data_source ||= Repositories::ReceiptDataSource.new(environment: Rails.env)
@service_receipt_data_source ||= Services::ReceiptDataSource.new(environment: Rails.env)
@local_records = @repository_receipt_data_source.all.collect(&:id)
@api_records = @service_receipt_data_source.all.collect(&:id)
@on_records = Array(@local_records & @api_records)
end
describe "receipts list call" do
it "provides receipts with the same set of ids, each of which have equivalent numbers" do
expect(Set.new(local_records)).to eq(Set.new(api_records))
end
end
describe "receipts detail call" do
it "given an id, provides a receipt with the same attributes from local database or API"
@on_records.each do |id|
local_record = @repository_receipt_data_source.get(id)
api_record = @service_receipt_data_source.get(id)
expect local_record.number.to eq(api_record.number)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment