在rspec中为多个文件设置多个测试的元数据

时间:2013-06-19 01:45:53

标签: ruby-on-rails rspec

我用vcr作为元数据编写了许多测试,语法如下:

  vcr_options = {allow_playback_repeats: true, :record => :new_episodes, :re_record_interval => 7.days}

  describe 'a User with no enabled services' do
    it 'any system page should show a request to add needed service providers', {vcr: vcr_options, :js => true} do
      ...
    end
  end

因为我的大多数测试都进行了网络调用,所以我希望能够将文件或文件夹中的每个测试设置为自动使用vcr,并设置该选项。

而不是:

vcr_options = {allow_playback_repeats: true, :record => :new_episodes, :re_record_interval => 7.days}

describe 'blah blah' do
    it 'blah blah', vcr: vcr_options do
      ...
    end

    it 'blah blah blah', vcr: vcr_options do
      ...
    end
  end

describe 'etc etc' do
    it 'etc etc', {vcr: vcr_options, js: true} do
      ...
    end

    it 'etc etc etc, vcr: vcr_options do
      ...
    end
  end

我想简单地编写测试并让每个测试块都假设测试应该使用vcr和vcr选项运行(为少数几个测试设置元数据)。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:2)

您可以在示例组级别设置VCR选项,它将应用于示例组(或任何嵌套组)中的所有示例:

describe SomeClass, vcr: vcr_options do
  it 'uses VCR without explicitly using VCR metadata at this level' do
  end
end
相关问题