Sha256: db1cb68ab7f9d5c1bdf3bcacc0f8fbc798850b9f4c5c1e0fa1a291d8230511f3

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require 'test_helper'

module MockModule end
module MockInterface end

module Remote
  def on
  end

  def off
  end
end

class BrokenDevice
  implements Remote, MockInterface
end

class Device < BrokenDevice
  include MockModule

  def on
    @power = true
  end

  def method_missing(method, *args)
    method == :off ? @power = false : super
  end
end

class InterfaceTest < Test::Unit::TestCase

  def test_should_include_interface
    assert BrokenDevice.included_modules.include?(Remote)
  end

  def test_interface_should_include_abstract
    assert Remote.is_a?(Interface::Abstract)
  end

  def test_should_raise_not_implemented_error
    assert_raises(NotImplementedError) { BrokenDevice.new.on }
  end

  def test_should_not_raise_not_implemented_error_if_method_is_defined
    assert Device.new.on
  end

  def test_should_not_raise_not_implemented_error_if_method_is_defined_by_method_missing
    assert !Device.new.off
  end

  def test_should_return_interfaces
    assert_equal [Remote, MockInterface], Device.interfaces
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shuber-interface-0.0.1 test/interface_test.rb