简体   繁体   中英

How can i create this simple minitest?

I'm new to testing rails applications, i'm trying to do a test of YAML for a friend on Udemy, but i cannot do it, could you help me?

The objective is insert in the text the word "carrot" in "vegetable:" with a space.

The message to modify is this:

Fruit: Apple
Drink: Water
Dessert: Cake
Vegetable:

I was thinking in something like this, but it's obviously wrong,

require "minitest/autorun"
require "./food"

class Evaluate < Minitest::Test
    def test_Vegetable
        assert_equal {"Vegetable"=>"Carrot"},
                     vegetable,
                     "Vegetable: Carrot"
    end
end

So when loading the YAML you have a hash like this, right?

hash = {
 Fruit: 'Apple',
 Drink: 'Water',
 Dessert: 'Cake',
 Vegetable: 'Carrot'
}

Then you could test it like this

assert_equal hash[:Vegetable], 'Carrot'

So we select the key :Vegetable from the hash and assert it's Carrot .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM