Sha256: 8dd4a3ab0cee49e1097048220b2d90997a73b6f09932aa0a795c28ca3dc8db95

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

require 'test/unit'
require 'matchy'
require 'parse_tree'
require 'parse_tree_extensions'
require 'ruby2ruby'
require File.dirname(__FILE__) + '/zebra/shoulda'

module Zebra
  class << self
    def shoulda?
      defined?(Shoulda)
    end
  end

  def expect(&block)
    Zebra.shoulda? ? expect_shoulda(&block) : expect_context(&block)
  end

  protected
    def expect_shoulda(&block)
      Shoulda::Context.send(:include, Zebra::ShouldaSupport) unless Shoulda::Context.include?(Zebra::ShouldaSupport)

      if Shoulda.current_context
        Shoulda.current_context.expect(&block)
      else
        context_name = self.name.gsub(/Test/, "")
        context      = Shoulda::Context.new(context_name, self) do
          expect(&block)
        end
        context.build
      end
    end

    def expect_context(&block)
      define_method(expect_test_name(context_name, &block), &block)
    end

    def expect_test_name(context_name, &block)
      block_translation = block.to_ruby.gsub /proc \{ (.+?) \}/, '\1'
      test_name         = ["test:", context_name, "expect", block_translation]
      test_name.reject! { |s| s == "" }

      test_name.join(' ')
    end
end

Test::Unit::TestCase.send(:extend, Zebra)
Object.send(:alias_method, :to, :should)
Object.send(:alias_method, :not_to, :should_not)

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
giraffesoft-zebra-0.2.0 lib/zebra.rb
joshng-zebra-0.1.1 lib/zebra.rb