【问题标题】:How can i create this simple minitest?我怎样才能创建这个简单的小测试?
【发布时间】:2020-10-10 19:26:52
【问题描述】:

我是测试 Rails 应用程序的新手,我正在尝试在 Udemy 上为朋友做 YAML 测试,但我做不到,你能帮帮我吗?

目的是在文本中插入“vegetable:”中的“carrot”一词,并带有空格。

要修改的消息是这样的:

Fruit: Apple
Drink: Water
Dessert: Cake
Vegetable:

我在想这样的事情,但显然是错误的,

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

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

【问题讨论】:

    标签: ruby-on-rails ruby yaml minitest


    【解决方案1】:

    所以在加载 YAML 时,你有这样的哈希值,对吧?

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

    然后你可以这样测试它

    assert_equal hash[:Vegetable], 'Carrot'
    

    所以我们从哈希中选择键 :Vegetable 并断言它是 Carrot

    【讨论】:

    • 我添加了一个错误,你能帮帮我吗?谢谢克里斯蒂安!
    猜你喜欢
    • 2022-11-28
    • 2017-08-11
    • 2022-01-11
    • 1970-01-01
    • 2011-04-27
    • 2017-07-06
    • 2022-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多