0

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)>'

如何让水豚看到这个按钮?我只是找不到解决这个问题的方法,在此先感谢。

4

1 回答 1

0

Problem solved, mistake was of course made by me, I forgot that by visit "/inspiring", you are visiting posts list, and to add comment you have to actually visit particular post to be able to add any comments, so passing code should look like this.

  it "should redirect when you want to add new comment" do
    visit "/inspiring"
    click_link("inspiring_#{@inspiring.id}")
    click_button("add_comment")
  end
于 2014-09-08T08:04:34.663 回答