Dao*_*ang 5 ruby testing rspec
我有一个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)
AFAIK,let()的值将在同一示例中的多个调用中缓存,但不跨示例缓存.所以当使用before(:all)时,不太确定为什么它会失败第二个例子.
我正在使用ruby 1.9.2p180和rspec 2.6.4
| 归档时间: |
|
| 查看次数: |
295 次 |
| 最近记录: |