Skip to content

Commit 4445423

Browse files
committed
Merge pull request #1512 from Ferdy89/do_not_leak_test_unit_methods_after_rails_4
Do not leak TestUnit specific methods after Rails 4
2 parents d108631 + 255f08d commit 4445423

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/rspec/rails/adapters.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def assertion_method_names
201201
select do |m|
202202
m.to_s =~ /^(assert|flunk|refute)/
203203
end
204-
methods + [:build_message]
204+
methods + test_unit_specific_methods
205205
end
206206

207207
def define_assertion_delegators
@@ -211,6 +211,18 @@ def define_assertion_delegators
211211
end
212212
end
213213
end
214+
215+
# Starting on Rails 4, Minitest is the default testing framework so no
216+
# need to add TestUnit specific methods.
217+
if ::Rails::VERSION::STRING >= '4.0.0'
218+
def test_unit_specific_methods
219+
[]
220+
end
221+
else
222+
def test_unit_specific_methods
223+
[:build_message]
224+
end
225+
end
214226
end
215227

216228
class AssertionDelegator

spec/rspec/rails/assertion_adapter_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,16 @@
2525
it "does not expose Minitest's message method" do
2626
expect(methods).not_to include("message")
2727
end
28+
29+
if ::Rails::VERSION::STRING >= '4.0.0'
30+
# In Ruby <= 1.8.7 Object#methods returns Strings instead of Symbols. They
31+
# are all converted to Symbols to ensure we always compare them correctly.
32+
it 'does not leak TestUnit specific methods into the AssertionDelegator' do
33+
expect(methods.map(&:to_sym)).to_not include(:build_message)
34+
end
35+
else
36+
it 'includes methods required by TestUnit into the AssertionDelegator' do
37+
expect(methods.map(&:to_sym)).to include(:build_message)
38+
end
39+
end
2840
end

0 commit comments

Comments
 (0)