2012-09-02 27 views
5

我有我的意見觀點的鏈接回覆到像這樣的評論:錯誤電流通路與水豚和RSpec比較

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

我查了一下頁面保存_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 

爲什麼我一次比一次這個錯誤,而應該是正確的嗎?

回答

6

current_path只包含路徑並且不包含URL參數。您可能需要使用current_url來獲取整個URL。

+0

謝謝:)我不得不改變所有路徑到網址。 – ArashM