No commit activity in last 3 years
No release in over 3 years
Duck typing + Interfaces
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.13
>= 10.0
>= 3.0
 Project Readme

duckface

Duckface CircleCI

A collection of tools to enforce duck typing based interfaces in Ruby.

Install

From gem:

gem 'duckface-interfaces', require: 'duckface'

From source:

gem 'duckface-interfaces', require: 'duckface', git: 'git@github.com:samuelgiles/duckface.git'

Configure

RSpec

spec/spec_helper.rb

require 'duckface/rspec'

Usage

Define an interface

require 'duckface'

module MyInterface
  extend Duckface::ActsAsInterface

  exclude_methods_from_interface_enforcement :ignoreable_method_a, :ignoreable_method_b

  def say_my_name(_name)
    raise NotImplementedMethod
  end

  def ignoreable_method_a
    puts 'I can be ignored'
  end

  def ignoreable_method_b
    puts 'And so can I'
  end
end

Define an implementation

require 'duckface'

class MyImplementation
  implements_interface MyInterface

  def say_my_name(name)
    puts name
  end
end

Test that an implementation correctly implements an interface

require 'spec_helper'

describe MyImplementation
  it_behaves_like 'it implements', MyInterface
end

If it fails you'll get messages pointing out where you've gone wrong:

Failures:

  1) MyImplementation behaves like it implements MyInterface correctly  
     Failure/Error: expect(check_session.successful?).to be(true), formatted_message(check_session)

       expected to correctly implement MyInterface:
        - say_my_name is not present