Forum: Ruby on Rails Do tests run independently of each other?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
pergesu (Guest)
on 2005-11-14 14:58
(Received via mailing list)
I'm seeing something really weird...I've got a functional test set up,
and it runs fine.  I add a second one after it...and now the first one
breaks.  Comment out the second one, and the first one runs fine
again.  No, the failed assertion is not happening in the second test,
according to the test output it's definitely a failure in the first
test.  Why would this be happening?  I thought the outcome of one test
shouldn't affect the outcome of another...but clearly this is not the
case.

Here are the two tests.  If I comment out test_signup_bad_password,
test_signup runs fine.  If I include test_signup_bad_password, then
test_signup fails on
assert_equal 1, user.verified
saying "<1> expected but was <0>."

I'm just confused, because I don't think it should work like this...


	def test_signup
		LoginEngine::CONFIG[:use_email_notification] = true
		LoginEngine::CONFIG[:require_validation] = true

		ActionMailer::Base.deliveries = []

		@request.session[:return_to] = "/bogus/location"

		assert_equal 5, User.count
		post :signup, :user => { :login => "newbob", :password =>
"newpassword", :password_confirmation => "newpassword", :email =>
"removed_email_address@domain.invalid" }
		assert_session_has_no :user

		assert_redirect_url(@controller.url_for(:action => "login"))
		assert_equal 1, ActionMailer::Base.deliveries.size
		mail = ActionMailer::Base.deliveries[0]
		assert_equal "removed_email_address@domain.invalid", mail.to_addrs[0].to_s
		assert_match /login:\s+\w+\n/, mail.encoded
		assert_match /password:\s+\w+\n/, mail.encoded
		mail.encoded =~ /key=(.*?)"/
		key = $1

		user = User.find_by_email("removed_email_address@domain.invalid")
		assert_not_nil user
		assert_equal 0, user.verified

		# First past the expiration.
		Time.advance_by_days = 1
		get :home, :user=> { "id" => "#{user.id}" }, "key" => "#{key}"
		Time.advance_by_days = 0
		user = User.find_by_email("removed_email_address@domain.invalid")
		assert_equal 0, user.verified

		# Then a bogus key.
		get :home, :user=> { "id" => "#{user.id}" }, "key" => "boguskey"
		user = User.find_by_email("removed_email_address@domain.invalid")
		assert_equal 0, user.verified

		# Now the real one.
		get :home, :user=> { "id" => "#{user.id}" }, "key" => "#{key}"
		user = User.find_by_email("removed_email_address@domain.invalid")
		assert_equal 1, user.verified  # Fails when signup_bad_password is run

		post :login, :user => { :login => "newbob", :password => "newpassword"
}
		assert_session_has :user
		get :logout
	end

	def test_signup_bad_password
		LoginEngine::CONFIG[:use_email_notification] = true
		LoginEngine::CONFIG[:require_validation] = true

		ActionMailer::Base.deliveries = []

		@request.session[:return_to] = "/bogus/location"
		post :signup, :user => { :login => "newbob", :password => "bad",
:password_confirmation => "bad", :email => 
"removed_email_address@domain.invalid" }
		assert_session_has_no :user
		assert_invalid_column_on_record "user", "password"
		assert_success
		assert_equal 0, ActionMailer::Base.deliveries.size
	end
This topic is locked and can not be replied to.