我正在尝试编写Ruby代码以使以下Rspec代码通过:
describe ThanksgivingDinner do
before do
@t_dinner = ThanksgivingDinner.new(:vegan)
context "#menu" do
it "should have a diet specified" do
@t_dinner.menu[:diet].should eq :vegan
end
我想传递的代码如下:
class ThanksgivingDinner < Dinner
def initialize(diet)
@diet = diet
end
def menu
{ diet: @diet }
end
end
我一直被告知,不是等于素食主义者,而是返回零值。如何修复此问题以在initialize方法中返回@diet中的值?
编辑:这是CL错误:
3) ThanksgivingDinner#menu should have a diet specified
Failure/Error: @t_dinner.menu[:diet].should eq :vegan
expected: :vegan
got: nil