Здравствуйте, подскажите пожалуйста почему не срабатывает тест?
RSpec.describe QuestionsController, type: :controller do
describe "Show action" do
it "renders show template if an item is found" do
question = Question.create
get :show, {id: question.id}
response.should render_template('show')
end
it "renders 404 page if an question is not found" do
get :show, {id: 10}
expect(response).to have_http_status(:error)
end
end
end
В контроллере QuestionsController, есть before_action: set_question там
def set_question
@question = Question.find(params[:id])
unless @question
render status: 404
end
end
При вводе в адресной строке id вопроса, который не существует происходит редирект на страницу 404. Но при прохождении 2 части теста выскакивает ошибка
Failure/Error: @question = Question.find(params[:id])
ActiveRecord::RecordNotFound:
Couldn't find Question with 'id'=10
Подскажите пожалуйста что не так.