6

我的评论视图中有一个链接,用于回复这样的评论:

<%= link_to t('.reply', :default => t("helpers.links.reply")), new_story_comment_path(comment.story, parent_id: comment)%>

测试的某些部分是这样的:

  it "replies to a comment" do
    comment = FactoryGirl.create :comment, story_id: story.id, user_id: user.id
    visit story_path story
    save_and_open_page
    click_link "reply"
    current_path.should eq(new_story_comment_path story.id, parent_id: comment.id)
    ...
  end

我收到此错误:

  1) Comments replies to a comment
     Failure/Error: current_path.should eq(new_story_comment_path story.id, parent_id: comment.id)

       expected: "/stories/1/comments/new?parent_id=1"
            got: "/stories/1/comments/new"

       (compared using ==)
     # ./spec/requests/comments_spec.rb:23:in `block (2 levels) in <top (required)>'

我用 save_and_open_page 检查了页面,链接是正确的:

file:///stories/1/comments/new?parent_id=1

我还检查了 test.log 文件,我可以看到这一行:

Started GET "/stories/1/comments/new?parent_id=1" for 127.0.0.1 at 2012-09-02 21:05:57

为什么我每次都会收到这个错误,而它应该是正确的?

4

1 回答 1

7

current_path 只包含路径,不包含 URL 参数。您可能需要使用 current_url 来获取整个 URL。

于 2012-09-02T16:42:37.993 回答