我正在尝试Minitest。我收到以下错误:

`const_missing': uninitialized constant MiniTest::Test (NameError)


这是我的主要代码文件:

class BmiCalc

    def initialize(weight, height)
        @weight = weight;
        @height = height;
    end

    def bmi
        kgweight = @weight * 0.4535;
        meterheight = @height * 0.01;
        bmivalue = kgweight/(meterheight * meterheight);
        return bmivalue;
    end

end

print "Please Enter your Weight in lbs: ";
weight = gets.to_f;

print "Please Enter your Height in cm: ";
height = gets.to_f;

bmiCalc = BmiCalc.new(weight, height);
answer = bmiCalc.bmi;

printf("You have a BMI of #{'%.2f' % answer} \n");


这是我的MiniTest文件:

require 'minitest/autorun'
require_relative "bmicalc.rb"

class TestBmi < Minitest::Test

    def setup
        @bmicalc = BmiCalc.new(190, 250);
    end

    def test_answers
        assert_equal 31.40581717451523, @bmicalc.bmi;
    end

end


首先,我不明白为什么在测试文件中调用它时会要求我提供输入。我已经实例化了一个示例类,所以为什么要输入。

其次,我不确定我是否理解错误或错误的性质。我正在尝试遵循本教程:http://blog.teamtreehouse.com/short-introduction-minitest

最佳答案

我不明白为什么在测试文件中调用它时会要求我输入


因为在您的测试文件中,您需要"bmicalc.rb",所以它将运行其中的所有代码。包括您的打印和获取行。


  我不确定我是否理解错误或错误的性质


您可能没有引起足够的重视?它是Minitest::Test,而不是Minitest::test

关于ruby-on-rails - 未初始化的常量MiniTest::Test错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45353599/

10-13 02:12