jeudi 27 juillet 2017

NoMethodError Ruby MiniTest

I am trying to get started with Minitest. I get the following error:

Please Enter your Weight in lbs: 250
Please Enter your Height in cm: 190
You have a BMI of 31.41 
bmicalc_test.rb:4:in `<main>': private method `test' called for 
MiniTest:Module (NoMethodError)

This is my main code file:

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");

This is my MiniTest file:

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

Firstly, I don't understand why it asks for input from me when I call this in the test file. I am instantiation a sample class already so why does it ask for input.

Secondly, I am not sure I understand the error or the nature of it. I am trying to follow this tutorial: http://ift.tt/1APaSmR

Aucun commentaire:

Enregistrer un commentaire