Permalink
Browse files

Merge branch 'switch-from-test-unit-to-minitest'

  • Loading branch information...
alindeman committed Aug 13, 2013
2 parents 710fb67 + 68c5204 commit f4dd001ccaf423a0561d7f56de919dbd5ef922e7
View
@@ -6,6 +6,10 @@ Breaking Changes for 3.0.0:
* Extracts `autotest` and `autotest-rails` support to `rspec-autotest` gem.
(Andy Lindeman)
+Enhancements
+
+* Supports Rails 4.1 and Minitest 5. (Patrick Van Stee)
+
Bug fixes
* Fixes "warning: instance variable @orig\_routes not initialized" raised by
@@ -11,7 +11,12 @@ Feature: ActiveRecord::Relation match array
describe Widget do
let!(:widgets) { Array.new(3) { Widget.create } }
- subject { Widget.scoped }
+
+ if ::Rails::VERSION::STRING >= '4'
+ subject { Widget.all }
+ else
+ subject { Widget.scoped }
+ end
it "returns all widgets in any order" do
expect(subject).to match_array(widgets)
@@ -1,14 +1,23 @@
require 'delegate'
require 'active_support/concern'
-require 'test/unit/assertions'
module RSpec
module Rails
+ if ::Rails::VERSION::STRING >= '4.1.0'
+ gem 'minitest'
+ require 'minitest/assertions'
+ Assertions = Minitest::Assertions
+ else
+ require 'test/unit/assertions'
+ Assertions = Test::Unit::Assertions
+ end
+
+ # @api private
class AssertionDelegator < Module
# @api private
def initialize(*assertion_modules)
assertion_class = Class.new(SimpleDelegator) do
- include Test::Unit::Assertions
+ include ::RSpec::Rails::Assertions
include ::RSpec::Rails::MinitestCounters
assertion_modules.each { |mod| include mod }
end
@@ -38,8 +47,10 @@ def #{method}(*args, &block)
end
end
- # MiniTest::Unit::LifecycleHooks
- module MiniTestLifecycleAdapter
+ # Adapts example groups for `Minitest::Test::LifecycleHooks`
+ #
+ # @api private
+ module MinitestLifecycleAdapter
extend ActiveSupport::Concern
included do |group|
@@ -79,6 +90,7 @@ def assertions=(assertions)
end
end
+ # @api private
module SetupAndTeardownAdapter
extend ActiveSupport::Concern
@@ -112,7 +124,8 @@ def method_name
end
end
- module TestUnitAssertionAdapter
+ # @private
+ module MinitestAssertionAdapter
extend ActiveSupport::Concern
module ClassMethods
@@ -122,7 +135,7 @@ module ClassMethods
# examples without exposing non-assertion methods in Test::Unit or
# Minitest.
def assertion_method_names
- Test::Unit::Assertions.public_instance_methods.select{|m| m.to_s =~ /^(assert|flunk)/} +
+ ::RSpec::Rails::Assertions.public_instance_methods.select{|m| m.to_s =~ /^(assert|flunk|refute)/} +
[:build_message]
end
@@ -138,8 +151,9 @@ def #{m}(*args, &block)
end
end
+ # @api private
class AssertionDelegator
- include Test::Unit::Assertions
+ include ::RSpec::Rails::Assertions
include ::RSpec::Rails::MinitestCounters
end
@@ -152,5 +166,11 @@ def assertion_delegator
define_assertion_delegators
end
end
+
+ # Backwards compatibility. It's unlikely that anyone is using this
+ # constant, but we had forgotten to mark it as `@private` earlier
+ #
+ # @api private
+ TestUnitAssertionAdapter = MinitestAssertionAdapter
end
end
@@ -7,8 +7,8 @@ module Rails
module RailsExampleGroup
extend ActiveSupport::Concern
include RSpec::Rails::SetupAndTeardownAdapter
- include RSpec::Rails::MiniTestLifecycleAdapter if ::Rails::VERSION::STRING >= '4'
- include RSpec::Rails::TestUnitAssertionAdapter
+ include RSpec::Rails::MinitestLifecycleAdapter if ::Rails::VERSION::STRING >= '4'
+ include RSpec::Rails::MinitestAssertionAdapter
include RSpec::Rails::Matchers
end
end
@@ -4,8 +4,8 @@ module Rails
module FixtureSupport
extend ActiveSupport::Concern
include RSpec::Rails::SetupAndTeardownAdapter
- include RSpec::Rails::MiniTestLifecycleAdapter if ::ActiveRecord::VERSION::STRING > '4'
- include RSpec::Rails::TestUnitAssertionAdapter
+ include RSpec::Rails::MinitestLifecycleAdapter if ::ActiveRecord::VERSION::STRING > '4'
+ include RSpec::Rails::MinitestAssertionAdapter
include ActiveRecord::TestFixtures
included do
View
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
end
s.add_development_dependency 'rake', '~> 10.0.0'
- s.add_development_dependency 'cucumber', '~> 1.1.9'
+ s.add_development_dependency 'cucumber', '~> 1.3.5'
s.add_development_dependency 'aruba', '~> 0.4.11'
s.add_development_dependency 'ZenTest', '4.9.0'
s.add_development_dependency 'ammeter', '0.2.5'
@@ -1,9 +1,9 @@
require "spec_helper"
-describe RSpec::Rails::TestUnitAssertionAdapter do
- include RSpec::Rails::TestUnitAssertionAdapter
+describe RSpec::Rails::MinitestAssertionAdapter do
+ include RSpec::Rails::MinitestAssertionAdapter
- Test::Unit::Assertions.public_instance_methods.select{|m| m.to_s =~ /^(assert|flunk)/}.each do |m|
+ RSpec::Rails::Assertions.public_instance_methods.select{|m| m.to_s =~ /^(assert|flunk|refute)/}.each do |m|
if m.to_s == "assert_equal"
it "exposes #{m} to host examples" do
assert_equal 3,3
@@ -18,11 +18,11 @@
end
end
- it "does not expose internal methods of MiniTest" do
+ it "does not expose internal methods of Minitest" do
methods.should_not include("_assertions")
end
- it "does not expose MiniTest's message method" do
+ it "does not expose Minitest's message method" do
methods.should_not include("message")
end
end
@@ -3,7 +3,7 @@
describe RSpec::Rails::AssertionDelegator do
it "provides a module that delegates assertion methods to an isolated class" do
klass = Class.new {
- include RSpec::Rails::AssertionDelegator.new(Test::Unit::Assertions)
+ include RSpec::Rails::AssertionDelegator.new(RSpec::Rails::Assertions)
}
expect(klass.new).to respond_to(:assert)
@@ -1,10 +1,10 @@
require "spec_helper"
-describe RSpec::Rails::MiniTestLifecycleAdapter do
+describe RSpec::Rails::MinitestLifecycleAdapter do
it "invokes minitest lifecycle hooks at the appropriate times" do
invocations = []
- example_group = RSpec::Core::ExampleGroup.describe("MiniTestHooks") do
- include RSpec::Rails::MiniTestLifecycleAdapter
+ example_group = RSpec::Core::ExampleGroup.describe("MinitestHooks") do
+ include RSpec::Rails::MinitestLifecycleAdapter
define_method(:before_setup) { invocations << :before_setup }
define_method(:after_setup) { invocations << :after_setup }
@@ -360,9 +360,8 @@
end
describe "ActiveModel Lint tests" do
- require 'test/unit/assertions'
require 'active_model/lint'
- include RSpec::Rails::TestUnitAssertionAdapter
+ include RSpec::Rails::MinitestAssertionAdapter
include ActiveModel::Lint::Tests
# to_s is to support ruby-1.9

0 comments on commit f4dd001

Please sign in to comment.