Question

So I'm trying to write some integration tests for this app I'm working on and one of the tests I have written when run follows through the steps and lands on the error page, while performing the exact same steps manually lands on the correct page. Here is the test:

describe 'sign up page' do
    it 'signs a user up when valid information is entered and displays success message' do
        sign_up_with('John Doe', 'user11@gmail.com', 'a8wsk389nd9w02kdncui20dkc')
        current_path.should == root_path
        page.should have_content('Email sent with password set instructions')
    end
    ...
    def sign_up_with(name, email, registration)
        visit('/signup')
        fill_in 'Full Name', with: name
        fill_in 'Email Address', with: email
        fill_in 'Email Address Confirmation', with: email
        fill_in 'Registration Code', with: registration
        click_button('Create Java user')
    end
end

When I run this test it doesn't throw any errors at me, but the route goes to /java_users which is where the page goes if it fails, instead of / like it is supposed to. If I perform these same steps manually with the same data, it works perfectly. I honestly have no idea what is going wrong or what I have done wrong. I'm really new to Capybara (and RoR for that matter) so it could be something really simple. The only thing I can thing of is that because ActionMailer is called to send an email that's throwing it off somehow. Any help would be appreciated.

Updates:

Although I don't receive any errors when running the test (other than the test failing), I installed the launchy gem and tried save_and_open_page. It took me to a page with a wall of text. Here is a snippet:

ArgumentError at /java_users ============================ > Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true app/views/support_mailer/password_set.text.erb, line 3 ------------------------------------------------------ ``` ruby 1 In order to set your password, please click the URL below. 2 > 3 <%= password_set_url(@user.password_reset_token) %> 4 5 If you did not purchase a *******, just ignore this email.``` App backtrace ------------- - app/views/support_mailer/password_set.text.erb:3:in `_app_views_support_mailer_password_set_text_erb___10448386_70208856' - app/mailers/support_mailer.rb:250:in `password_set' - app/models/user.rb:65:in `send_password_set' - app/controllers/java_users_controller.rb:60:in `create' - spec/features/sign_up_spec.rb:28:in `sign_up_with' - spec/features/sign_up_spec.rb:5:in `block (2 levels) in...

Also here is the create function in the controller:

def create
    @java_user = JavaUser.new(user_params)
    registration = RegistrationCode.find_by_code(params[:registration_code])
    email = params[:java_user][:email]
    email_confirmation = params[:email_confirmation]
    user = User.find_by_email(email)

    if validateInput(registration, email, email_confirmation, user)
      @java_user.rails_uuid = user.id

      if @java_user.save
        registration.user_id = @java_user.id
        registration.save

        if user
          user.send_password_set
          redirect_to root_url, notice: "Email sent with password reset instructions"
        else
          render :new
        end
      else
        render :new
      end
    else
     render :new
    end
end
Was it helpful?

Solution

I seem to have solved it. I was missing the following in my test.rb file in /config/environments

config.action_mailer.default_url_options = { :host => "localhost:3000" }

I had it in development.rb, but not in test.rb.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top