我在评论视图中有一个链接,用于回复此类评论:
<%= 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
为什么我每次都会收到此错误,而它应该是正确的?
答案 0 :(得分:7)
current_path仅包含路径,不包含URL参数。您可能需要使用current_url来获取整个URL。