Skip to content

Do not leak TestUnit specific methods after Rails 4 #1512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/rspec/rails/adapters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def assertion_method_names
select do |m|
m.to_s =~ /^(assert|flunk|refute)/
end
methods + [:build_message]
methods + test_unit_specific_methods
end

def define_assertion_delegators
Expand All @@ -211,6 +211,18 @@ def define_assertion_delegators
end
end
end

# Starting on Rails 4, Minitest is the default testing framework so no
# need to add TestUnit specific methods.
if ::Rails::VERSION::STRING >= '4.0.0'
def test_unit_specific_methods
[]
end
else
def test_unit_specific_methods
[:build_message]
end
end
end

class AssertionDelegator
Expand Down
12 changes: 12 additions & 0 deletions spec/rspec/rails/assertion_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@
it "does not expose Minitest's message method" do
expect(methods).not_to include("message")
end

if ::Rails::VERSION::STRING >= '4.0.0'
# In Ruby <= 1.8.7 Object#methods returns Strings instead of Symbols. They
# are all converted to Symbols to ensure we always compare them correctly.
it 'does not leak TestUnit specific methods into the AssertionDelegator' do
expect(methods.map(&:to_sym)).to_not include(:build_message)
end
else
it 'includes methods required by TestUnit into the AssertionDelegator' do
expect(methods.map(&:to_sym)).to include(:build_message)
end
end
end