Skip to content

Instantly share code, notes, and snippets.

@blowmage
Created September 26, 2012 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blowmage/3785771 to your computer and use it in GitHub Desktop.
Save blowmage/3785771 to your computer and use it in GitHub Desktop.
Stoopid example of MiniTest Shouldify
=== 1.0.0 / 2012-09-25
* 1 major enhancement
* Birthday!
History.txt
Manifest.txt
README.txt
Rakefile
bin/stoopid
lib/stoopid.rb
test/test_stoopid.rb
require 'rubygems'
require 'hoe'
Hoe.plugin :minitest
Hoe.spec 'stoopid' do
developer('mike Moore', 'mike@blowmage.com')
dependency "minitest-shouldify", ">= 1.0", :dev
dependency "minitest-matchers", ">= 1.2", :dev
end
class Stoopid
VERSION = '1.0.0'
def to_s
"stoopid"
end
end
require "minitest/autorun"
require "minitest/shouldify"
require "minitest/matchers"
class Stoopid
module Matchers
class BeEqualTo
def initialize expected
@expected = expected
end
def matches? actual
@actual = actual
@actual == @expected
end
def failure_message
"Expected #{@actual.inspect} " +
"to be the same as #{@expected.inspect}"
end
def negative_failure_message
"Expected #{@actual.inspect} " +
"to not be the same as #{@expected.inspect}"
end
end
def be_equal_to(attr)
BeEqualTo.new(attr)
end
def self.included(base)
instance_methods.each do |name|
base.register_matcher name, name
end
end
end
end
class MiniTest::Unit::TestCase
include Stoopid::Matchers
end
require "test_helper"
require "stoopid"
MiniTest.shouldify! "should", "should_not"
MiniTest.shouldify! "would_you_please", "please_o_please_dont"
describe Stoopid do
it "is stoopid" do
Stoopid.new.to_s.should_equal "stoopid"
Stoopid.new.to_s.should_not_equal "smart"
end
subject { Stoopid.new.to_s }
it { would_you_please be_equal_to "stoopid" }
please_o_please_dont { be_equal_to "nothing" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment