【问题标题】:Skip multiple examples in RSpec?跳过 RSpec 中的多个示例?
【发布时间】:2020-06-30 01:47:41
【问题描述】:

有谁知道跳过组内的多个示例而不在它们之间重复跳过语句的方法?

例如,给定这个测试:

describe 'some feature' do
  it 'should do something' do
    ...
  end

  it 'should do something else too' do
    ...
  end
end

skip 如果放在第一个示例之前,则不起作用,如下所示:

describe 'some feature' do
  skip 'I would like to skip both with one statement'

  it 'should do something' do
    ...
  end

  it 'should do something else too' do
    ...
  end
end

一个理想的解决方案将允许我跳过示例结构的任何级别(describe/featurecontextscenario/it)并跳过该级别的所有子级层次结构。

换句话说,允许我这样做:

describe 'some feature' do
  it 'should do something' do
    ...
  end

  it 'should do something else too' do
    skip 'just one of these for now'
    ...
  end
end

describe 'some feature' do
  skip 'everything within this describe block'

  it 'should do something' do
    ...
  end

  it 'should do something else too' do
    ...
  end
end

也一样

describe 'some feature' do
  context 'such and such' do
    skip 'just this context'

    it 'should do something' do
      ...
    end

    it 'should do something else too' do
      ...
    end

  it 'but do not skip this one' do
    ...
  end
end

【问题讨论】:

    标签: ruby rspec rubygems rspec3


    【解决方案1】:

    documentation 中所述,您可以使用元数据跳过上下文。

    describe 'some feature', :skip do
      it 'should do something' do
        # This example is skipped
      end
    
      it 'should do something else too' do
        # This example is skipped as well
      end
    end
    

    【讨论】:

    • 嗯。具体来说,我正在寻找一种将跳过的原因作为参数传递的方法,就像我在问题详细信息中发布的示例一样;似乎是因为存在使用标签的选项,所以没有涵盖其他用例。谢谢你的回答。
    猜你喜欢
    • 1970-01-01
    • 2022-01-21
    • 2011-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多