0

我正在尝试编写 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

我一直被告知,不是等于 vegan,而是返回一个 nil 值。如何解决此问题以在初始化方法中从 @diet 返回值?

编辑:这是 CL 错误:

3) ThanksgivingDinner#menu should have a diet specified
 Failure/Error: @t_dinner.menu[:diet].should eq :vegan

   expected: :vegan
        got: nil
4

0 回答 0