Using capybara to Validate Redirect Destination Pages

Asked 2 years ago, Updated 2 years ago, 110 views

I use capybara to write feature specifications.

class UserController <ApplicationController
  def index
    redirect_to new_user_path
  end

  def new
    # something
  end
end

If there is a controller called

 feature "sample features",:type=>:feature do
      scenario "Transition to new user creation screen" do
        visit users_path
        expect(current_path).to eq new_user_path
      end
    end

As mentioned above, I would like to verify that you have been redirected to the redirect destination page after some event. Is there any way?

ruby-on-rails rspec

2022-09-30 21:12

1 Answers

I think you can write an example like the following.
If you click on visit as you like, you can change it to a method that moves you.

 feature "sample features",:type=>:feature do
  scenario "Transition to new user creation screen" do
   visit users_path
   expect {visit new_user_path}.to change {
     current_path
   }.from(users_path).to(users_path)
  end
end


2022-09-30 21:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.