Rails testing button functionality with capybara.

81 views Asked by At

I have this code, I am trying to click on the button to test its functionality using guard and capybara. I get an undefined method error on guard when I have it written like this. It comes back with no errors if I comment out the click_button line. It should render a response that the import was successful as well which is being displayed by an index page.

require 'rails_helper'
require 'spec_helper'

RSpec.describe "Imports", type: :request do
  it "checks the import page." do
    get '/imports'
    click_button "submit"
  end
end
2

There are 2 answers

0
Pippo On

how long does the it take to load the element? if > 2 seconds (capybara default wait time is 2s) then it's most likely you will get the undefined method error...

Try increasing capybara's timeout or do it for that element only:

click_button "submit", wait: 10

If that doesn't solve your issue then assure "submit" is the correct path to your element...

0
Thomas Walpole On

By default Capybara::DSL is only included in tests of type :feature, are you also including it in type :request?