Rspec 和 Capybara , visit 和 get 有什么区别
Rspec and Capybara , what is the difference between visit and get
下面是我的spec/controllers/undertakings_controller_spec.rb
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
这有错误(预期响应为 ,但为 <200>)。
但是当我将 (visit undertaking_path(@undertaking) ) 更改为 ( get :show , id: @undertaking ) 时,这没有错误。 visit 和 get 有什么区别?我读
Rspec and capybara, difference between visit and get methods, with regards to the current_path object
但我无法理解这种情况下的错误。请帮助我。
反正我的controllers/undertakings_controller.rb在下面
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
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.
您可以阅读更多内容“Improving the integration between Capybara and RSpec”
希望对您有所帮助
下面是我的spec/controllers/undertakings_controller_spec.rb
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
这有错误(预期响应为 ,但为 <200>)。 但是当我将 (visit undertaking_path(@undertaking) ) 更改为 ( get :show , id: @undertaking ) 时,这没有错误。 visit 和 get 有什么区别?我读
Rspec and capybara, difference between visit and get methods, with regards to the current_path object
但我无法理解这种情况下的错误。请帮助我。
反正我的controllers/undertakings_controller.rb在下面
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
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.
您可以阅读更多内容“Improving the integration between Capybara and RSpec”
希望对您有所帮助