Ruby on rails 在rspec中跨多个文件设置多个测试的元数据
我正在使用vcr作为元数据,使用以下语法编写许多测试:Ruby on rails 在rspec中跨多个文件设置多个测试的元数据,ruby-on-rails,rspec,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 ser
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
因为我的大多数测试都会进行web调用,所以我希望能够将文件或文件文件夹中的每个测试设置为自动使用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
我只想正常编写测试,并让每个it块假设测试应该使用vcr和vcr选项运行(为少数不使用的测试设置元数据)。如何实现这一点?您可以在示例组级别设置VCR选项,它将应用于示例组(或任何嵌套组)中的所有示例:
请看这里:。如果在块之前使用VCR宏和RSpec global
,我相信您可以使其正常工作。VCR::RSpec::Macros不推荐使用。运行它会要求人们使用RSpec元数据选项,而不是:vcr=>vcr\u选项
describe SomeClass, vcr: vcr_options do
it 'uses VCR without explicitly using VCR metadata at this level' do
end
end