Skip to content

Instantly share code, notes, and snippets.

@route
Created September 28, 2012 08:58
Show Gist options
  • Save route/3798746 to your computer and use it in GitHub Desktop.
Save route/3798746 to your computer and use it in GitHub Desktop.
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'bundler/setup' unless defined?(Bundler)
require 'minitest/autorun'
# Database cleaner strategy
require 'database_cleaner'
DatabaseCleaner.strategy = :transaction
class MiniTest::Spec
before(:each) { DatabaseCleaner.start }
after(:each) { DatabaseCleaner.clean }
end
# Turn factory girl on
require 'factory_girl'
FactoryGirl.find_definitions
class MiniTest::Spec
include FactoryGirl::Syntax::Methods
end
# Turn rspec mocks on
require 'rspec/mocks'
MiniTest::Unit::TestCase.add_setup_hook do |test_case|
RSpec::Mocks.setup(test_case)
end
MiniTest::Unit::TestCase.add_teardown_hook do |test_case|
begin
RSpec::Mocks.verify
ensure
RSpec::Mocks.teardown
end
end
# Controller test
require 'action_controller/test_case'
class ControllerSpec < MiniTest::Spec
include ActiveSupport::Testing::SetupAndTeardown
include ActionController::TestCase::Behavior
include ActiveSupport::Testing::Assertions
include Rails.application.routes.url_helpers
# https://github.com/blowmage/minitest-rails/issues/12
def build_message(*args)
args[1].gsub(/\?/, '%s') % args[2..-1]
end
before do
@routes = Rails.application.routes
end
end
# Test subjects ending with 'Controller' are treated as functional tests
# e.g. describe TestController do ...
MiniTest::Spec.register_spec_type( /Controller$/, ControllerSpec )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment