0

In development mode, I can point my browser at http://arewesmallyet.dev/data and I see a json dump of all of my scraped data, indicating that the route mapping, and the data action in the application are doing their job.

In /features/step_definitions/landing_steps.rb I have:

When /^I visit the (.*) page$/ do |webpage|
  visit path_to(webpage)
end

In /features/support/url.rb I have:

def path_to(webpage)
  case webpage
    when 'home'
      '/'
    when 'data'
      '/data'
  end
end

and rake routes gives:

Application: Arewesmallyet
    URL         REQUEST  PATH
    (:index)      GET    /
    (:data)       GET    /data(.:format)

But when I run cucumber, I get:

Scenario: data page                     # features/landing.feature:10
  Given records exist in the database   # features/step_definitions/landing_steps.rb:9
  When I visit the data page            # features/step_definitions/landing_steps.rb:1
File saved to ~/Developer/Ruby/arewesmallyet/capybara-timestamp.html.
Please install the launchy gem to open the file automatically.
  Then I should be served the json data # features/step_definitions/landing_steps.rb:15
    proper content missing (Minitest::Assertion)
    features/landing.feature:13:in `Then I should be served the json data'

and capybara-timestamp.html has the content from '/'. When I add puts path_to(webpage) to the step, I get the correct paths printed. But current_url gives '/'.

Infact if I change the step to:

When /^I visit the (.*) page$/ do |webpage|
  puts path_to(webpage)
  visit path_to(webpage)
  puts 'first:'+current_path
end

the (truncated) output is:

 When I visit the data page  # features/step_definitions/landing_steps.rb:1
  /data
  first:/

How should I go about finding the cause of this problem?

Something interesting I found while debugging with byebug:

Capybara is trying to visit http://www.example.com when I tell it to visit '/data', '/data.json', '/data.js', '/', or any other path. Since all paths get turned into http://www.example.com there is no path component to the url so my app obviously serves '/'. I do NOT want to access a remote URL, which is why I use the '/' and '/data' paths, and the :rack_test driver; but based on the discussion at https://groups.google.com/forum/#!topic/ruby-capybara/HMKCIDJAA6w capybara is just completely broken?

Is there any workaround or is this gem just worthless?

I reported the issue at https://groups.google.com/forum/#!topic/ruby-capybara/SaB81spfil8, we'll see if they bother to fix it.

Camden Narzt
  • 2,271
  • 1
  • 23
  • 42

2 Answers2

0

You can use byebug, to debug this, and step into the code to see what is happening. Add byebug to the development,test group in you Gemfile and do a bundle install. Then put a byebug statement in your step definition before you do the visit.

I'd also but a byebug statement in your controller. The basic technique is to isolate the problem, and then step in to investigate. In this case you might have to step into quite alot of capybara and rack code to get to the problem.

Having said that, I suspect that the problem is your route. I'm guessing that a browser is much more liberal with how it inteprets routes, compared to the driver you are using when testing. So I would try changing the data route to 'data.json', or data.html, and see what happens. If that doesn't work, add the contents of routes.rb to your question

diabolist
  • 3,990
  • 1
  • 11
  • 15
0

Capybara deliberately uses example.com if you don't set app_host, and since I redirect if the domain is incorrect, that's unacceptable so I have to set app host in my features/support/env.rb file like so:

Capybara.app_host = 'http://arewesmallyet.dev'

Camden Narzt
  • 2,271
  • 1
  • 23
  • 42