Module: Hermes::Context
- Included in:
- IntegrationCase
- Defined in:
- lib/hermes/context.rb
Overview
Add context support to AS::TestCase.
Instance Method Summary collapse
- #context(name, &block) ⇒ Object
- #context_buffer ⇒ Object
- #context_list ⇒ Object
- #test(name) ⇒ Object
Instance Method Details
#context(name, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hermes/context.rb', line 16 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 |
#context_buffer ⇒ Object
8 9 10 |
# File 'lib/hermes/context.rb', line 8 def context_buffer @context_buffer ||= [] end |
#context_list ⇒ Object
4 5 6 |
# File 'lib/hermes/context.rb', line 4 def context_list @@context_list ||= [] end |
#test(name) ⇒ Object
12 13 14 |
# File 'lib/hermes/context.rb', line 12 def test(name) super("#{self.context_buffer.join(" ")} #{name}".strip) end |