Created
July 23, 2012 12:33
-
-
Save pithyless/3163387 to your computer and use it in GitHub Desktop.
minitest samples
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
# https://gist.github.com/2032303 | |
module MiniTest::Assertions | |
def assert_palindrome(string) | |
assert string == string.reverse, "Expected #{string} to read the same way backwards and forwards" | |
end | |
def assert_default(hash, default_value) | |
assert default_value == hash.default, "Expected #{default_value} to be default value for hash but was #{hash.default.inspect}" | |
end | |
end | |
String.infect_an_assertion :assert_palindrome, :must_be_palindrome, :only_one_argument | |
Hash.infect_an_assertion :assert_default, :must_default_to, :do_not_flip |
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
# https://gist.github.com/1116486 | |
class MiniTest::Spec | |
attr_accessor :subject | |
def self.its msg, &block | |
it msg.to_s do | |
subject.send(msg).instance_eval &block | |
end | |
end | |
end | |
describe CashRegister do | |
before do | |
self.subject = CashRegister.new | |
end | |
describe "when empty" do | |
its(:items) { must_be_empty } | |
its(:total) { must_equal 0 } | |
end | |
describe "after scanning 1 and 2" do | |
before do | |
subject.scan(1) | |
subject.scan(2) | |
end | |
its(:items) { wont_be_empty } | |
its(:total) { must_equal 3 } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment