Skip to content

Instantly share code, notes, and snippets.

@mmmries
Created April 16, 2013 17:20
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 mmmries/5397748 to your computer and use it in GitHub Desktop.
Save mmmries/5397748 to your computer and use it in GitHub Desktop.
How can a get good error messages about which parameters I was using when the test failed?
require 'spec_helper'
describe MerchantAccount do
it "can find an appropriate merchant" do
{
'GND130415A' => 'GRAZ_1',
'MIS130417A' => 'GRAZ_2',
'ROA130417A' => 'GRAZ_2',
'LON130417A' => 'GRAZ_3',
}.each do |tour_code, expected_merchant_account_descriptor|
event = Event.find_by_name(tour_code)
ma = MerchantAccount.find_by_event_and_product(event, nil)
ma.descriptor.should == expected_merchant_account_descriptor
end
end
end
@mmmries
Copy link
Author

mmmries commented Apr 16, 2013

Given a hash of known things I want to test against, and their expected outcomes how do I get this test to give me failure messages that include what parameters caused the failure?

Is this just a terrible way to write tests?

@localshred
Copy link

Meaning you want it to say something like "GND130415A doesn't match GRAZ_1, got FOO instead" or something?

The best (only?) way is to write a custom matcher. You end up specifying your own error strings on failures.

@blowmage
Copy link

assert_equal expected_merchant_account_descriptor, ma.descriptor, "#{tour_code} doesn't match #{expected_merchant_account_descriptor}, got #{ma.descriptor} instead"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment