My spec/controllers/undertakings_controller_spec.rbは以下のとおりです。RspecとCapybara、訪問と取得の違いは何ですか
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
これはエラーです(予想される応答はaですが、<> 200)。 しかし、(undertaking_path(@undertaking)を訪問して)(get:show、id:@undertaking)に変更すると、エラーにはなりません。訪問とゲットの違いは何ですか?私は
を読んで、私は、この場合にエラーを理解することはできません。私を助けてください。
とにかく、私のコントローラ/ undertakings_controller.rbは以下の通りです。
class UndertakingsController < ApplicationController
before_action :undertaking_not_have_comment , only: [:show]
def show
@undertaking=Undertaking.find(params[:id])
@[email protected]
@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
に役立つことを願っています "であることが予想応答が、<200>だった" ですフルエラー? –
申し訳ありませんが、エラーの上に "Failure/Error:expect(response).to redirect_to root_path"があります。 –
'visit'は、rspecとのインテグレーション/フィーチャ仕様で使用されるカピバラのメソッドであり、' get'は一般的にコントローラ/ルーティング仕様に使用されます。これらは、テストをより読みやすくするためのDSLです。バックグラウンドでは、訪問はGETリクエストを経由します – sa77