Routes 我没有在测试模式中使用我可以在开发模式中使用的路由

Routes 我没有在测试模式中使用我可以在开发模式中使用的路由,routes,cucumber,capybara,padrino,Routes,Cucumber,Capybara,Padrino,在开发模式下,我可以将浏览器指向,并看到一个json转储文件,其中包含我所有的抓取数据,这表明路由映射和应用程序中的数据操作正在完成它们的工作 在/features/step_definitions/landing_steps.rb中,我有: When /^I visit the (.*) page$/ do |webpage| visit path_to(webpage) end def path_to(webpage) case webpage when 'home'

在开发模式下,我可以将浏览器指向,并看到一个json转储文件,其中包含我所有的抓取数据,这表明路由映射和应用程序中的数据操作正在完成它们的工作

在/features/step_definitions/landing_steps.rb中,我有:

When /^I visit the (.*) page$/ do |webpage|
  visit path_to(webpage)
end
def path_to(webpage)
  case webpage
    when 'home'
      '/'
    when 'data'
      '/data'
  end
end
在/features/support/url.rb中,我有:

When /^I visit the (.*) page$/ do |webpage|
  visit path_to(webpage)
end
def path_to(webpage)
  case webpage
    when 'home'
      '/'
    when 'data'
      '/data'
  end
end
rake路由
给出:

Application: Arewesmallyet
    URL         REQUEST  PATH
    (:index)      GET    /
    (:data)       GET    /data(.:format)
但当我跑步时,我得到:

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'
而capybara-timestamp.html的内容来自“/”。当我在步骤中添加
put path_to(webpage)
时,我会打印正确的路径。但是
current_url
给出了“/”

如果我将步骤更改为:

When /^I visit the (.*) page$/ do |webpage|
  puts path_to(webpage)
  visit path_to(webpage)
  puts 'first:'+current_path
end
(截断的)输出为:

 When I visit the data page  # features/step_definitions/landing_steps.rb:1
  /data
  first:/
我应该如何着手找出这个问题的原因

在使用byebug进行调试时,我发现了一些有趣的东西:

当我告诉Capybara访问“/data”、“/data.json”、“/data.js”、“/”或任何其他路径时,它正在尝试访问。由于所有路径都转换为url,因此url没有路径组件,因此我的应用程序显然提供“/”服务。我不想访问远程URL,这就是我使用“/”和“/数据”路径以及
:rack_test
驱动程序的原因;但是根据在水豚岛的讨论,它完全崩溃了

有什么解决办法吗?或者这颗宝石一文不值


我在上报告了这个问题,我们将看看他们是否愿意修复它。

您可以使用byebug来调试它,然后进入代码查看发生了什么。将byebug添加到Gemfile中的开发、测试组中,并进行捆绑安装。然后在进行访问之前,在步骤定义中添加一个byebug语句

我还想在你的控制器中添加一个byebug语句。基本技术是隔离问题,然后介入调查。在这种情况下,您可能需要进入相当多的水豚和机架代码来解决问题


话虽如此,我怀疑问题出在你的路线上。我猜,与测试时使用的驱动程序相比,浏览器在如何解释路线方面要自由得多。因此,我会尝试将数据路由更改为“data.json”或data.html,看看会发生什么。如果这不起作用,请将routes.rb的内容添加到您的问题中

如果您没有设置app_host,Capybara故意使用example.com,因为如果域不正确,我会重定向,这是不可接受的,因此我必须在我的
features/support/env.rb
文件中设置app host,如下所示:

Capybara.app\u主机=”http://arewesmallyet.dev“