Module: TestProf::BeforeAll::RSpec

Defined in:
lib/test_prof/recipes/rspec/before_all.rb

Overview

Helper to wrap the whole example group into a transaction

Instance Method Summary collapse

Instance Method Details

#before_all(setup_fixtures: BeforeAll.config.setup_fixtures, &block) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/test_prof/recipes/rspec/before_all.rb', line 9

def before_all(setup_fixtures: BeforeAll.config.setup_fixtures, &block)
  raise ArgumentError, "Block is required!" unless block

  if within_before_all?
    before(:all) do
      @__inspect_output = "before_all hook"
      ::RSpec.current_scope = :before_all if ::RSpec.respond_to?(:current_scope=)
      instance_eval(&block)
    end
    return
  end

  @__before_all_activation__ = context = self
   = 

  before(:all) do
    @__inspect_output = "before_all hook"
    ::RSpec.current_scope = :before_all if ::RSpec.respond_to?(:current_scope=)
    BeforeAll.setup_fixtures(self) if setup_fixtures
    BeforeAll.begin_transaction(context, ) do
      instance_eval(&block)
    end
  end

  after(:all) do
    BeforeAll.rollback_transaction(context, )
  end
end

#within_before_all?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/test_prof/recipes/rspec/before_all.rb', line 38

def within_before_all?
  instance_variable_defined?(:@__before_all_activation__)
end