使用 Rspec 应该收到
Using Rspec should receive
我正在学习一个教程,但遇到了一些错误,我相信某些语言已经过时 Rspec 并且已经搞砸了很多尝试并解决这个问题但未能解决。
我得到的错误是
NoMethodError:
undefined method `should_recieve' for #<Panda:0x007f9cd45c6458>
# ./spec/zookeeper_spec.rb:9:in `block (2 levels) in <top (required)>'
有问题的代码是
describe Zookeeper do
it "should be able to feed the bamboo to the pandas" do
panda = Panda.new
panda.should_recieve(:eat).with(:bamboo)
Zookeeper.new.feed(food: :bamboo, to: panda)
end
我意识到 should_recieve 实际上应该是 should_receive,这已经解决了问题。然后我将 should_receive 替换为 and expectation and to receive
describe Zookeeper do
it "should be able to feed the bamboo to the pandas" do
panda = Panda.new
expect(panda).to receive(:eat).with(:bamboo)
Zookeeper.new.feed(food: :bamboo, to: panda)
end
我正在学习一个教程,但遇到了一些错误,我相信某些语言已经过时 Rspec 并且已经搞砸了很多尝试并解决这个问题但未能解决。
我得到的错误是
NoMethodError:
undefined method `should_recieve' for #<Panda:0x007f9cd45c6458>
# ./spec/zookeeper_spec.rb:9:in `block (2 levels) in <top (required)>'
有问题的代码是
describe Zookeeper do
it "should be able to feed the bamboo to the pandas" do
panda = Panda.new
panda.should_recieve(:eat).with(:bamboo)
Zookeeper.new.feed(food: :bamboo, to: panda)
end
我意识到 should_recieve 实际上应该是 should_receive,这已经解决了问题。然后我将 should_receive 替换为 and expectation and to receive
describe Zookeeper do
it "should be able to feed the bamboo to the pandas" do
panda = Panda.new
expect(panda).to receive(:eat).with(:bamboo)
Zookeeper.new.feed(food: :bamboo, to: panda)
end