class Minitest::ValueMonad

Constants

VERSION

Public Class Methods

new(v) click to toggle source
# File lib/minitest/bacon.rb, line 36
def initialize v
  @val = v
  @pos = true
end

Public Instance Methods

a(*args, &block)
Alias for: be
an(*args, &block)
Alias for: be
assert(msg = nil) { |val| ... } click to toggle source
# File lib/minitest/bacon.rb, line 68
def assert msg = nil
  r = yield @val

  Minitest.poke
  msg ||= "boom"
  raise Minitest::Assertion, msg if @pos ^ r

  r
end
be(*args, &block) click to toggle source
# File lib/minitest/bacon.rb, line 47
def be(*args, &block)
  if args.empty?
    self
  else
    block = args.shift unless block_given?
    block ||= lambda { @val.send(*args) }
    assert(&block)
  end
end
Also aliased as: a, an
be_false() click to toggle source
# File lib/minitest/bacon.rb, line 64
def be_false
  assert { !@val }
end
be_true() click to toggle source
# File lib/minitest/bacon.rb, line 60
def be_true
  assert { @val }
end
change?(*args, &block) click to toggle source
# File lib/minitest/bacon.rb, line 96
def change?(*args, &block); block.change?(*args); end
equal(value) click to toggle source
# File lib/minitest/bacon.rb, line 89
def equal(value)         self == value      end
flunk(reason="Flunked") click to toggle source
# File lib/minitest/bacon.rb, line 98
def flunk(reason="Flunked")
  raise Minitest::Assertion, reason
end
identical_to(value) click to toggle source
# File lib/minitest/bacon.rb, line 91
def identical_to(value)  self.equal? value  end
Also aliased as: same_as
match(value) click to toggle source
# File lib/minitest/bacon.rb, line 90
def match(value)         self =~ value      end
method_missing(name, *args, &block) click to toggle source
# File lib/minitest/bacon.rb, line 78
def method_missing(name, *args, &block)
  name = name.to_s.sub(/^be_/, '')
  name = "#{name}?" if name =~ /\w[^?]\z/

  msg = @pos ? "" : "not"
  msg << @val.inspect << ".#{name}"
  msg << "(#{args.map(&:inspect).join ", "}) failed"

  assert(msg) { @val.__send__(name, *args, &block) }
end
not(*args, &block) click to toggle source
# File lib/minitest/bacon.rb, line 41
def not(*args, &block)
  @pos = !@pos

  be(*args, &block)
end
raise?(*args, &block) click to toggle source
# File lib/minitest/bacon.rb, line 94
def raise?(*args,  &block); block.raise?(*args);  end
same_as(value)
Alias for: identical_to
throw?(*args, &block) click to toggle source
# File lib/minitest/bacon.rb, line 95
def throw?(*args,  &block); block.throw?(*args);  end