gpt4 book ai didi

RubyKoans 113/282 - 类型不匹配 :string given/how could i have solved myself with irb?

转载 作者:太空宇宙 更新时间:2023-11-03 17:11:08 25 4
gpt4 key购买 nike

在尝试完成 about_method koans 时,我一直在第 39 和 42 行遇到“type mismatch:String given”错误。我的第一个问题是为什么会出现错误?我的第二个问题是我怎么能用 irb 自己解决这个问题?

公案

 require File.expand_path(File.dirname(__FILE__) + '/neo')

def my_global_method(a,b)
a + b
end

class AboutMethods < Neo::Koan

def test_calling_global_methods_with_wrong_number_of_arguments
exception = assert_raise(ArgumentError) do
my_global_method
end

assert_match(/__/, exception.message)

exception = assert_raise(ArgumentError) do
my_global_method(1,2,3)
end
assert_match(/__/, exception.message)
end
#...
end

错误与我的工作

一个。如果我将断言更改为

assert_match(/"wrong number of arguments (0 for 2)"/, exception.message)

结果是:

Expected "wrong number of arguments (0 for 2)" to match / "wrong number of arguments (0 for 2)" /

B.如果我把它改成

assert_match("wrong number of arguments (0 for 2)", exception.message)

结果是:

type mismatch: String given

对于两条 assert_match 行,我得到了相同的结果。

最佳答案

assert_match(/wrong number of arguments \(0 for 2\)/, exception.message)

没有双引号和转义括号。

关于RubyKoans 113/282 - 类型不匹配 :string given/how could i have solved myself with irb?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19945329/

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