Sha256: 8ef91050a4a5f2c16dec43895082b2d35f2c8bf4c413cae4e86a2b42c3e47c3c

Contents?: true

Size: 1.81 KB

Versions: 14

Compression:

Stored size: 1.81 KB

Contents

require 'assert/macro'
require 'assert/suite'
require 'assert/test'

module Assert; end
class Assert::Context

  module TestDSL

    def test(desc_or_macro, called_from=nil, first_caller=nil, &block)
      if desc_or_macro.kind_of?(Assert::Macro)
        instance_eval(&desc_or_macro)
      elsif block_given?
        ci = Assert::Suite::ContextInfo.new(self, called_from, first_caller || caller.first)
        test_name = desc_or_macro

        # create a test from the given code block
        self.suite.tests << Assert::Test.new(test_name, ci, self.suite.config, &block)
      else
        test_eventually(desc_or_macro, called_from, first_caller || caller.first, &block)
      end
    end

    def test_eventually(desc_or_macro, called_from=nil, first_caller=nil, &block)
      ci = Assert::Suite::ContextInfo.new(self, called_from, first_caller || caller.first)
      test_name = desc_or_macro.kind_of?(Assert::Macro) ? desc_or_macro.name : desc_or_macro
      skip_block = block.nil? ? Proc.new { skip 'TODO' } : Proc.new { skip }

      # create a test from a proc that just skips
      self.suite.tests << Assert::Test.new(test_name, ci, self.suite.config, &skip_block)
    end
    alias_method :test_skip, :test_eventually

    def should(desc_or_macro, called_from=nil, first_caller=nil, &block)
      if !desc_or_macro.kind_of?(Assert::Macro)
        desc_or_macro = "should #{desc_or_macro}"
      end
      test(desc_or_macro, called_from, first_caller || caller.first, &block)
    end

    def should_eventually(desc_or_macro, called_from=nil, first_caller=nil, &block)
      if !desc_or_macro.kind_of?(Assert::Macro)
        desc_or_macro = "should #{desc_or_macro}"
      end
      test_eventually(desc_or_macro, called_from, first_caller || caller.first, &block)
    end
    alias_method :should_skip, :should_eventually

  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
assert-2.14.0 lib/assert/context/test_dsl.rb
assert-2.13.0 lib/assert/context/test_dsl.rb
assert-2.12.2 lib/assert/context/test_dsl.rb
assert-2.12.1 lib/assert/context/test_dsl.rb
assert-2.12.0 lib/assert/context/test_dsl.rb
assert-2.11.0 lib/assert/context/test_dsl.rb
assert-2.10.1 lib/assert/context/test_dsl.rb
assert-2.10.0 lib/assert/context/test_dsl.rb
assert-2.9.0 lib/assert/context/test_dsl.rb
assert-2.8.0 lib/assert/context/test_dsl.rb
assert-2.7.1 lib/assert/context/test_dsl.rb
assert-2.7.0 lib/assert/context/test_dsl.rb
assert-2.6.0 lib/assert/context/test_dsl.rb
assert-2.5.0 lib/assert/context/test_dsl.rb