Sha256: 1999855da0a34bc09f6576f39e09189f8af543e44f9c90f4805c352667bc7c57

Contents?: true

Size: 607 Bytes

Versions: 1

Compression:

Stored size: 607 Bytes

Contents

require 'nanotest'

module NanoTest
  class Spec
    instance_methods.each {|m| undef_method(m) unless m.match(/^__|object_id/) }

    def initialize(obj, positive=true)
      @obj, @positive = obj, positive
    end

    def method_missing(method, *args, &block)
      file, line = caller.first.split(':')[0..1]
      bool = @obj.__send__(method, *args, &block)
      bool = !bool unless @positive
      NanoTest.assert("assertion failed", file, line) { bool }
      @obj
    end
  end
end

class Object
  def must
    NanoTest::Spec.new(self)
  end
  def wont
    NanoTest::Spec.new(self, false)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nanotest_spec-0.9 lib/nanotest/spec.rb