Ruby on Rails 4 Rspec, Capybara 看不到按钮



Capybara似乎并没有在我的网页上看到按钮。这是我的测试代码

  before(:each) do
    @inspiring = PostMotivation.create(:title => "This is title",:body => "body main content",:short => "short content of this post",:date => "20.06.2014")
  end
  it "should redirect when you want to add new comment" do
    visit "/inspiring"
    click_button("add_comment")
  end

在这里你可以看到我的观点:

<%= button_to new_main_dupa_path(0,0,@post_to_render3.id), class: "button",id: "add_comment" do %>
        Add new comment!
<% end %>

错误为:

  2) Testing inspiring subpage with integration tests should redirect when you want to add new comment
     Failure/Error: click_button("add_comment")
     Capybara::ElementNotFound:
       Unable to find button "add_comment"
     # ./spec/features/inspiring.rb:39:in `block (2 levels) in <top (required)>'

如何让水豚看到这个按钮?我就是找不到解决这个问题的办法,提前谢谢。

问题解决了,错误当然是我犯的,我忘记了通过访问"/incensive",你正在访问帖子列表,要添加评论,你必须实际访问特定的帖子才能添加任何评论,所以传递代码应该是这样的。

  it "should redirect when you want to add new comment" do
    visit "/inspiring"
    click_link("inspiring_#{@inspiring.id}")
    click_button("add_comment")
  end