Skip to content

Instantly share code, notes, and snippets.

@gentlefuture
Forked from blowmage/foo.rb
Created August 7, 2012 12:37
Show Gist options
  • Save gentlefuture/3284961 to your computer and use it in GitHub Desktop.
Save gentlefuture/3284961 to your computer and use it in GitHub Desktop.
Shouldify MiniTest
class Foo
def bar
"bar"
end
def baz
"baz"
end
end
require_relative "spec_helper"
require_relative "foo"
describe Foo do
it "knows how to bar" do
Foo.new.bar.should_equal "bar"
end
it "knows how to baz" do
Foo.new.baz.should_equal "baz"
end
end
$ ruby foo_spec.rb
Run options: --seed 56769
# Running tests:
..
Finished tests in 0.000467s, 4282.6552 tests/s, 4282.6552 assertions/s.
2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
require "minitest/autorun"
module MiniTest::Expectations
def self.shouldify_methods! pattern, replacement
public_instance_methods.grep(pattern).each do |action|
shouldify_action = action.to_s.sub(pattern, replacement).to_sym
alias_method shouldify_action, action
end
end
end
class MiniTest::Spec < MiniTest::Unit::TestCase
def self.shouldify!
MiniTest::Expectations.shouldify_methods! /^must_/, "should_"
MiniTest::Expectations.shouldify_methods! /^wont_/, "should_not_"
end
end
MiniTest::Spec.shouldify!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment