module Hermes # Add context support to AS::TestCase. module Context def context_list @@context_list ||= [] end def context_buffer @context_buffer ||= [] end def test(name) super("#{self.context_buffer.join(" ")} #{name}".strip) end def context(name, &block) klass = Class.new(self) klass.context_buffer.concat self.context_buffer klass.context_buffer << name # Care about Rails tests in nested contexts # Extracted this from github.com/jm/context klass.tests($1.constantize) if self < ActiveSupport::TestCase && self.name =~ /^(.*(Controller|Helper|Mailer))Test/ # Undefine parent methods so they don't get executed twice klass.instance_methods.grep(/^test_/).each { |m| klass.send(:undef_method, m) } klass.class_eval(&block) self.context_list << klass Object.const_set("TestContext#{name.camelize.gsub(/\W/,'')}#{klass.object_id.abs}", klass) klass end end end ActiveSupport::TestCase.extend Hermes::Context