运行我的测试时,实际上并没有创建新的指南。因为我拥有所有的属性,所以我无法看到我所缺少的东西......
1) Failure:
test_should_create_guideline_when_logged_in(GuidelinesControllerTest) [test/functional/guidelines_controller_test.rb:47]:
"Guideline.count" didn't change by 1.
<4> expected but was
<3>.
MODELS guideline.rb
attr_accessible :content, :hospital, :title, :user_id, :guideline_id, :specialty
guidelines_controller_test.rb
test "should create guideline when logged in" do
sign_in users(:testuser)
assert_difference('Guideline.count') do
post :create, guideline: { content: @guideline.content, hospital: @guideline.hospital, title: @guideline.title, user_id: users(:testuser).id, specialty: @guideline.specialty }
end
assert_redirected_to guideline_path(assigns(:guideline))
end
夹具/ users.yml里
testuser:
first_name: "Jonny"
last_name: "Rotten"
email: "jonnyrotten@gmail.com"
base_hospital: "Rottem Hospital"
profile_name: "jjrotten"
encrypted_password: "password"
答案 0 :(得分:0)
在您的测试中@guideline
从哪里获取其属性?我总是使用rspec
代替Rails的测试套件,所以不确定,但会认为你需要做类似的事情:
post :create, guideline: { content: "This is the content", hospital: "Children's hospital", title: ... }
如果我错了,请纠正我......