あなたはbefore(:each)
がこれを試す前に実行するbefore(:all)
をスコープによってこれを行うことができます。
describe 'Feature' do
before(:each) do
puts "second"
end
describe 'Success' do
before(:all) do
puts "first"
end
specify 'It works' do
...
end
end
end
# =>
10:29:54 - INFO - Running: spec
Run options: include {:focus=>true}
first
second
.
Finished in 0.25793 seconds (files took 2.52 seconds to load)
1 example, 0 failures
EDIT:
RSpecの2では、
この順序で実行するアクション:
before suite
before all
before each
after each
after all
after suite
ここに、メソッドの呼び出し順序を示すドキュメントへのリンクがあります。https://www.relishapp.com/rspec/rspec-core/v/2-2/docs/hooks/before-and-after-hooks#before/after-blocks-are-run-in-order
明らかにRspec 3.5では、beforeブロック呼び出しには別の命名もあります。彼らは、この順序で実行します。
before :suite
before :context
before :example
after :example
after :context
after :suite
describe 'Feature' do
before(:example) do
puts "second"
end
describe 'Success' do
before(:context) do
puts "first"
end
specify 'It works' do
...
end
end
end
10:59:45 - INFO - Running: spec
Run options: include {:focus=>true}
first
second
.
Finished in 0.06367 seconds (files took 2.57 seconds to load)
1 example, 0 failures
はここで新しいドキュメントです: http://www.relishapp.com/rspec/rspec-core/v/3-5/docs/hooks/before-and-after-hooks
私はドキュメントを見たが、何も把握していません。 –