简体   繁体   English

关于current_path对象,Rspec和capybara,visit和get方法之间的区别

[英]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 . before(:each)块之前,将current_path设置为/users/51 ,因此在使用get时它看起来仍然是那样。

I just want to check here: 我只想在这里查看:

  • do visit and current_path come from capybara, whereas get comes from rack? 访问current_path来自水豚,而get来自机架?
  • does the current_path object necessarily require you to use the visit method, in order to keep it updated? current_path对象是否必须要求您使用visit方法,以保持更新?

Your issue is a shared issue and was described in a post by Jose Valim . 你的问题是一个共同的问题,并在Jose Valim的一篇文章中有描述

To be short, in integration tests, only use visit . 简而言之,在集成测试中,只使用visit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM