Created
February 7, 2012 09:52
-
-
Save prepor/1758845 to your computer and use it in GitHub Desktop.
let for minitest
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 'minitest/spec' | |
require 'minitest/autorun' | |
module Helpers | |
module Let | |
def let(name, &blk) | |
define_method name do | |
@let_assigments ||= {} | |
@let_assigments[name] ||= send(:"original_#{name}") | |
end | |
define_method "original_#{name}", &blk | |
end | |
end | |
end | |
class MiniTest::Unit::TestCase | |
extend Helpers::Let | |
end | |
describe Helpers::Let do | |
let(:hash) { { foo: 'bar' } } | |
it "should set hash with foo" do | |
hash[:foo].must_equal 'bar' | |
end | |
it "should return eq objects" do | |
hash.object_id.must_equal hash.object_id | |
end | |
describe "overriding" do | |
let(:hash) { super().merge(zoo: 'foo' )} | |
it "should override super-let" do | |
hash[:foo].must_equal 'bar' | |
hash[:zoo].must_equal 'foo' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment