Permalink
Browse files

Extract method declaration regexp into a constant

  • Loading branch information...
1 parent 492e6b5 commit 83d0232304a16fc7431b6778f80e42cc073b3600 @pabloh pabloh committed Apr 12, 2013
Showing with 3 additions and 1 deletion.
  1. +3 −1 railties/lib/rails/generators/testing/assertions.rb
@@ -2,6 +2,8 @@ module Rails
module Generators
module Testing
module Assertions
+ METHOD_DECLARATION_REGEXP = /(\s+)def #{method}(\(.+\))?(.*?)\n\1end/m
+
# Asserts a given file exists. You need to supply an absolute path or a path relative
# to the configured destination:
#
@@ -96,7 +98,7 @@ def assert_class_method(method, content, &block)
# end
# end
def assert_instance_method(method, content)
- assert content =~ /(\s+)def #{method}(\(.+\))?(.*?)\n\1end/m, "Expected to have method #{method}"
+ assert content =~ METHOD_DECLARATION_REGEXP, "Expected to have method #{method}"
yield $3.strip if block_given?
end
alias :assert_method :assert_instance_method

0 comments on commit 83d0232

Please sign in to comment.