简体   繁体   English

RSpec controller 测试:如何检查 @organization.destroy 是否被调用?

[英]RSpec controller test: How do I check @organization.destroy is being called?

I thought it might be like:我想它可能是这样的:

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

..but I get a "can't modify frozen object" error. ..但我收到“无法修改冻结对象”错误。

Here's how I would write that spec:这是我编写该规范的方式:

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

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

  it { should be_successful }
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM