Elliot
Elliot

Reputation: 13845

Testing signup form with rspec, capybara, and stripe

I'm super new to testing, so I'm not really sure what I should be debugging here.

That said, I have two different user types: Authors and Readers, subclassed on Users.

They can both sign up fine in my app, and the tests for Readers works without any problems.

The signup form for Authors includes a stripe payment form - and makes a remote call to Stripe's API before submitting the form.

Here is what the test looks like:

require 'spec_helper'

feature 'Author sign up' do
  scenario 'author can see signup form' do
    visit root_path
    expect(page).to have_css 'form#new_author'
  end
  scenario 'user signs up and is logged in' do
    visit root_path
    fill_in 'author[email]', :with => '[email protected]'
    fill_in 'author[password]', :with => '123456'
    fill_in 'author[password_confirmation]', :with => '123456'
    fill_in 'author[name]', :with => 'joe shmoe'
    fill_in 'author[zipcode]', :with => '02021'
    fill_in 'card_number', :with => '4242424242424242'
    fill_in 'card_code', :with => '123'
    select "1 - January", :from => 'card_month'
    select "2014", :from => 'card_year'
    find('.author_signup_button').click
    expect(page).to have_css '.author_menu'
  end
end

The only difference between this test and the Reader test are the credit card forms.

The controller which handles this account creation looks like this:

  def create
    @author = Author.new(params[:author])
    if @author.save_with_payment
      sign_in @author, :event => :authentication
      redirect_to root_path, :notice => "Thanks for signing up!"
    else
      render :nothing => true
    end
  end

If I don't have the else in here, the test fails sooner, saying its missing templates. Which means its not passing the "save_with_payment" method, which supports the idea that the form never hits stripe.

The error simply says:

**Failure/Error: expect(page).to have_css '.author_menu'
expected css ".author_menu' to return something**

This worked before I integrated with stripe - so I'm convinced it has to do with the ajax call.

Is there something I should be doing to support ajax?

Upvotes: 3

Views: 2201

Answers (1)

Elliot
Elliot

Reputation: 13845

The answer, was to use :js => true in the test:

scenario 'user signs up and is logged in', :js => true do

This forces the test to run with selenium, and uses the browser.

Upvotes: 4

Related Questions