0

私の作成メソッドには、次のrspecテストがあります

describe "with valid information" do
  it "should respond with success" do
    post 'create', :show_secretary_id => @show_secretary.id, :show => @show
    response.should be_success
  end

  it "should incremenet the show count" do
    expect do 
      post 'create', :show_secretary_id => @show_secretary.id, :show => @show
    end.to change(Show,'count').by(1)
  end
end

テストは失敗します。ただし、ブラウザで create メソッドを試すと、機能します。私が欠けているものについてのアイデアはありますか?

編集:私のコントローラーコード

  def create
    @show_secretary = ShowSecretary.find_by_id(params[:show_secretary_id])
    @show = @show_secretary.shows.build(params[:show])
    if @show.save
      flash[:notice] = "Successfully created show"
      redirect_to show_path @show 
    else
      render 'new'
    end
  end

編集: @show_secretary、@show

これら 2 つのオブジェクトは、それぞれ FactoryGirl によって作成および構築された ActiveRecords です。

@show_secretary = FactoryGirl.create(:show_secretary_user).verifiable
@show = FactoryGirl.build(:show)
4

1 に答える 1

1

交換

@show = FactoryGirl.build(:show)

と:

@show = FactoryGirl.attributes_for(:show)
于 2012-07-30T15:14:41.193 に答える