的用戶我正在使用rspec測試我的應用程序,我讀到我必須在測試環境中創建用戶,但不知道如何......這裏是代碼:ActiveRecord :: RecordNotFound:找不到id =
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 => "[email protected]", :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=>"[email protected]", :password=>"foobar", :password_confirmation=>"foobar"}
你的方式更清晰給我解釋一下嗎? – Asantoya17 2012-08-02 18:57:44
你有三個數據庫:開發,生產,測試。您正在搜索的記錄存在於開發數據庫中,但不存在於您的測試數據庫中。所以你必須在測試數據庫中創建對象。或者,您可以將測試數據庫更改爲您的開發數據庫,但不建議這樣做,因爲您希望將測試數據庫關閉。 – brntsllvn 2015-04-19 17:18:03