ruby – let()值在使用before(:all)时跨越示例缓存?

ruby – let()值在使用before(:all)时跨越示例缓存?,第1张

概述我有一个spec文件,看起来像: # foo_spec.rbclass Fooenddescribe Foo do let(:foo) { 'foo' } subject { bar } # before(:all) { foo } # The seond example fails if uncomment this line. describe 'test one' 我有一个spec文件,看起来像:

# foo_spec.rbclass Fooenddescribe Foo do  let(:foo) { 'foo' }  subject { bar }  # before(:all) { foo } # The SEOnd example fails if uncomment this line.  describe 'test one' do    let(:bar) { 'one' }    it        { should == 'one' }  end  describe 'test two' do    let(:bar) { 'two' }    it        { should == 'two' }  endend

这两个例子都按预期传递.但是,如果我取消注释before(:all),则第二个示例将失败:

1) Foo test two     Failure/Error: it        { should == 'two' }       expected: "two"            got: "one" (using ==)

AFAIK,let()的值将在同一示例中的多个调用中缓存,但不跨示例缓存.所以当使用before(:all)时,不太确定为什么它会失败第二个例子.

我正在使用ruby 1.9.2p180和rspec 2.6.4

解决方法 这是 a known problem与rspec:

lets are not designed to be used with before(:all) blocks

(Quoting rspec贡献者myronmarston从yet another ticket开始就问题(这看起来与你在这里描述的行为非常相似)).

总结

以上是内存溢出为你收集整理的ruby – let()值在使用before(:all)时跨越示例缓存?全部内容,希望文章能够帮你解决ruby – let()值在使用before(:all)时跨越示例缓存?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1293930.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-10
下一篇 2022-06-10

发表评论

登录后才能评论

评论列表(0条)

保存