# 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:
let
s are not designed to be used withbefore(:all)
blocks
(Quoting rspec贡献者myronmarston从yet another ticket开始就问题(这看起来与你在这里描述的行为非常相似)).
总结以上是内存溢出为你收集整理的ruby – let()值在使用before(:all)时跨越示例缓存?全部内容,希望文章能够帮你解决ruby – let()值在使用before(:all)时跨越示例缓存?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)