Created
August 3, 2012 11:42
-
-
Save blowmage/3246871 to your computer and use it in GitHub Desktop.
Shouldify 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
class Foo | |
def bar | |
"bar" | |
end | |
def baz | |
"baz" | |
end | |
end |
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_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 |
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
$ 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 |
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/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