-
-
Save rick/fd69ced87a2c73b37428 to your computer and use it in GitHub Desktop.
intermittent test failure helper
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
context "Creating an org with a coupon" do | |
setup do | |
@user = User.make :plan => "micro" | |
@coupon = Coupon.make(:code => "50off", | |
:discount => 0.5, | |
:limit => 50) | |
@org = Organization.make_unsaved(:random, :plan => 'bronze') | |
end | |
test "works if the coupon is valid" do | |
@org.coupon = @coupon.code | |
fails_intermittently("https://github.com/my/repo/issues/5432", | |
"@org" => @org, | |
"@coupon" => @coupon, | |
"@org.valid?" => @org.valid?, | |
"@org.errors" => @org.errors) do | |
assert @org.save | |
end | |
assert_equal 12.5, @org.payment_amount | |
end | |
end | |
end |
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
# Public: provide debugging information for tests which are known to fail intermittently | |
# | |
# issue_link - url of GitHub issue documenting this intermittent test failure | |
# args - Hash of debugging information (names => values) to output on a failure | |
# block - block which intermittently fails | |
# | |
# Example | |
# | |
# fails_intermittently('https://github.com/my/repo/issues/1234', | |
# '@repo' => @repo, 'shas' => shas, 'expected' => expected) do | |
# assert_equal expected, shas | |
# end | |
# | |
# Re-raises any MiniTest::Assertion from a failing test assertion in the block. | |
# | |
# Returns the value of the yielded block when no test assertion fails. | |
def fails_intermittently(issue_link, args = {}, &block) | |
raise ArgumentError, "provide a GitHub issue link" unless issue_link | |
raise ArguemntError, "a block is required" unless block_given? | |
yield | |
rescue MiniTest::Assertion => boom # we have a test failure! | |
STDERR.puts "\n\nIntermittent test failure! See: #{issue_link}" | |
if args.empty? | |
STDERR.puts "No further debugging information available." | |
else | |
STDERR.puts "Debugging information:\n" | |
args.keys.sort.each do |key| | |
STDERR.puts "#{key} => #{args[key].inspect}" | |
end | |
end | |
raise boom | |
end |
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
Intermittent test failure! See: https://github.com/github/github/issues/25266 | |
Debugging information: | |
@coupon => #<Coupon id: 1111, code: "x0x0x0x0", plan: nil, discount: 0.5, duration: 30, limit: 1, group: "internal", expires_at: "2015-06-26 10:07:17", note: "Test coupon"> | |
@org => #<Organization: any > | |
@org.errors => #<ActiveRecord::Errors:0x007f9ad924bd98 @base=#<Organization: any >, @errors={"login"=>[#<ActiveRecord::Error:0x007f9ad943f6b8 @base=#<Organization: any >, @attribute=:login, @type="is a reserved word", @options={}, @message="is a reserved word">]}> | |
@org.valid? => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment