Last active
May 10, 2017 07:15
-
-
Save wuarmin/c83c10ad9cbc9a43af110426f07ed493 to your computer and use it in GitHub Desktop.
Minitest/Spec Sharing Examples / Check if class implements the interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ServiceInterface | |
def self.included(base) | |
base.send :include, InstanceMethods | |
end | |
module InstanceMethods | |
def test | |
"test" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'service_interface' | |
class TestService | |
include ServiceInterface | |
def my_test | |
"my_test" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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