mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Extract test method declaration
This commit is contained in:
parent
728606df91
commit
ae9581e0f3
1 changed files with 21 additions and 0 deletions
21
activesupport/lib/active_support/testing/declarative.rb
Normal file
21
activesupport/lib/active_support/testing/declarative.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module ActiveSupport
|
||||
module Testing
|
||||
module Declarative
|
||||
# test "verify something" do
|
||||
# ...
|
||||
# end
|
||||
def test(name, &block)
|
||||
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
||||
defined = instance_method(test_name) rescue false
|
||||
raise "#{test_name} is already defined in #{self}" if defined
|
||||
if block_given?
|
||||
define_method(test_name, &block)
|
||||
else
|
||||
define_method(test_name) do
|
||||
flunk "No implementation provided for #{name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue