Skip to content

Instantly share code, notes, and snippets.

@genericsteele
Last active August 29, 2015 13:58
Show Gist options
  • Save genericsteele/10415655 to your computer and use it in GitHub Desktop.
Save genericsteele/10415655 to your computer and use it in GitHub Desktop.
Use relative paths in failed assertions

Monkey patch Minitest::Assertion#location...

## in test/test_helper.rb
class Minitest::Assertion
  alias_method :old_location, :location
  def location
    old_location.sub("#{Rails.root.to_s}/", '')
  end
end

...to dump the relative path on failure...

  2) Failure:
ExampleTest#test_for_failure [test/models/example_test.rb:9]:
Expected: true
  Actual: false

...instead of the full path.

  2) Failure:
ExampleTest#test_for_failure [/Users/eric/Projects/obscenely_long_example_app_name/test/models/example_test.rb:9]:
Expected: true
  Actual: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment