aaandre
aaandre

Reputation: 2512

Running Capybara without rack produces errors when using url parameters

Here's my setup, based on this recommendation: How to get Cucumber/Capybara/Mechanize to work against external non-rails site

It works until I add parameters to the URL. Any advice on addressing this issue?

require 'rspec'
require 'capybara/rspec'
require 'capybara/dsl'

@test_url = "test"

RSpec.configure do |config|
  config.include Capybara::DSL
end

Capybara.configure do |config|
  config.run_server = false
  config.current_driver = :selenium
  config.app = "fake app name"
  config.app_host = "http://site.com/#{@test_url}"
end

This works fine:

describe "the page, without URL parameters" do
  it "shows the regular form" do
    visit "/registration.aspx"
    page.should have_content "YES"    
  end
end

But this:

describe "the page, when not fully pre-filled" do
  it "shows the regular form if only passed the attendance" do
    visit "/registration.aspx?r=y"
    page.should have_content "YES"    
  end

  it "shows the regular form if only passed the attendance" do
    visit "/registration.aspx?f=Jim"
    page.should have_content "YES"    
  end

end

results in

....FF

Failures:

  1) the page, when not fully pre-filled shows the regular form if only passed the attendance
     Failure/Error: visit "/registration.aspx?r=y"
     NoMethodError:
       undefined method `call' for "fake app name":String
     # ./conf_spec.rb:39:in `block (2 levels) in <top (required)>'

  2) the page, when not fully pre-filled shows the regular form if only passed the attendance
     Failure/Error: visit "/registration.aspx?f=Jim"
     NoMethodError:
       undefined method `call' for "fake app name":String
     # ./conf_spec.rb:44:in `block (2 levels) in <top (required)>'

Upvotes: 7

Views: 17603

Answers (3)

Jason
Jason

Reputation: 195

If you're specifying an app_host instead of using rack, you need to specify default_driver instead of current_driver. For example:

Capybara.run_server = false
Capybara.default_driver = :selenium
Capybara.app_host = 'https://www.google.com'

instead of

Capybara.run_server = false
Capybara.current_driver = :selenium
Capybara.app_host = 'https://www.google.com'

Upvotes: 4

Andrei Botalov
Andrei Botalov

Reputation: 21096

You can set only one of app and app_host. So you should remove config.app from configuration.

Also you should set default_driver instead of current_driver.

As it's shown in my answer in linked question working configuration is:

Capybara.configure do |config|
  config.run_server = false
  config.default_driver = :selenium
  config.app_host = 'https://www.google.com' # change url
end

Upvotes: 18

Peter Alfvin
Peter Alfvin

Reputation: 29389

Assuming you have a non-Rack application and are following the instructions in the second answer which references https://groups.google.com/forum/#!msg/ruby-capybara/9UFnfrc1S-s/TfQO5uBv7gMJ, it seems to me that the hack/workaround is only valid for the simplest of use cases, namely when you're not attempting to pass in parameters to the app. I assume that either Rack or Capybara is attempting to invoke your app to pass the parameters and it's failing because you app is just a String and not a callable object.

Upvotes: 0

Related Questions