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

我可能在这里混淆机架和水豚方法

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 

第二次测试失败了:

  Failure/Error: specify { current_path.should eq(edit_user_path(admin)) } expected: "/users/51/edit" got: "/users/51" (compared using ==) 

before(:each)块之前,将current_path设置为/users/51 ,因此在使用get时它看起来仍然是那样。

我只想在这里查看:

  • 访问current_path来自水豚,而来自机架?
  • current_path对象是否必须要求您使用visit方法,以保持更新?

你的问题是一个共同的问题, 在Jose Valim的一篇文章中有描述 。

简而言之,在集成测试中,只使用visit