Created
April 16, 2013 17:20
-
-
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?
This file contains 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
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 |
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.
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
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?