gpt4 book ai didi

ruby-on-rails - 未初始化常量 MiniTest::测试错误

转载 作者:行者123 更新时间:2023-11-28 21:23:59 26 4
gpt4 key购买 nike

我正在尝试开始使用 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

最佳答案

I don't understand why it asks for input from me when I call this in the test file

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

I am not sure I understand the error or the nature of it

也许你没有给予足够的重视?它是 Minitest::Test,而不是 Minitest::test

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com