I have the following class:
class Brewer < ActiveRecord::Base
class EmailNotFound < StandardError; end
class << self
def find_by_email(*args)
b = super(*args)
raise EmailNotFound if b.nil?
return b
end
end
end
And the following two tests:
require File.dirname(FILE) + ‘/…/test_helper’
class BrewerTest < Test::Unit::TestCase
fixtures :brewers
def test_should_find_brewer_with_valid_email
assert_equal brewers(:active_brewer),
Brewer.find_by_email(brewers(:active_brewer).email)
end
def test_should_raise_email_not_found_exception_with_invalid_email
assert_raises Brewer::EmailNotFound do
Brewer.find_by_email(‘NotAnEmail’)
end
end
end
The tests fail like this:
Loaded suite test/unit/brewer_test
Started
.F
Finished in 0.428367 seconds.
- Failure:
test_should_raise_email_not_found_exception_with_invalid_email(BrewerTest)
[test/unit/brewer_test.rb:207]:
Brewer::EmailNotFound exception expected but none was thrown.
2 tests, 2 assertions, 1 failures, 0 errors
If I comment out test_should_find_brewer_with_valid_email, the other
test passes.
What’s going on here?
Regards,
–Dean