aboutsummaryrefslogtreecommitdiffstats
path: root/spec/spec_helper.rb
blob: 6d99fa40385b617bbf6f2f015789683c78c656ea (plain) (blame)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
dir = File.dirname(__FILE__)
$LOAD_PATH.unshift "#{dir}/../lib"

require 'rubygems'
require 'spec'
require 'pp'
require 'fileutils'
require 'arel'

[:matchers, :doubles].each do |helper|
  Dir["#{dir}/#{helper}/*"].each { |m| require "#{dir}/#{helper}/#{File.basename(m)}" }
end

module AdapterGuards
  def adapter_is(name)
    verify_adapter_name(name)
    yield if name.to_s == adapter_name
  end

  def adapter_is_not(name)
    verify_adapter_name(name)
    yield if name.to_s != adapter_name
  end

  def adapter_name
    name = ActiveRecord::Base.configurations["unit"][:adapter]
    verify_adapter_name(name)
    name
  end

  def verify_adapter_name(name)
    raise "Invalid adapter name: #{name}" unless valid_adapters.include?(name.to_s)
  end

  def valid_adapters
    %w[mysql postgresql sqlite3]
  end
end

module Check
  # This is used to eliminate Ruby warnings on some RSpec assertion lines
  # See: https://rspec.lighthouseapp.com/projects/5645/tickets/504
  def check(*args)
  end
end

Spec::Runner.configure do |config|
  config.include BeLikeMatcher, HashTheSameAsMatcher, DisambiguateAttributesMatcher
  config.include AdapterGuards
  config.include Check

  config.before do
    Arel::Table.engine = Arel::Sql::Engine.new(ActiveRecord::Base)
  end
end