Skip to content

Instantly share code, notes, and snippets.

@wuarmin
Last active May 10, 2017 07:15
Show Gist options
  • Save wuarmin/c83c10ad9cbc9a43af110426f07ed493 to your computer and use it in GitHub Desktop.
Save wuarmin/c83c10ad9cbc9a43af110426f07ed493 to your computer and use it in GitHub Desktop.
Minitest/Spec Sharing Examples / Check if class implements the interface
module ServiceInterface
def self.included(base)
base.send :include, InstanceMethods
end
module InstanceMethods
def test
"test"
end
end
end
require 'spec_helper'
class Module
def it(description, &block)
define_method "test_#{description}", &block
end
end
module TestServiceInterface
it "should respond to my_test" do
assert_respond_to(@object, :my_test)
end
end
require_relative 'service_interface'
class TestService
include ServiceInterface
def my_test
"my_test"
end
end
require 'spec_helper'
require_relative 'service_interface_spec'
describe TestService do
include TestServiceInterface
before do
@object = TestService.new
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment