Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add Rails 4 support. #19

Merged
merged 1 commit into from

3 participants

@caike

Mix shoulda-context in MiniTest::Spec if present and part of ActiveSupport::TestCase's ancestors.

This is a simple suggestion for adding support to upcoming Rails 4, which now has its base test class inheriting from MiniTest::Spec instead of Test::Unit::TestCase.

I'm not expecting this pull-request to merged right away, as it doesn't include any tests or Appraisal support for Rails 4, but I'd love to hear your thoughts on this approach.

@caike caike Add Rails 4 support.
Mix shoulda-context in MiniTest::Spec if present and part of ActiveSupport::TestCase's ancestors.
350e852
@Neku

When this will be merged?

@travisjeffery travisjeffery merged commit bd69be2 into from
@travisjeffery
Collaborator

Done.

@Neku

That was fast :+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 21, 2012
  1. @caike

    Add Rails 4 support.

    caike authored
    Mix shoulda-context in MiniTest::Spec if present and part of ActiveSupport::TestCase's ancestors.
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 6 deletions.
  1. +25 −6 lib/shoulda/context.rb
View
31 lib/shoulda/context.rb
@@ -1,15 +1,34 @@
-if !defined?(Test::Unit::TestCase)
- require 'test/unit/testcase'
+begin
+ # if present, then also loads MiniTest::Spec
+ ActiveSupport::TestCase
+rescue
end
+if defined?([ActiveSupport::TestCase, MiniTest::Spec]) && (ActiveSupport::TestCase.ancestors.include?(MiniTest::Spec))
+ base_test_case = MiniTest::Spec
+else
+ if !defined?(Test::Unit::TestCase)
+ require 'test/unit/testcase'
+ end
+ base_test_case = Test::Unit::TestCase
+end
+
+
require 'shoulda/context/version'
require 'shoulda/context/proc_extensions'
require 'shoulda/context/assertions'
require 'shoulda/context/context'
require 'shoulda/context/autoload_macros'
-class Test::Unit::TestCase
- include Shoulda::Context::Assertions
- include Shoulda::Context::InstanceMethods
- extend Shoulda::Context::ClassMethods
+
+module ShouldaContextLoadable
+ def self.included(base)
+ base.class_eval do
+ include Shoulda::Context::Assertions
+ include Shoulda::Context::InstanceMethods
+ end
+ base.extend(Shoulda::Context::ClassMethods)
+ end
end
+
+base_test_case.class_eval { include ShouldaContextLoadable }
Something went wrong with that request. Please try again.