views:

1548

answers:

3

Hi there.

I'm still new to rails and testing with rspec, so hopefully you can help me.

I have a controller which requires login. I use the restful authentication function of rails.

To create things in tests I'm using the factory framework factorygirl.

Ok the problem is the following:

I want to test a controller (authentication required). So I create a new User with

@user = Factory.create(:user)

After this, I login by using:

login_as @user

And the test:

describe "when handling index" do
  it "should redirect to root" do
    get :index
    response.should redirect_to "/"
  end
end

Executing this I get the following error:

Net::SMTPAuthenticationError in 'MyCoolController when handling index should redirect to root' 535 5.7.8 Error: authentication failed: authentication failure

The error is raised when creating the user with the factory.

When using fixtures everything seems to work. But I only want to use factories.

Yay that's the problem. Thanks a lot for help :)

+1  A: 

This may help: http://afreshcup.com/2008/08/03/double-shot-262/

It says:

If you’re running a Rails app on Debian, and ActionMailer is failing with mysterious “Net::SMTPAuthenticationError: 535 5.7.0 Error: authentication failed: generic failure” errors, check to make sure the saslauthd service is running.

I imagine the same thing applies to your app.

Jeremy Stanley
A: 

I'm running Mac OS X 10.5 (Leopard). I don't think that that's the point, because I can run my app without any errors. It just fails when testing.

A: 

Aha! I finally found it :)

Your answer was absolutely and totally right yap!

After reading the error message more carefully and walking around in my code, I got to the following point:

*MyMailer.stub!(:deliver_signup_notification).and_return(true) MyMailer.stub!(:deliver_activation).and_return(true)*

Now it's working :)