Skip to content

Instantly share code, notes, and snippets.

@wojtekmach
Created August 28, 2011 12:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wojtekmach/1176619 to your computer and use it in GitHub Desktop.
Save wojtekmach/1176619 to your computer and use it in GitHub Desktop.
minitest + shoulda-matchers
gem "minitest"
require "minitest/spec"
require "minitest/autorun"
require "active_model"
require "turn"
require "shoulda-matchers"
class MiniTest::Unit::TestCase
include Shoulda::Matchers::ActiveModel
extend Shoulda::Matchers::ActiveModel
end
class Post
attr_accessor :title
include ActiveModel::Validations
validates :title, :presence => true, :length => 2..16
end
class MiniTest::Spec
class << self
def it_must &block
matcher = yield
it "must #{matcher.description}" do
result = matcher.matches? subject
assert result, matcher.failure_message
end
end
def it_wont &block
matcher = yield
it "wont #{matcher.description}" do
result = matcher.does_not_match? subject
assert result, matcher.negative_failure_message
end
end
end
end
describe "Post" do
subject { Post.new }
it_must { ensure_length_of(:title).is_at_least(2).is_at_most(16) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment