Skip to content

Commit

Permalink
Wrap T/U and/or MiniTest assertions in a separate scope from that of the
Browse files Browse the repository at this point in the history
example.
  • Loading branch information
dchelimsky committed Aug 9, 2010
1 parent 11e368e commit 8660031
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
38 changes: 32 additions & 6 deletions lib/rspec/rails/adapters.rb
Expand Up @@ -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 changes: 28 additions & 0 deletions spec/rspec/rails/assertion_adapter_spec.rb
@@ -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

0 comments on commit 8660031

Please sign in to comment.