Skip to content

Commit a0c52b0

Browse files
sarahmeiSam Phippen
authored andcommitted
Use klass.method_defined? instead of .methods.include? because it works the same way in Ruby 1.8 & 1.9+ (plus is faster).
1 parent 88cd444 commit a0c52b0

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lib/rspec/rails/view_spec_methods.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ module ViewSpecMethods
99
# When class is `::ActionView::TestCase::TestController`, these methods
1010
# are exposed in view specs on the `controller` object.
1111
def add_to(klass)
12-
return if klass.instance_methods.include?(:extra_params) && klass.instance_methods.include?(:extra_params=)
13-
return if klass.instance_methods.include?("extra_params") && klass.instance_methods.include?("extra_params=")
12+
return if klass.method_defined?(:extra_params) && klass.method_defined?(:extra_params=)
1413

1514
klass.module_exec do
1615
# Set any extra parameters that rendering a URL for this view
@@ -46,10 +45,9 @@ def extra_params
4645

4746
# Removes methods `extra_params=` and `extra_params` from the indicated class.
4847
def remove_from(klass)
49-
methods = klass.instance_methods
5048
klass.module_exec do
51-
undef extra_params= if methods.include?(:extra_params=) || methods.include?("extra_params=")
52-
undef extra_params if methods.include?(:extra_params) || methods.include?("extra_params")
49+
undef extra_params= if klass.method_defined?(:extra_params=)
50+
undef extra_params if klass.method_defined?(:extra_params)
5351
end
5452
end
5553
end

0 commit comments

Comments
 (0)