我的路线文件如下所示:
resources :people do
resources :text_messages, only: [:index, :new, :create]
end
我的/app/controllers/text_messages_controllers.rb
看起来像:
class TextMessagesController < ApplicationController
def index
puts 'You have reached the index controller'
@messages = Message.all
end
end
这是/spec/controllers/text_messages_controller_spec.rb
describe TextMessagesController do
describe 'GET #index' do
it 'shows all the messages to that user' do
person = create(:person)
message = create(:message, person: person)
get :index, person_id: person.id
expect(assigns(:messages)).to include(message)
end
end
end
然而,当我运行测试时,它失败说@messages
为零并且不打印文本。为什么此测试未达到控制器操作?当我访问网址时,它在开发方面效果很好。