Module: TestProf::BeforeAll

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(&block) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/test_prof/recipes/rspec/before_all.rb', line 11

def before_all(&block)
  raise ArgumentError, "Block is required!" unless block_given?

  return before(:all, &block) if within_before_all?

  @__before_all_activated__ = true

  before(:all) do
    ActiveRecord::Base.connection.begin_transaction(joinable: false)
    instance_eval(&block)
  end

  after(:all) do
    ActiveRecord::Base.connection.rollback_transaction
  end
end

#within_before_all?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/test_prof/recipes/rspec/before_all.rb', line 28

def within_before_all?
  instance_variable_defined?(:@__before_all_activated__)
end