-
-
Save snooc/4569840 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 'rails/test_help' | |
require 'minitest/autorun' | |
require 'minitest/pride' | |
require 'capybara/rails' | |
class MiniTest::Spec | |
include ActiveSupport::Testing::SetupAndTeardown | |
include ActiveSupport::Testing::Assertions | |
include ActiveRecord::TestFixtures | |
alias :method_name :__name__ if defined? :__name__ | |
self.fixture_path = File.join( Rails.root, 'test', 'fixtures' ) | |
class << self | |
alias :context :describe | |
end | |
# cf: https://github.com/blowmage/minitest-rails/issues/12 | |
def build_message(*args) | |
args[1].gsub(/\?/, '%s') % args[2..-1] | |
end | |
end | |
class ControllerSpec < MiniTest::Spec | |
include Rails.application.routes.url_helpers | |
include ActionController::TestCase::Behavior | |
# 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 ) | |
class AcceptanceSpec < MiniTest::Spec | |
include Rails.application.routes.url_helpers | |
include Capybara::DSL | |
before do | |
@routes = Rails.application.routes | |
end | |
end | |
# Integration/Acceptance tests = describe '*** Integration' | |
MiniTest::Spec.register_spec_type( /Integration$/, AcceptanceSpec ) | |
class HelperTest < MiniTest::Spec | |
include ActionView::TestCase::Behavior | |
end | |
# Helper tests = describe '*** Helper' | |
MiniTest::Spec.register_spec_type( /Helper$/, HelperTest ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment