Permalink
Browse files

Create facade for switching assertion libraries

This is in preparation of requiring different testing libraries based on
the rails version.
  • Loading branch information...
vanstee authored and alindeman committed Jul 25, 2013
1 parent 710fb67 commit 2d21e673e6b7aa1e2786422de6e50eb964c7a5f3
@@ -1,14 +1,18 @@
require 'delegate'
require 'active_support/concern'
-require 'test/unit/assertions'
module RSpec
module Rails
+ module Assertions
+ require 'test/unit/assertions'
+ include Test::Unit::Assertions
+ end
+
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
@@ -122,7 +126,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)/} +
[:build_message]
end
@@ -139,7 +143,7 @@ def #{m}(*args, &block)
end
class AssertionDelegator
- include Test::Unit::Assertions
+ include ::RSpec::Rails::Assertions
include ::RSpec::Rails::MinitestCounters
end
@@ -3,7 +3,7 @@
describe RSpec::Rails::TestUnitAssertionAdapter do
include RSpec::Rails::TestUnitAssertionAdapter
- 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)/}.each do |m|
if m.to_s == "assert_equal"
it "exposes #{m} to host examples" do
assert_equal 3,3
@@ -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)
@@ -360,7 +360,6 @@
end
describe "ActiveModel Lint tests" do
- require 'test/unit/assertions'
require 'active_model/lint'
include RSpec::Rails::TestUnitAssertionAdapter
include ActiveModel::Lint::Tests

0 comments on commit 2d21e67

Please sign in to comment.