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

狂风中的少年 提交于 2020-01-19 04:04:25

问题


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:

  • do visit and current_path come from capybara, whereas get comes from rack?
  • does the current_path object necessarily require you to use the visit method, in order to keep it updated?

回答1:


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

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



来源:https://stackoverflow.com/questions/11090038/rspec-and-capybara-difference-between-visit-and-get-methods-with-regards-to-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!