Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: rspec/rspec-rails
...
head fork: rspec/rspec-rails
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
38 lib/rspec/rails/adapters.rb
View
@@ -15,21 +15,47 @@ def teardown(*methods)
methods.each {|method| after { send method } }
end
end
+
+ module InstanceMethods
+ def method_name
+ @example
+ end
+ end
end
module TestUnitAssertionAdapter
extend ActiveSupport::Concern
- def method_name
- @example
+
+ class AssertionDelegate
+ include Test::Unit::Assertions
end
- include Test::Unit::Assertions
+ module ClassMethods
+ def assertion_method_names
+ Test::Unit::Assertions.public_instance_methods.select{|m| m.to_s =~ /^assert/} +
+ [:build_message]
+ end
- included do
- before do
- @_result = Struct.new(:add_assertion).new
+ def define_assertion_delegators
+ assertion_method_names.each do |m|
+ class_eval <<-CODE
+ def #{m}(*args, &block)
+ assertion_delegate.send :#{m}, *args, &block
+ end
+ CODE
+ end
end
end
+
+ module InstanceMethods
+ def assertion_delegate
+ @assertion_delegate ||= AssertionDelegate.new
+ end
+ end
+
+ included do
+ define_assertion_delegators
+ end
end
end
end
28 spec/rspec/rails/assertion_adapter_spec.rb
View
@@ -0,0 +1,28 @@
+require "spec_helper"
+
+describe RSpec::Rails::TestUnitAssertionAdapter do
+ include RSpec::Rails::TestUnitAssertionAdapter
+
+ Test::Unit::Assertions.public_instance_methods.select{|m| m.to_s =~ /^assert/}.each do |m|
+ if m.to_s == "assert_equal"
+ it "exposes #{m} to host examples" do
+ assert_equal 3,3
+ expect do
+ assert_equal 3,4
+ end.to raise_error(ActiveSupport::TestCase::Assertion)
+ end
+ else
+ it "exposes #{m} to host examples" do
+ methods.should include(m)
+ end
+ end
+ end
+
+ it "does not expose internal methods of MiniTest" do
+ methods.should_not include("_assertions")
+ end
+
+ it "does not expose MiniTest's message method" do
+ methods.should_not include("message")
+ end
+end

No commit comments for this range

Something went wrong with that request. Please try again.