Ruby 的 RSpec 测试替身中的#<foo> 和#[foo] 有什么区别?
What's the difference between #<foo> and #[foo] in Ruby's RSpec test doubles?
我为一个较旧的 Ruby 库做出了开源贡献,以修复上游依赖项更改的几个错误。我认为它运行良好并修补了问题,但是,RSpec 测试失败并显示一条我无法理解的错误消息。
.....................................F...........................
Failures:
1) MagicAdmin::Resource::Token instance methods public methods #validate
Failure/Error: validate_public_address!(rec_address, did_token)
#<MagicAdmin::Resource::Token:0x00007fac020ff7c0> received :validate_public_address! with unexpected arguments
expected: (#<Double "rec_address">, "WyIweHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAw...DAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDBcIn0iXQ==")
got: ("#[Double \"rec_address\"]", "WyIweHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAw...DAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDBcIn0iXQ==")
Diff:
@@ -1 +1 @@
-[#<Double "rec_address">,
+["#[Double \"rec_address\"]",
# ./lib/magic-admin/resource/token.rb:25:in `validate'
# ./test/resource/token_test.rb:31:in `block (4 levels) in <top (required)>'
# /Users/ajen/.rvm/gems/ruby-3.0.1/gems/webmock-3.14.0/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
Finished in 0.21978 seconds (files took 1.9 seconds to load)
65 examples, 1 failure
Failed examples:
rspec ./test/resource/token_test.rb:8 # MagicAdmin::Resource::Token instance methods public methods #validate
Coverage report generated for RSpec to /Users/ajen/pg/magic-admin-ruby/coverage. 633 / 643 LOC (98.44%) covered.
Stopped processing SimpleCov as a previous error not related to SimpleCov has been detected
这是一个永久的、深入的 link 问题测试:magic-admin-ruby/0b7c37e..633516b/test/resource/token_test.rb#L9-L31
具体来说,以下差异让我感到困惑:
@@ -1 +1 @@
-[#<Double "rec_address">,
+["#[Double \"rec_address\"]",
我该如何阅读? Ruby 的 RSpec 测试双打中 #<foo>
和 #[foo]
有什么区别?
当我看这两行的时候
expected: (#<Double "rec_address">, "WyIweHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAw...DAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDBcIn0iXQ==")
got: ("#[Double \"rec_address\"]", "WyIweHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAw...DAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDBcIn0iXQ==")
那么看起来您期望 Double
的实例,但您得到了 Double
的 String
表示。注意第二行的值用双引号括起来,里面的引号转义了。
我为一个较旧的 Ruby 库做出了开源贡献,以修复上游依赖项更改的几个错误。我认为它运行良好并修补了问题,但是,RSpec 测试失败并显示一条我无法理解的错误消息。
.....................................F...........................
Failures:
1) MagicAdmin::Resource::Token instance methods public methods #validate
Failure/Error: validate_public_address!(rec_address, did_token)
#<MagicAdmin::Resource::Token:0x00007fac020ff7c0> received :validate_public_address! with unexpected arguments
expected: (#<Double "rec_address">, "WyIweHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAw...DAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDBcIn0iXQ==")
got: ("#[Double \"rec_address\"]", "WyIweHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAw...DAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDBcIn0iXQ==")
Diff:
@@ -1 +1 @@
-[#<Double "rec_address">,
+["#[Double \"rec_address\"]",
# ./lib/magic-admin/resource/token.rb:25:in `validate'
# ./test/resource/token_test.rb:31:in `block (4 levels) in <top (required)>'
# /Users/ajen/.rvm/gems/ruby-3.0.1/gems/webmock-3.14.0/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'
Finished in 0.21978 seconds (files took 1.9 seconds to load)
65 examples, 1 failure
Failed examples:
rspec ./test/resource/token_test.rb:8 # MagicAdmin::Resource::Token instance methods public methods #validate
Coverage report generated for RSpec to /Users/ajen/pg/magic-admin-ruby/coverage. 633 / 643 LOC (98.44%) covered.
Stopped processing SimpleCov as a previous error not related to SimpleCov has been detected
这是一个永久的、深入的 link 问题测试:magic-admin-ruby/0b7c37e..633516b/test/resource/token_test.rb#L9-L31
具体来说,以下差异让我感到困惑:
@@ -1 +1 @@
-[#<Double "rec_address">,
+["#[Double \"rec_address\"]",
我该如何阅读? Ruby 的 RSpec 测试双打中 #<foo>
和 #[foo]
有什么区别?
当我看这两行的时候
expected: (#<Double "rec_address">, "WyIweHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAw...DAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDBcIn0iXQ==")
got: ("#[Double \"rec_address\"]", "WyIweHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAw...DAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDB0ZXN0MDAwMHRlc3QwMDAwdGVzdDAwMDBcIn0iXQ==")
那么看起来您期望 Double
的实例,但您得到了 Double
的 String
表示。注意第二行的值用双引号括起来,里面的引号转义了。