我有一个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)