Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 3.2销毁挂钩失败前的RSpec测试_Ruby On Rails_Rspec Rails - Fatal编程技术网

Ruby on rails Rails 3.2销毁挂钩失败前的RSpec测试

Ruby on rails Rails 3.2销毁挂钩失败前的RSpec测试,ruby-on-rails,rspec-rails,Ruby On Rails,Rspec Rails,我有两种型号: class Region < ActiveRecord::Base has_one :acol, :dependent => :nullify before_destroy :check_acol_presence private def check_acol_presence if acol errors.add(:base,"activerecord.errors.models.region.delete_with_existin

我有两种型号:

class Region < ActiveRecord::Base
  has_one :acol, :dependent => :nullify
  before_destroy :check_acol_presence
private 
  def check_acol_presence
    if acol
      errors.add(:base,"activerecord.errors.models.region.delete_with_existing_acol")
      return false
    end
  end
end

class Acol < ActiveRecord::Base
  belongs_to :region
end

在rails控制台中,此检查工作正常。但测试失败了。为什么?

试着在有一行之前放置销毁行

应该是raise\u错误,而不仅仅是raise:

lambda { region.reload }.should_not raise_error(ActiveRecord::RecordNotFound)

否则,您的测试本身可能会导致错误。

旧帖子,但它可以将“在销毁之前”移到“已销毁”之前。。。谢谢
lambda { region.reload }.should_not raise_error(ActiveRecord::RecordNotFound)