привет я делаю некоторые испытания моего приложения с Rspec (это мой самый первый раз я использую его)RSpec Рубин на Rails неинициализированным постоянной RecipesController :: Рецепты
это мой тестовый файл, расположенный в спецификации/контроллеры/recipes_controller_spec.rb:
require 'spec_helper'
describe RecipesController do
render_views
describe "index" do
before do
Recipe.create!(name: 'Baked Potato w/ Cheese')
Recipe.create!(name: 'Garlic Mashed Potatoes')
Recipe.create!(name: 'Potatoes Au Gratin')
Recipe.create!(name: 'Baked Brussel Sprouts')
xhr :get, :index, format: :json, keywords: keywords
end
subject(:results) { JSON.parse(response.body) }
def extract_name
->(object) { object["name"] }
end
context "when the search finds results" do
let(:keywords) { 'baked' }
it 'should 200' do
expect(response.status).to eq(200)
end
it 'should return two results' do
expect(results.size).to eq(2)
end
it "should include 'Baked Potato w/ Cheese'" do
expect(results.map(&extract_name)).to include('Baked Potato w/ Cheese')
end
it "should include 'Baked Brussel Sprouts'" do
expect(results.map(&extract_name)).to include('Baked Brussel Sprouts')
end
end
context "when the search doesn't find results" do
let(:keywords) { 'foo' }
it 'should return no results' do
expect(results.size).to eq(0)
end
end
end
end
, когда я пытаюсь запустить его с помощью команды:
bundle exec rspec spec/controllers/recipes_controller_spec.rb
я не в состоянии все мои TES TS с этой ошибкой:
Failure/Error: xhr :get, :index, format: :json, keywords: keywords
NameError:
uninitialized constant RecipesController::Recipes
# ./app/controllers/recipes_controller.rb:4:in `index'
# ./spec/controllers/recipes_controller_spec.rb:12:in `block (3 levels) in <top (required)>'
Я попытался посмотреть все мой код, но я не обнаружил ошибку
Он находится внутри вашего контроллера, строка 4. Не могли бы вы пропустить этот файл? – BroiSatse
Похоже, у вас есть 'Рецепты', а не' Рецепт' в 'index' метод' recipes_controller'. – Pavan