Error comparing current path with capybara and rspec

I have a link in my comment view to respond to such a comment:

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

Some part of the test is as follows:

  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

I get this error:

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

I checked the page with save_and_open_page and the link is correct:

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

I also checked the test.log file and I see this line:

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

Why do I get this error every time, although it should be correct?

+5
source share
1 answer

current_path includes only the path and does not include URL parameters. You will probably need to use current_url to get the whole url.

+6
source

All Articles