Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Last active July 2, 2018 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelseatroy/76bea8a5e2dbe383277052df77804328 to your computer and use it in GitHub Desktop.
Save chelseatroy/76bea8a5e2dbe383277052df77804328 to your computer and use it in GitHub Desktop.
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