0

私のテストを実行するとき、それは実際には新しいガイドラインを作成していません。私はすべての属性を持っているので、私が欠けているものをまったく見ることができません...

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>.

モデルguideline.rb

attr_accessible :content, :hospital, :title, :user_id, :guideline_id, :specialty

ガイドライン_コントローラー_テスト.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"
4

1 に答える 1

0

あなたのテストでは@guideline、その属性はどこから取得していますか?私はいつもrspecRailsのテストスイートの代わりに使用しているのでわかりませんが、次のようなことをする必要があると思います。

post :create, guideline: { content: "This is the content", hospital: "Children's hospital", title: ... }

私が間違っている場合は私を訂正してください...

于 2013-02-20T23:34:24.570 に答える