-
-
Save adamrobbie/5561983 to your computer and use it in GitHub Desktop.
This file contains 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
ENV["RAILS_ENV"] = "test" | |
require File.expand_path('../../config/environment', __FILE__) | |
require File.dirname(__FILE__) + '/blueprints' | |
require 'faker' | |
require 'rails/test_help' | |
require 'minitest/autorun' | |
require 'minitest/pride' | |
class MiniTest::Unit::TestCase | |
include MiniTest::ActiveRecordAssertions | |
DatabaseCleaner.strategy = :transaction | |
def setup | |
DatabaseCleaner.start | |
end | |
def teardown | |
DatabaseCleaner.clean | |
end | |
end | |
class MiniTest::Spec | |
include ActiveSupport::Testing::SetupAndTeardown | |
alias :method_name :__name__ if defined? :__name__ | |
def build_message(*args) | |
args[1].gsub(/\?/, '%s') % args[2..-1] | |
end | |
end | |
class ControllerSpec < MiniTest::Spec | |
include ActionController::TestCase::Behavior | |
include Devise::TestHelpers | |
include Rails.application.routes.url_helpers | |
# Rails 3.2 determines the controller class by matching class names that end in Test | |
# This overides the #determine_default_controller_class method to allow you use Controller | |
# class names in your describe argument | |
# cf: https://github.com/rawongithub/minitest-rails/blob/gemspec/lib/minitest/rails/controller.rb | |
def self.determine_default_controller_class(name) | |
if name.match(/.*(?:^|::)(\w+Controller)/) | |
$1.safe_constantize | |
else | |
super(name) | |
end | |
end | |
before do | |
@controller = self.class.name.match(/((.*)Controller)/)[1].constantize.new | |
@routes = Rails.application.routes | |
end | |
subject do | |
@controller | |
end | |
end | |
# Functional tests = describe ***Controller | |
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