File: before_all.rb

package info (click to toggle)
ruby-test-prof 0.12.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 508 kB
  • sloc: ruby: 4,075; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 774 bytes parent folder | download
1
2
3
4
5
6
7
8
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
# frozen_string_literal: true

require "test_prof/before_all"

module TestProf
  module BeforeAll
    # Helper to wrap the whole example group into a transaction
    module RSpec
      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
          BeforeAll.begin_transaction do
            instance_eval(&block)
          end
        end

        after(:all) do
          BeforeAll.rollback_transaction
        end
      end

      def within_before_all?
        instance_variable_defined?(:@__before_all_activated__)
      end
    end
  end
end

RSpec::Core::ExampleGroup.extend TestProf::BeforeAll::RSpec