Ruby Rspec:参数数量错误

Ruby Rspec:参数数量错误,ruby,rspec,Ruby,Rspec,我是Ruby的新手,也是Rspec的新手,我正在尝试通过以下Rspec代码: require "#{File.dirname(__FILE__)}/fish" describe fish do before do @fish = fish.new(3) end it "should report the number of fish" do @fish.number.should equal 3 end end 我正在尝试测试以下代码,我确信这是错误的,原

我是Ruby的新手,也是Rspec的新手,我正在尝试通过以下Rspec代码:

require "#{File.dirname(__FILE__)}/fish"

describe fish do

  before do
    @fish = fish.new(3)
  end

  it "should report the number of fish" do
    @fish.number.should equal 3
  end
end
我正在尝试测试以下代码,我确信这是错误的,原因有很多,但现在我只是试图通过一个“错误数量的参数(1代表0)”错误:


您在类定义中拼写了
initialize
错误(遗漏了n后面的i。)

因此,您的类仍然具有默认构造函数,因为您没有重写它。
默认构造函数不接受任何参数,因此当您尝试传递
3

时,我会立即注意到一些事情

  • 我建议在您习惯Ruby的语法之前使用括号

  • 您在类中拼写错误了
    initialize

  • 用大写字母
    F
    初始化
    Fish
    (以及类
    Fish
    ,以这种方式)



  • 天哪,谢谢!我犯了一个多么愚蠢的错误>@aserty你也应该从一个没有大写的类名中得到一个错误。你没有得到一个错误吗?当我去修复stackoverflow上的格式时,我删除了大写的F并意外地用小写的F替换了它,但是谢谢你的关注:)
    class fish
      def intialize n
        @number = n
      end
    end
    
    describe fish do
      before do
        @fish = Fish.new(3)
      end
    
      it "should report the number of fish" do
        @fish.number.should equal(3)
      end
    end
    
    
    class Fish
      def intialize n
        @number = n
      end
    end