Module: JakeWendt::TestWithVerbosity::ClassMethods
- Defined in:
- lib/test_with_verbosity.rb
Instance Method Summary collapse
-
#test(name, &block) ⇒ Object
activesupport-4.1.4/lib/active_support/testing/declarative.rb.
-
#test_with_verbosity(name, &block) ⇒ Object
NOW I use W and converted non-word chars to a underscores (no more groups).
Instance Method Details
#test(name, &block) ⇒ Object
activesupport-4.1.4/lib/active_support/testing/declarative.rb
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/test_with_verbosity.rb', line 18 def test(name, &block) #test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym test_name = "test_#{name.gsub(/\W/,'_')}".to_sym # NEED THIS 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) # # could possibly do something like this, but I can't seem to figure out # how to call a passed block correctly. # # define_method(test_name) do # print "\n#{self.class.name.gsub(/Test$/,'').titleize} #{name}: " # block.call # FAIL # end else define_method(test_name) do flunk "No implementation provided for #{name}" end end end |
#test_with_verbosity(name, &block) ⇒ Object
NOW I use W and converted non-word chars to a underscores (no more groups)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/test_with_verbosity.rb', line 47 def test_with_verbosity(name,&block) test_without_verbosity(name,&block) test_name = "test_#{name.gsub(/\W/,'_')}".to_sym define_method("_#{test_name}_with_verbosity") do print "\n#{self.class.name.gsub(/Test$/,'').titleize} #{name}: " send("_#{test_name}_without_verbosity") end # # can't do this... # alias_method_chain test_name, :verbosity # end up with 2 methods that begin # with 'test_' so they both get run # alias_method "_#{test_name}_without_verbosity".to_sym, test_name alias_method test_name, "_#{test_name}_with_verbosity".to_sym end |