Created
December 13, 2016 04:20
-
-
Save bryanp/87fb0fdfe045b8e181623e44b611b1a5 to your computer and use it in GitHub Desktop.
Pakyow Test DB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add these to your Gemfile under the `test` group: | |
gem "factory_girl" | |
gem "database_cleaner" | |
# spec_helper.rb should look similar to: | |
require 'pakyow-test' | |
require 'factory_girl' | |
require 'database_cleaner' | |
require_relative '../app/setup' | |
# run the migrations | |
Pakyow::App.after :configure do | |
next if @migrated | |
app_migration_dir = './migrations' | |
begin | |
Sequel.extension :migration | |
Sequel::Migrator.check_current(config.app.db, app_migration_dir) | |
rescue Sequel::Migrator::NotCurrentError | |
Pakyow.logger.info 'migrations not current; running them now' | |
Sequel::Migrator.run(config.app.db, app_migration_dir) | |
end | |
@migrated = true | |
end | |
# disable the logger | |
module Pakyow | |
class << self | |
def logger | |
Rack::NullLogger.new(self) | |
end | |
end | |
end | |
# setup pakyow test helpers | |
Pakyow::TestHelp.setup | |
# include factory girl definitions | |
FactoryGirl.find_definitions | |
RSpec.configure do |config| | |
config.include Pakyow::TestHelp::Helpers | |
config.include FactoryGirl::Syntax::Methods | |
config.before :suite do | |
begin | |
FactoryGirl.lint | |
ensure | |
DatabaseCleaner.strategy = :transaction | |
DatabaseCleaner.clean_with(:truncation) | |
end | |
end | |
config.around :each do |example| | |
DatabaseCleaner.cleaning do | |
example.run | |
end | |
end | |
end | |
# makes sequel work with factory girl | |
Sequel::Model.send :alias_method, :save!, :save |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment