ruby-on-rails - Cucumber 上的步骤定义在 Ruby on Rails 上找不到路径

标签 ruby-on-rails routes cucumber

使用 Ruby on Rails,我正在编写步骤定义,以便可以运行 Cucumber。但是,我有一个访问页面的通用定义,而 cucumber 找不到我给它的路径:

Can't find mapping from "the Brainstormy home index page" to a path.

这是步骤定义:

Given /^(?:|I )am on (.+)$/ do |page_name|
  visit path_to(page_name)
end

这是场景:

Scenario: Sign up for Brainstormy

Given I am on the Brainstormy home index page
When I fill in "firstName" with "John"
And I fill in "lastName" with "Adams"
And I fill in "email" with "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f2989396939f81b2959f939b9edc919d9f" rel="noreferrer noopener nofollow">[email protected]</a>"
And I fill in "email2" with "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3a9a2a7a2aeb083a4aea2aaafeda0acae" rel="noreferrer noopener nofollow">[email protected]</a>"
And I fill in "password" with "spot1234"
And I fill in "password2" with "spot1234"
And I press "Sign Up"
Then I should be on the profile page

我的路线:

home_index        /home/index(.:format)     home#index
root              /                         home#index

我的路线.rb:

root :to => 'home#index'
resources :ideas
resources :users

#root :to => redirect('/home/index')
match 'home/index' => 'home#index'
match 'users/new' => 'users#new'

问题是,我没有写定义。我从一个正在运行的应用程序中得到它,基本上反射(reflect)了他们所做的事情。有人可以帮我解决这个问题吗?

最佳答案

查看 path_to 方法的内部。这将是从人类可读字符串到 URL 的某种映射。您必须为“Brainstormy home index page” 添加映射才能转到您想要的任何 URL。如果您需要其他帮助,请在帖子中包含 path_to 方法。

关于ruby-on-rails - Cucumber 上的步骤定义在 Ruby on Rails 上找不到路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15857363/

相关文章:

javascript - 在 Angular js 中使用 $stateProvider 进行路由,当尝试使用状态进行路由时,页面未加载

php - Zend Framework - 使用路由和正则表达式设置用户友好的 URL

ruby - 如何使用 Capybara 获取 HTML 表格行

javascript - capybara :Webkit 无法找到 iframe 或其内容

ruby-on-rails - 为什么 REDIS key 总是过期?

java - 带有 Java 库的 JRuby 应用程序需要访问数据库

ruby-on-rails - url_paths - 理解它们的问题

cucumber - Cypress 在 9.3.0 之后停止使用 cucumber 预处理器

javascript - Rails + JQuery : Getting to a sibling div from script

ruby-on-rails - 测试 has_one 关系?