Rails 路由无法使用黄瓜进行测试

Rails route not working using cucumber to test

[你好,这是我关于 Whosebug 的第一个问题,所以请耐心等待,我会尽量提供尽可能详细的信息。我是编码新手,目前正在开发 rails 应用程序,我正在构建一个讨论区。到目前为止,我已经建立了我的用户模型和讨论模型,其中讨论 belongs_to 用户和用户 has_many 讨论。我的测试在第 10 行失败,新讨论的 link 似乎设置为正确的路线,当我窥探它时,它在第 15 行显示正确的 path.Then 当前路径在索引页上...所以我不确定我的测试是否写得不好或者我是否遗漏了什么。我希望这连同屏幕截图是足够的信息......我真的花了一天时间在这上面,我已经无能为力了......非常感谢任何帮助谢谢。

error message rails routes

我的测试*

# A user starts a new discussion
Given("they click on the discussion link") do
click_link 'DISCUSSIONS'
end

Then("they will be redirected to the discussions index page") do
expect(current_path).to eq(user_discussions_path(@user.id))
end

   When("they click on the new discussion link") do
   click_link 'New Discussion'
   end

  Then("they will be redirected to the new discussion page") do
  expect(current_path).to eq(new_user_discussion_path(@user.id))
  end

讨论索引页*

<div class="container">
  <div class="grid">
   <%= render 'discussions_navbar' %>
   <%= link_to "New Discussion", new_user_discussion_path %>
  </div>
</div>

绑定 Pry on current_path 来自测试*

[1] pry(#<Cucumber::Rails::World>)> current_path
=> "/users/1715/discussions"
[2] pry(#<Cucumber::Rails::World>)> new_user_discussion_path(@user.id)
=> "/users/1715/discussions/new"
[3] pry(#<Cucumber::Rails::World>)> expect(current_path).to 
eq(new_user_discussion_path(@user.id))
RSpec::Expectations::ExpectationNotMetError:
expected: "/users/1715/discussions/new"
got: "/users/1715/discussions"

对新讨论的捆绑撬动 Link*

[1] pry(#<#<Class:0x007fd3a62cf660>>)> new_user_discussion_path
=> "/users/1722/discussions/new"

错误信息*

When they click on the new discussion link                 # features/step_definitions/discussion_steps.rb:10
      undefined method `discussions_path' for #<#<Class:0x007fd3a62cf660>:0x007fd3a6681740> (ActionView::Template::Error)
      ./app/views/discussions/_form.html.erb:1:in `_app_views_discussions__form_html_erb__787511772381390310_70273503263920'
      ./app/views/discussions/new.html.erb:4:in `_app_views_discussions_new_html_erb___371545055918840709_70273503334040'
      ./features/step_definitions/discussion_steps.rb:11:in `"they click on the new discussion link"'
      features/discussion.feature:10:in `When they click on the new discussion link'

新讨论表格*

<%= simple_form_for @discussion do |d| %>
  <%= d.input :title, label: "Discussion Title" %>
  <%= d.input :description %>
  <%= d.button :submit %>
<% end %>

路线*

user_discussions GET /users/:user_id/discussions(.:format) 讨论#index

POST /users/:user_id/discussions(.:format) discussions#create new_user_discussion GET /users/:user_id/discussions/new(.:format) 讨论#new

尝试:

<%= simple_form_for [current_user, @discussion] do |d| %>