我正在使用 rspec 测试我的应用程序,我读到我必须在测试环境中创建一个用户,但不知道如何......这是代码:
require 'spec_helper'
describe CarsController do
describe "GET 'new'" do
it "should be successful" do
visit new_user_car_path(:user_id=>"28")#also try (current_user) but nothing
response.should be_success
end
end
end
当我运行它时,我收到了这条消息
Failure/Error: visit new_user_car_path(:user_id=>"28")
ActiveRecord::RecordNotFound:
Couldn't find User with id=28
# ./app/controllers/cars_controller.rb:3:in `new'
# ./spec/controllers/tanking_logs_controller_spec.rb:6:in `block (3 levels) in <top (required)>'
如果您需要更多代码,请告诉我
编辑。我试过这个
require 'spec_helper'
describe CarsController do
describe "GET 'new'" do
it "should be successful" do
#user = User.create(...)
@user = {:email => "user@example.com", :password => "foobar", :password_confirmation => "foobar" }
visit new_user_car_path(@user)
response.should be_success
end
end
end
我现在得到了这个错误:
No route matches {:action=>"new", :controller=>"cars", :email=>"user@example.com", :password=>"foobar", :password_confirmation=>"foobar"}