Есть ли способ «отключить» общий контекст внутри одного blcok? - PullRequest
0 голосов
/ 30 октября 2019

Я использую общие контексты для СУШКИ моих спецификационных файлов.

Однако у меня есть один единственный блок context, где я хотел бы отключить общий контекст. Возможно ли это?

describe MyClass do
  include_context 'my shared context'

  describe '#some_method' do
    # Specs using the shared context...

    context 'with some special context' do
      # Turn off 'my shared context' here      
      # ...
    end
  end
end

1 Ответ

1 голос
/ 30 октября 2019

Я думаю, что, слегка изменив способ включения контекста и используя метаданные RSpec, вы сможете добиться этого.

RSpec.shared_context "my shared context" do
  # code
end



# spec/support/shared_context_load.rb
RSpec.configure do |config|
  config.before do |example|
    unless example.metadata[:load_shared_context] == false
      config.include_context "my shared context"
    end
  end
end



describe MyClass do
  # NOTE the shared_contxet is removed from here

  describe '#some_method' do
    # Specs using the shared context...

    it "this spec using shared context"
       # code
    end

    context 'with some special context' do
      it "this spec is not using shared context", load_shared_context: false do 
        # Turn off 'my shared context' here      
        # ...
      end
    end
  end
end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...