# One test affects another

**URL:** <https://www.ruby-forum.com/t/one-test-affects-another/129386>\
**Category:** Rails\
**Created:** [February 18, 2008, 3:42am UTC](https://www.ruby-forum.com/t/one-test-affects-another/129386 "2008-02-18T03:42:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dean](https://www.ruby-forum.com/u/dean)\
**Post date:** [February 18, 2008, 3:42am UTC](https://www.ruby-forum.com/t/one-test-affects-another/129386/1 "2008-02-18T03:42:36Z")

</div>

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.

1. 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
