嵌套使用ScalaTest中嵌套的beforeAll / afterAll方法描述块?

时间:2016-09-07 15:23:48

标签: scala rspec scalatest

我们正在尝试将所有旧RSpec转换为ScalaTest FunSpec。我们遇到了嵌套describe块的问题。

在RSpec中,每个嵌套的describe块都可以将自己的before/after(:all/:each)块添加到外部作用域。这是一个非常有用的事情,我们已经很好地利用它。不幸的是,ScalaTest只能在测试类的根级别拥有before/afterAll/Each()个方法,因此不能嵌套。

是否有解决方法?

RSpec的:

describe 'A person with two email addresses' do
  before(:all) do
    # create data
  end

  after(:all) do
    # delete data
  end

  it 'should have two phone numbers' do
    # ...
  end

  describe 'and one email address is retired' do
    before(:all) do
      # change some settings
    end

    it 'should be able to delete a retired email address' do
      # ...
    end

    it 'should not be able to retire the other email address' do
      # ...
    end
  end
end

0 个答案:

没有答案