Rspec和Capybara,关于current_path对象的访问和获取方法之间的区别 [英] Rspec and capybara, difference between visit and get methods, with regards to the current_path object

查看:49
本文介绍了Rspec和Capybara,关于current_path对象的访问和获取方法之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

第二次测试失败:

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

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

       (compared using ==)

A before(:each)块,将current_path设置为 / users / 51 ,所以在使用 get 时看起来仍然如此。

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

我只是要检查她e:


  • 执行访问 current_path 来自水豚,而来自机架?

  • current_path 对象是否一定需要您使用 visit 方法以保持其更新?

  • 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?

推荐答案

您的问题是共享问题,是在何塞·瓦里姆(Jose Valim)的帖子中描述的

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

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

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

这篇关于Rspec和Capybara,关于current_path对象的访问和获取方法之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆