Sha256: 1b08802c934b4c243489ef2179f320ce96c396f96ac66c3f9610fa7c9154aa3e

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

require "bundler"

ENV["RAILS_ENV"] = "test"

RSpec.configure do |config|
  config.around(:each) do |example|
    Dir.chdir("spec/dummy") do
      example.run
    end
  end

  config.before(:suite) do
    Dir.chdir("spec/dummy") do
      system <<~CMD
        git init -b master 1>/dev/null &&
        git config user.email "fx@example.com"
        git config user.name "Fx"
        git add -A &&
        git commit --no-gpg-sign --message 'initial' 1>/dev/null
      CMD
    end
  end

  config.after(:suite) do
    Dir.chdir("spec/dummy") do
      ActiveRecord::Base.connection.disconnect!
      system <<~CMD
        echo &&
        rake db:environment:set db:drop db:create 1>/dev/null &&
        git add -A &&
        git reset --hard HEAD 1>/dev/null &&
        rm -rf .git/ 1>/dev/null
      CMD
    end
  end

  def successfully(command)
    `RAILS_ENV=test #{command}`
    expect($?.exitstatus).to eq(0), "'#{command}' was unsuccessful"
  end

  def write_function_definition(file, contents)
    write_definition(file, contents, "functions")
  end

  def write_trigger_definition(file, contents)
    write_definition(file, contents, "triggers")
  end

  def write_definition(file, contents, directory)
    File.open("db/#{directory}/#{file}.sql", File::WRONLY) do |definition|
      definition.truncate(0)
      definition.write(contents)
    end
  end

  def verify_identical_definitions(def_a, def_b)
    successfully "cmp #{def_a} #{def_b}"
  end

  def execute(command)
    ActiveRecord::Base.connection.execute(command).first
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fx-0.9.0 spec/acceptance_helper.rb