RSpec中的这些块有什么区别以及在块之前使用哪种情况
before(:each)
end
before
end
没有区别。:each
是默认选项。除非您指定:each
/ :all
,否则:each
使用 then。
:each is the scope, it can be :each which runs the block before each example, or :all which runs the block before all examples.
You use it to run a block before each or all examples to set up your text fixture. you always have to pass a block to before, thus, your syntax above is slightly incorrect, it should be
before(:each) do
...
end
or before(:each) { ... }
see https://www.relishapp.com/rspec/rspec-core/v/2-0/docs/hooks/before-and-after-hooks