0

RSpec中的这些块有什么区别以及在块之前使用哪种情况

before(:each)
end

before
end
4

2 回答 2

1

没有区别。:each是默认选项。除非您指定:each/ :all,否则:each使用 then。

于 2012-08-02T06:26:28.743 回答
0

: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

于 2012-08-02T06:36:34.977 回答