gpt4 book ai didi

rspec - JRuby:nil != nil:即使数组相同,RSpec 测试也会失败

转载 作者:行者123 更新时间:2023-12-04 05:33:40 25 4
gpt4 key购买 nike

我在 JRuby 中看到一个问题,即使预期输出和实际输出相同,我的 rspec 规范也失败了。这是失败消息:

Failures:

1) PgArrayParser#parse_pg_array one dimensional arrays NULL values returns an array of strings, with nils replacing NULL characters
Failure/Error: parser.parse_pg_array(%[{1,NULL,NULL}]).should eq ['1',nil,nil]

expected: ["1", nil, nil]
got: ["1", nil, nil]

(compared using ==)

Diff:["1", nil, nil].==(["1", nil, nil]) returned false even though the diff between ["1", nil, nil] and ["1", nil, nil] is empty. Check the implementation of ["1", nil, nil].==.
# ./spec/parser_spec.rb:26:in `(root)'

2) PgArrayParser#parse_pg_array two dimensional arrays strings returns an array of strings with a sub array and a quoted }
Failure/Error: parser.parse_pg_array(%[{1,{"2,}3",NULL},4}]).should eq ['1',['2,}3',nil],'4']

expected: ["1", ["2,}3", nil], "4"]
got: ["1", ["2,}3", nil], "4"]

(compared using ==)

Diff:["1", ["2,}3", nil], "4"].==(["1", ["2,}3", nil], "4"]) returned false even though the diff between ["1", ["2,}3", nil], "4"] and ["1", ["2,}3", nil], "4"] is empty. Check the implementation of ["1", ["2,}3", nil], "4"].==.
# ./spec/parser_spec.rb:69:in `(root)'

3) PgArrayParser#parse_pg_array three dimensional arrays returns an array of strings with sub arrays
Failure/Error: parser.parse_pg_array(%[{1,{2,{3,4}},{NULL,6},7}]).should eq ['1',['2',['3','4']],[nil,'6'],'7']

expected: ["1", ["2", ["3", "4"]], [nil, "6"], "7"]
got: ["1", ["2", ["3", "4"]], [nil, "6"], "7"]

(compared using ==)

Diff:["1", ["2", ["3", "4"]], [nil, "6"], "7"].==(["1", ["2", ["3", "4"]], [nil, "6"], "7"]) returned false even though the diff between ["1", ["2", ["3", "4"]], [nil, "6"], "7"] and ["1", ["2", ["3", "4"]], [nil, "6"], "7"] is empty. Check the implementation of ["
1", ["2", ["3", "4"]], [nil, "6"], "7"].==.
# ./spec/parser_spec.rb:87:in `(root)'

Finished in 0.2 seconds
15 examples, 3 failures

使用 =~而不是 eq==产生了以下输出:
..F.......F..F.

Failures:

1) PgArrayParser#parse_pg_array one dimensional arrays NULL values returns an array of strings, with nils replacing NULL characters
Failure/Error: parser.parse_pg_array(%[{1,NULL,NULL}]).should =~ ['1',nil,nil]
expected collection contained: ["1", nil, nil]
actual collection contained: ["1", nil, nil]
the missing elements were: [nil, nil]
the extra elements were: [nil, nil]
# ./spec/parser_spec.rb:26:in `(root)'

2) PgArrayParser#parse_pg_array two dimensional arrays strings returns an array of strings with a sub array and a quoted }
Failure/Error: parser.parse_pg_array(%[{1,{"2,}3",NULL},4}]).should =~ ['1',['2,}3',nil],'4']
expected collection contained: ["1", ["2,}3", nil], "4"]
actual collection contained: ["1", ["2,}3", nil], "4"]
the missing elements were: [["2,}3", nil]]
the extra elements were: [["2,}3", nil]]
# ./spec/parser_spec.rb:69:in `(root)'

3) PgArrayParser#parse_pg_array three dimensional arrays returns an array of strings with sub arrays
Failure/Error: parser.parse_pg_array(%[{1,{2,{3,4}},{NULL,6},7}]).should =~ ['1',['2',['3','4']],[nil,'6'],'7']
expected collection contained: ["1", ["2", ["3", "4"]], [nil, "6"], "7"]
actual collection contained: ["1", ["2", ["3", "4"]], [nil, "6"], "7"]
the missing elements were: [[nil, "6"]]
the extra elements were: [[nil, "6"]]
# ./spec/parser_spec.rb:87:in `(root)'

Finished in 0.17 seconds
15 examples, 3 failures

规范为 here .需要注意的是,这些比较是唯一包含 nil 的比较。 s。好像是 nil在 Java 中实例化与 nil 不同在 JRuby 中有人知道解决此问题的方法吗?

最佳答案

使用 runtime.getNil()而不是 new RubyNil(runtime) here .

关于rspec - JRuby:nil != nil:即使数组相同,RSpec 测试也会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12254965/

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