开发者

Rspec before method

If a spec file contains this before the it() example groups, what does it mean?

context "when almost full (with one element less than capacity)" do
  开发者_高级运维before(:each) do
    @stack = Stack.new
    (1..9).each { |n| @stack.push n }
  end
end

context "when full" do
  before(:each) do
    @stack = Stack.new
    (1..10).each { |n| @stack.push n }
  end
end

Which one will be the one that is executed before?

I don't get it.


before(:each) will get run prior to running any specs that follow. So for example, in your spec for a full stack, any specifications will have a full stack set up prior being executed. You don't have any It methods, so that does not really occur at present however.

It may be worth noting there is before(:all) which will be run once, prior all specs for that context. Whereas before(:each) gets run prior to each spec.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜