Last active
December 23, 2015 20:49
-
-
Save danielevans/6692625 to your computer and use it in GitHub Desktop.
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
ENV["RAILS_ENV"] ||= "test" | |
require File.expand_path('../../config/environment', __FILE__) | |
require 'rails/test_help' | |
require "minitest/spec" | |
# require "mocha/setup" | |
# require "turn/autorun" | |
class ActiveSupport::TestCase | |
ActiveRecord::Migration.check_pending! | |
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. | |
# | |
# Note: You'll currently still have to declare fixtures explicitly in integration tests | |
# -- they do not yet inherit this setting | |
# fixtures :all | |
# Add more helper methods to be used by all tests here... | |
extend MiniTest::Spec::DSL | |
# include FactoryGirl::Syntax::Methods | |
class << self | |
remove_method :describe | |
end | |
register_spec_type self do |desc| | |
desc < ActiveRecord::Base if desc.is_a? Class | |
end | |
end |
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
require 'test_helper' | |
# class UsersControllerTest < ActionController::TestCase | |
# test "raises an error if no user with that unique token is found" do | |
# lambda { | |
# get(:unsubscribe, :unique_token => "bob") | |
# }.must_raise ActiveRecord::RecordNotFound | |
# end | |
# end | |
describe UsersController do | |
it "raises an error if no user with that unique token is found" do | |
lambda { | |
get(:unsubscribe, :unique_token => "bob") | |
}.must_raise ActiveRecord::RecordNotFound | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The reason the controller tests don't work when using the spec DSL is that you haven't told Minitest to use ActionController::TestCase when describing a controller. You need to call
register_spec_type
and get that registered.ActionController::TestCase does a bunch of name matching to figure out which controller is being tested and creating an instance of it for the tests. But AC::TC never intended to do this for test classes that were created by the spec DSL. You may still have problems when using describe because of how the class that
describe
creates is named. The best way around that is to override how AC::TC derives the class.There is more to do if you want to use the spec DSL for helper/view tests, or integration tests. You can either look at the source of minitest-rails and copy that code to your project, or you can make your life much easier and simply include it in your helper.