Sha256: d73c4b59e9c3fc67a9aaaa5cbc2fe26018e5fdaad7285934704301a80b007470

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 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
    sql = 'CREATE TABLE books (id integer primary key autoincrement)'
    Book.connection.execute(sql)
    Book.with_writable do
      Book.connection.execute(sql)
    end
  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
    Book.with_writable do
      Book.delete_all
    end
  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.1.0 spec/spec_helper.rb