module DataMapper::Spec::PendingHelpers

Public Instance Methods

pending_if(*args) { || ... } click to toggle source
# File lib/dm-core/spec/lib/pending_helpers.rb, line 5
def pending_if(*args)
  message, boolean = parse_args(*args)

  if boolean
    pending(message) { yield }
  else
    yield
  end
end
rescue_if(*args) { || ... } click to toggle source
# File lib/dm-core/spec/lib/pending_helpers.rb, line 15
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 Instance Methods

parse_args(*args) click to toggle source
# File lib/dm-core/spec/lib/pending_helpers.rb, line 35
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