Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.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 如何使用rspec2.13+;存根ActiveRecord连接对象;?_Ruby On Rails_Ruby_Activerecord_Rspec_Rspec2 - Fatal编程技术网

Ruby on rails 如何使用rspec2.13+;存根ActiveRecord连接对象;?

Ruby on rails 如何使用rspec2.13+;存根ActiveRecord连接对象;?,ruby-on-rails,ruby,activerecord,rspec,rspec2,Ruby On Rails,Ruby,Activerecord,Rspec,Rspec2,如中所示,我试图像这样执行ActiveRecord的存根方法 allow(ActiveRecord::Base.connection).to receive(:execute).and_return(assigments) 我犯了这个错误 Failure/Error: allow(ActiveRecord::Base.connection).to receive(:execute).and_return(assigments) NoMethodError: undefined met

如中所示,我试图像这样执行ActiveRecord的存根方法

allow(ActiveRecord::Base.connection).to receive(:execute).and_return(assigments)
我犯了这个错误

 Failure/Error: allow(ActiveRecord::Base.connection).to receive(:execute).and_return(assigments)
 NoMethodError:
   undefined method `allow' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007fd8c1501648>

在RSpec 2及以上版本中如何称呼它?

您使用的是具有新语法的RSpec版本吗?@sevensacat:是的,我使用的是RSpec 2.13.0这是在正确的上下文中发生的吗?这是在“之前”区吗?
ActiveRecord::Base.connection.should_receive(:execute).and_return(assigments)