rspec undefined方法`receive'用于expect语法

时间:2013-11-16 22:25:37

标签: rspec

更改有效的测试,例如:

describe "a" do
  it "does part A" do
    it "does not wait if not run in parallel" do
      ParallelTests.should_not_receive(:sleep)
      ParallelTests.wait_for_other_processes_to_finish
    end
  end
end

describe "a" do
  it "does not wait if not run in parallel" do
    expect(ParallelTests).to_not receive(:sleep)
    ParallelTests.wait_for_other_processes_to_finish
  end
end

给出

 Failure/Error: expect(ParallelTests).to_not receive(:sleep)
 NoMethodError:
   undefined method `receive' for 
 #<RSpec::Core::ExampleGroup::Nested_1::Nested_3:0x00000002874158>

这是一个例子。在许多地方发生的事情,共同的主题是,它始终是将.should_receive更改为expect().to receive

Gemfile的版本为2.4

的rspec

如何解决?

1 个答案:

答案 0 :(得分:5)

根据http://myronmars.to/n/dev-blog/2013/07/rspec-2-14-is-released在RSpec 2.14中引入了expect语法用于消息期望。 (注意:根据推荐的http://semver.org/,RSpec 2.4是早于的十个次要版本,而不是RSpec 2.14。)

将Gemfile更改为2.14,例如gem 'rspec', '2.14'并执行bundle