Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
535 views
in Technique[技术] by (71.8m points)

ruby on rails - 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:

  • 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?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...