小编Dao*_*ang的帖子

当使用before(:all)时,let()值在示例中缓存?

我有一个spec文件,看起来像:

# foo_spec.rb
class Foo
end

describe 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' }
  end
end
Run Code Online (Sandbox Code Playgroud)

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

1) Foo test two
     Failure/Error: it        { should == 'two' }
       expected: "two"
            got: "one" (using ==) …
Run Code Online (Sandbox Code Playgroud)

ruby testing rspec

5
推荐指数
1
解决办法
295
查看次数

标签 统计

rspec ×1

ruby ×1

testing ×1