Skip to content

Commit 928eddb

Browse files
committed
Convert all method names to Symbols to test correctly in Ruby <= 1.8.7
* Object#methods returns Strings in Ruby 1.8.7 and below, so in order to have accurate tests across all Ruby versions they must be all converted to Symbols beforehand.
1 parent c9fbfee commit 928eddb

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

spec/rspec/rails/assertion_adapter_spec.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
describe RSpec::Rails::MinitestAssertionAdapter do
44
include RSpec::Rails::MinitestAssertionAdapter
55

6-
RSpec::Rails::Assertions.public_instance_methods.select{|m| m.to_s =~ /^(assert|flunk|refute)/}.each do |m|
7-
if m.to_s == "assert_equal"
6+
# In Ruby 1.8.7 and below, Object#methods returns Strings instead of Symbols.
7+
# They're all converted to Symbols first to ensure we always compare them
8+
# correctly.
9+
let(:symbolized_methods) { methods.map(&:to_sym) }
10+
11+
RSpec::Rails::Assertions.public_instance_methods.map(&:to_sym).select{|m| m.to_s =~ /^(assert|flunk|refute)/}.each do |m|
12+
if m == :assert_equal
813
it "exposes #{m} to host examples" do
914
assert_equal 3,3
1015
expect do
@@ -13,16 +18,16 @@
1318
end
1419
else
1520
it "exposes #{m} to host examples" do
16-
expect(methods).to include(m)
21+
expect(symbolized_methods).to include(m)
1722
end
1823
end
1924
end
2025

2126
it "does not expose internal methods of Minitest" do
22-
expect(methods).not_to include("_assertions")
27+
expect(symbolized_methods).not_to include(:_assertions)
2328
end
2429

2530
it "does not expose Minitest's message method" do
26-
expect(methods).not_to include("message")
31+
expect(symbolized_methods).not_to include(:message)
2732
end
2833
end

0 commit comments

Comments
 (0)