0

I'm trying to test a post request with capybara and cucumber. I can't visit a page and press a link to send the request because it has a confirm dialogue and I haven't made it work with javascript so I'm trying to use the post method and then test if it redirects to the appropriated url but I'm getting:

No response yet. Request a page first. (Rack::Test::Error)

My code is:

page.driver.post url
page.driver.status_code.should be 302
follow_redirect!

It's working fine until follow_redirect!. I've tried page.driver.follow_redirects! but it doesn't work either.

Any help?

Bishma Stornelli
  • 2,539
  • 4
  • 22
  • 30

2 Answers2

7
Capybara::Rails::TestCase.class_eval do
  def post(url)
    page.driver.post url
    visit page.driver.response.location
  end
end
grosser
  • 14,707
  • 7
  • 57
  • 61
1

I would recommend you to dismiss the confirm dialogue by using this:

https://stackoverflow.com/a/2609244/560123

That way you wouldn't care about making the post by yourself, and instead trust your application code to do the post request.

Regards

Community
  • 1
  • 1
chischaschos
  • 557
  • 5
  • 13