-
-
Save revans/4402541 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'test_helper' | |
shared_examples_for 'An Adapter' do | |
describe '#read' do | |
before do | |
@adapter.write(@key = 'whiskey', @value = "Jameson's") | |
end | |
it 'reads a given key' do | |
@adapter.read(@key).must_equal(@value) | |
end | |
end | |
end |
This file contains hidden or 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 'test_helper' | |
describe Memory do | |
before do | |
@adapter = Memory.new('memory://127.0.0.1') | |
end | |
after do | |
@adapter.clear | |
end | |
it_behaves_like 'An Adapter' | |
describe '#to_s' do | |
it 'returns the name' do | |
@adapter.to_s.must_equal('Memory') | |
end | |
end | |
end |
This file contains hidden or 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 'test_helper' | |
describe Redis do | |
before do | |
@adapter = Redis.new('redis://127.0.0.1:6379') | |
end | |
after do | |
@adapter.clear | |
end | |
it_behaves_like 'An Adapter' | |
describe '#to_s' do | |
it 'returns the name' do | |
@adapter.to_s.must_equal('Redis') | |
end | |
end | |
end |
This file contains hidden or 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
gem 'minitest' | |
require 'minitest/spec' | |
require 'minitest/autorun' | |
MiniTest::Spec.class_eval do | |
def self.shared_examples | |
@shared_examples ||= {} | |
end | |
end | |
module MiniTest::Spec::SharedExamples | |
def shared_examples_for(desc, &block) | |
MiniTest::Spec.shared_examples[desc] = block | |
end | |
def it_behaves_like(desc) | |
self.instance_eval do | |
MiniTest::Spec.shared_examples[desc].call | |
end | |
end | |
end | |
Object.class_eval { include(MiniTest::Spec::SharedExamples) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment