Question: Rspec and Capybara , what is the difference between visit and get

Question

Rspec and Capybara , what is the difference between visit and get

Answers 1
Added at 2016-12-27 14:12
Tags
Question

My spec/controllers/undertakings_controller_spec.rb is below.

 RSpec.describe UndertakingsController, type: :controller do
     describe 'redirect with home due to login user' do
      subject {current_path}
      it 'can get with authenticate undertaking user' do
        login_user @undertaking.user
         #get :show , id: @undertaking
         visit undertaking_path(@undertaking)
         expect(response).to redirect_to root_path
      end
    end
end

This has error (Expected response to be a , but was <200>). But when I change ( visit undertaking_path(@undertaking) ) to ( get :show , id: @undertaking ) , this does not have the error. What is the difference between visit and get? I read

Rspec and capybara, difference between visit and get methods, with regards to the current_path object

but I can't understand the error in this case. Please help me.

Anyway, My controllers/undertakings_controller.rb is below.

      class UndertakingsController < ApplicationController
         before_action :undertaking_not_have_comment , only: [:show]
         def show
           @undertaking=Undertaking.find(params[:id])
           @asking=@undertaking.asking
           @comment=Comment.new do |c|
            c.user=current_user
           end
         end

         private
         def undertaking_not_have_comment
             @undertaking=Undertaking.find(params[:id])
             if current_user == @undertaking.user
               unless @undertaking.comments.count > 0
               redirect_to root_path
             end
         end
       end
Answers to

Rspec and Capybara , what is the difference between visit and get

nr: #1 dodano: 2016-12-27 16:12

Capybara, being an acceptance test framework, does not expose low-level details like a request or response object. In order to access a web page using Capybara, the developer needs to use the method visit (instead of get). To read the accessed page body, the developer must use page instead of manipulating the response.

you can read more "Improving the integration between Capybara and RSpec"

I hope that this helps

Source Show
◀ Wstecz