Sha256: a8c2168288a1492f1fe33b2b175928dfbb81347c7f149d4bb3ff73a32d51dfd3

Contents?: true

Size: 1.11 KB

Versions: 7

Compression:

Stored size: 1.11 KB

Contents

module TestBelt
  module Context

    # This provides a 'context' method on a TestCase.  Use this method
    # to describe the context the TestCase is running in.  This may be
    # a description of the subject or whatever you want.  The context
    # value will be added to the test name of any tests defined using
    # the 'should' method provided by should.rb.  Context descriptions
    # are nested as TestCases are sub-classed.

    # Usage:
    # class SomeTest < Test::Unit::TestCase
    #   include TestBelt::Context
    # end

    def self.included(receiver)
      receiver.send(:extend, ClassMethods)
      receiver.send(:include, InstanceMethods)
    end

    module ClassMethods
      def context(desc)
        raise ArgumentError, "no context description provided" if desc.nil?
        @_testbelt_contexts = [desc]
      end

      def _testbelt_contexts
        ((begin; superclass._testbelt_contexts; rescue NoMethodError; []; end) || []) +
        (@_testbelt_contexts || [])
      end
    end

    module InstanceMethods
      def context
        self.class._testbelt_contexts.join(' ')
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
test-belt-2.0.1 lib/test_belt/context.rb
test-belt-2.0.0 lib/test_belt/context.rb
test-belt-1.1.2 lib/test_belt/context.rb
test-belt-1.1.1 lib/test_belt/context.rb
test-belt-1.1.0 lib/test_belt/context.rb
test-belt-1.0.1 lib/test_belt/context.rb
test-belt-1.0.0 lib/test_belt/context.rb