RSpec控制器测试:我如何检查@ organization.destroy?

时间:2011-07-02 20:40:05

标签: ruby-on-rails ruby-on-rails-3 testing rspec rspec-rails

我认为它可能就像:

let(:organization) { mock_model(Organization).as_null_object }

before(:each) do
  Organization.stub(:find).and_return(organization)
end

it "calls the destroy action on @organization" do
  assigns[:organization].should_receive("destroy")
  post :destroy, :id => organization.id
end

..但是我得到了“无法修改冻结对象”的错误。

1 个答案:

答案 0 :(得分:0)

以下是我将如何编写该规范:

describe 'Oragnization#destroy' do
  let(:organization) { mock_model(Organization, :id => 1, :destroy => true) }

  subject { post :destroy, :id => organization.id }

  it { should be_successful }
end