这是我的 RSpec 测试:
describe "GET #show" do
it "assigns the requested user to @user" do
user = FactoryGirl.build(:user)
get :show, id: user
assigns(:user).should eq(user)
end
end
这是我的导轨控制器:
def show
@user = User.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @user }
end
end
我收到以下错误消息:
Failures:
1) UsersController GET #show assigns the requested user to @user
Failure/Error: get :show, id: user
ActiveRecord::RecordNotFound:
Couldn't find User without an ID
# /home/tim/fairym/app/controllers/users_controller.rb:25:in `show'
# ./users_controller_spec.rb:21:in `block (3 levels) in <top (required)>'
为了使测试通过,在这里使用 get 方法的正确方法是什么?