Sha256: 1cdcfa9592c67c703adc1cb92e5b54957f475177b665193857854b99e085a1b5

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

module DataMapper::Spec
  module PendingHelpers
    def pending_if(*args)
      message, boolean = parse_args(*args)

      if boolean
        pending(message) { yield }
      else
        yield
      end
    end

    def rescue_if(*args)
      message, boolean = parse_args(*args)

      if boolean
        raised = nil
        begin
          yield
          raised = false
        rescue Exception
          raised = true
        end

        raise "should have raised: #{message || 'TODO'}" if raised == false
      else
        yield
      end
    end

    private

    def parse_args(*args)
      case args.map { |arg| arg.class }
        when [ String, TrueClass ], [ String, FalseClass ] then args
        when [ String, NilClass ]                          then [ args.first, false      ]
        when [ String ]                                    then [ args.first, true       ]
        when [ TrueClass ], [ FalseClass ]                 then [ '',         args.first ]
        when [ NilClass ]                                  then [ '',         false      ]
        when []                                            then [ '',         true       ]  # defaults
        else
          raise ArgumentError, "Invalid arguments: #{args.inspect}"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
dm-rinda-adapter-0.1.2 spec/lib/pending_helpers.rb
dm-hibernate-adapter-0.1pre-java spec/transient/lib/pending_helpers.rb
dm-rinda-adapter-0.1.0 spec/lib/pending_helpers.rb
dm-core-0.10.2 spec/lib/pending_helpers.rb