Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error in comparing current path with capybara and rspec

I have a link in my comments view for replying to a comment like this:

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

Some part of the test is like this:

  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 can 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 i get this error each time, while it should be correct?

like image 487
ArashM Avatar asked Sep 02 '12 16:09

ArashM


1 Answers

current_path only includes the path and does not include the URL parameters. You will likely need to use current_url to get the entire URL.

like image 131
Peter Brown Avatar answered Oct 31 '22 21:10

Peter Brown