Sha256: 150dacbf5dfb010956eefd71a830b5943a63bb64bdcaed52862387eaabf1a470

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

require 'rspec-set'
require 'database_cleaner'
require 'active_record'

require_relative './fixtures/non_active_record_class'
require_relative './fixtures/active_record_class_example'

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

  config.before(:suite) do
    setup_database
  end

  config.after(:suite) do
    destroy_database
  end
  
  config.before(:each) do
    DatabaseCleaner.strategy = :transaction
    DatabaseCleaner.start
  end

  config.after(:each) do
    DatabaseCleaner.clean
  end

  config.order = 'random'
end

def db
  ActiveRecord::Base.connection
end

def setup_database
  ActiveRecord::Base.establish_connection(
    :adapter => 'sqlite3',
    :database => 'spec/db/rspec-set-test.sqlite3'
  )

  db.tables.each do |table|
    db.execute("DROP TABLE #{table}")
  end

  Dir[File.join(File.dirname(__FILE__), "db/migrate", "*.rb")].each do |f| 
    require f
    migration = Kernel.const_get(f.split("/").last.split(".rb").first.gsub(/\d+/, "").split("_").collect{|w| w.strip.capitalize}.join())
    migration.migrate(:up)
  end
end

def destroy_database
  db.tables.each do |table|
    db.execute("DROP TABLE #{table}")
  end
end

def setup_for_error_checking(klass)
  before do
    @orig_stderr = $stderr
    $stderr = StringIO.new
  end

  set(:my_object) { klass.create(name: 'Test Name') }

  after do
    $stderr = @orig_stderr
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rspec-set-0.1.3 spec/spec_helper.rb
rspec-set-0.1.2 spec/spec_helper.rb
rspec-set-0.1.1 spec/spec_helper.rb