Class Object
In: lib/quarry/assert.rb
lib/quarry/stub/stub.rb
lib/quarry/stub/mock.rb
Parent: Object

Methods

Public Instance methods

Assert a operational relationship.

4.assert == 3 #=> Assertion Error

[Source]

# File lib/quarry/assert.rb, line 119
  def assert
    return Assertion::True.new(self)
  end

Assert not an operational relationship. Read it as "assert not".

  4.assert! == 4  #=> Assertion Error

AUHTOR‘S NOTE: This method would not be necessary if Ruby would allow +!=+ to be define as a method, or at least +!+ as a unary method.

[Source]

# File lib/quarry/assert.rb, line 142
  def assert!
    return Assertion::False.new(self)
  end

Provides a way to assert that a procedure raises an exception.

  assert_raises(StandardError){ raise }

[Source]

# File lib/quarry/assert.rb, line 161
  def assert_raises(exception, &block)
    Assertion::True.new(
      lambda do |*a|
        begin
          block.call(*a)
          false
        rescue exception
          true
        end
      end
    )
  end
assert_raises!(exception, &block)

Alias for refute_raises

Create mock object.

[Source]

# File lib/quarry/stub/mock.rb, line 63
    def mock(mock_module=nil)
      if mock_module
        Mock::Delegator.new(self, mock_module)
      else
        @_mock ||= Mock.new
        extend(@_mock)
        @_mock
      end
    end
refute()

Alias for assert!

Provides a way to assert that a procedure does not raise an exception.

  refute_raises(StandardError){ raise }

[Source]

# File lib/quarry/assert.rb, line 181
  def refute_raises(exception, &block)
    Assertion::True.new(
      begin
        block.call(*a)
        true
      rescue exception
        false
      end
    )
  end

We can‘t remove the module per-say. So we have to just neuter it. This is a very weak solution, but it will suffice for the moment.

[Source]

# File lib/quarry/stub/mock.rb, line 79
    def remove(mock_module=nil)
      mock_module ||= @_mock
      obj = self
      mod = Module.new
      mock_module.__table__.each do |interface, result|
        meth = interface[0]
        mod.module_eval do
          define_method(meth, &obj.class.instance_method(meth).bind(obj))
        end
      end    
      extend(mod)
    end

We can‘t remove the module per-say. So we have to just neuter it. This is a very weak solution, but it will suffice for the moment.

[Source]

# File lib/quarry/stub/stub.rb, line 77
    def remove(stub_module=nil)
      stub_module ||= @_stub
      obj = self
      mod = Module.new
      stub_module.__table__.each do |interface, result|
        meth = interface[0]
        mod.module_eval do
          define_method(meth, &obj.class.instance_method(meth).bind(obj))
        end
      end    
      extend(mod)
    end
should()

Alias for assert

should_not()

Alias for refute

should_not_raise(exception, &block)

Alias for refute_raises

should_raise(exception, &block)

Alias for assert_raises

Create a new stub.

[Source]

# File lib/quarry/stub/stub.rb, line 61
    def stub(stub_module=nil)
      if stub_module
        Stub::Delegator.new(self, stub_module)
      else
        @_stub ||= Stub.new
        extend(@_stub)
        @_stub
      end
    end

[Validate]