Module: DatabaseRecorder::RSpec

Defined in:
lib/database_recorder/rspec.rb

Class Method Summary collapse

Class Method Details

.setupObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/database_recorder/rspec.rb', line 7

def setup
  ::RSpec.configure do |config|
    config.before(:suite) do
      Core.setup
    end

    config.around(:each, :dbr) do |example|
      ref = (example.[:scoped_id] || '').split(':')[-1]
      options = {}
      options[:name] = "#{example.full_description}__#{ref}"
      options.merge!(example.[:dbr]) if example.[:dbr].is_a?(Hash)
      Recording.new(options: options).tap do |recording|
        recording. = { example: example.id, started_at: Time.now }
        result = recording.start { example.run }
        if options[:verify_queries] && result[:stored_queries]
          expect(result[:stored_queries]).to match_array(result[:current_queries])
        end
      end
    end
  end
end