stephenmurdoch
stephenmurdoch

Reputation: 34643

Rspec and capybara, difference between visit and get methods, with regards to the current_path object

I'm possibly confusing rack and capybara methods here

let!(:admin){FactoryGirl.create(:admin)}

# test passes
describe "visiting #edit page" do
  before { visit edit_user_path(admin) }
  specify { current_path.should eq(edit_user_path(admin)) }
end

# test fails
describe "getting #edit page" do
  before { get edit_user_path(admin) }
  specify { current_path.should eq(edit_user_path(admin)) }
end

The second test fails with:

     Failure/Error: specify { current_path.should eq(edit_user_path(admin)) }

       expected: "/users/51/edit"
            got: "/users/51"

       (compared using ==)

A before(:each) block, sets the current_path to /users/51, so it looks like it remains that way when using get.

I just want to check here:

Upvotes: 5

Views: 4838

Answers (1)

apneadiving
apneadiving

Reputation: 115541

Your issue is a shared issue and was described in a post by Jose Valim.

To be short, in integration tests, only use visit.

Upvotes: 7

Related Questions