Sha256: c5391aa808e8192ac3c6ed681d852a5d153a7e41e3e1dece2352fdb5d7079a9d

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

require 'active_record'
require 'switch_point'
require 'models'

RSpec.configure do |config|
  config.filter_run :focus
  config.run_all_when_everything_filtered = true

  if config.files_to_run.one?
    config.full_backtrace = true
    config.default_formatter = 'doc'
  end

  config.order = :random
  Kernel.srand config.seed

  config.expect_with :rspec do |expectations|
    expectations.syntax = :expect
  end

  config.mock_with :rspec do |mocks|
    mocks.syntax = :expect
    mocks.verify_partial_doubles = true
  end

  config.before(:suite) do
    Book.with_writable do
      Book.connection.execute('CREATE TABLE books (id integer primary key autoincrement)')
    end
    FileUtils.cp('main_writable.sqlite3', 'main_readonly.sqlite3')

    Note.connection.execute('CREATE TABLE notes (id integer primary key autoincrement)')
  end

  config.after(:suite) do
    ActiveRecord::Base.configurations.each_value do |config|
      FileUtils.rm_f(config[:database])
    end
  end

  config.after(:each) do
    Book.delete_all # This queries to writable database
    FileUtils.cp('main_writable.sqlite3', 'main_readonly.sqlite3')
  end
end

RSpec::Matchers.define :connect_to do |expected|
  database_name = lambda do |model|
    model.connection.pool.spec.config[:database]
  end

  match do |actual|
    database_name.call(actual) == expected
  end

  failure_message do |actual|
    "expected #{actual.name} to connect to #{expected} but connected to #{database_name.call(actual)}"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
switch_point-0.3.1 spec/spec_helper.rb