【发布时间】:2011-10-25 09:36:59
【问题描述】:
如果我有 rspec 测试如下:
context "main context" do
before(:all) do
# code for before :all
puts "my fore :all"
end
describe "Scenario-1" do
context "my context 1" do
it "should blablabla" do
end
it "should blablabla" do
end
end
context "my context 2" do
it "should blablabla" do
end
it "should blablabla" do
end
end
end # end of describe "Scenario-1"
describe "Scenario-2"
context "my context 3" do
it "should blablabla" do
end
it "should blablabla" do
end
end
end #end of "Scenario-2"
end #end of main context
要问的两个问题:
1. 是不是before(:all) 声明实际上在每个子上下文 中被调用?我以为它在整个测试过程中只被调用一次,但是当我运行测试时,我所经历的是 before(:all) 在每个中执行的代码 @987654324 @,这就是每个 context 开始时运行的,为什么?
(您注意到我的before(:all) 代码中有“puts”,并且我在运行测试时看到每个子上下文中都有这个放置,为什么?不是before(:all)应该在整个测试过程中只执行一次??)
2.当我运行我的测试时,为什么测试运行的顺序是从底部上下文到向上上下文(而在每个上下文中,“it “是上下)?那么如何在上下文级别更改测试顺序?
【问题讨论】:
标签: ruby-on-rails rspec rspec2