Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit dc19415
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
This set of test helpers provides functionality similar to | ||
[contest](github.com/citrusbyte/contest), but for minitest. The code itself | ||
started from [this gist from Ryan Smith](https://gist.github.com/839034), and | ||
then I added miscellaneous things that other people suggested. | ||
|
||
It is mostly here for my own personal use, but feel free to do whatever you want | ||
with it. I might accept interesting patches if you send a pull request. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require "minitest/autorun" | ||
require "set" | ||
|
||
FIXTURE_DIR = File.expand_path( | ||
File.dirname(__FILE__)+"/fixtures/") | ||
|
||
# adopted from: https://gist.github.com/839034 | ||
def context(*args, &block) | ||
return super unless (name = args.first) && block | ||
|
||
context_class = Class.new(MiniTest::Unit::TestCase) do | ||
class << self | ||
def test(name, &block) | ||
test_method_name = "test_#{name.gsub(/\W/,'_')}".to_sym | ||
block ||= lambda { skip(name) } | ||
if instance_methods.include?(test_method_name) | ||
raise ArgumentError, "A test '#{name}' already exists" | ||
end | ||
define_method(test_method_name, &block) | ||
end | ||
|
||
def setup(&block) | ||
define_method(:setup, &block) | ||
end | ||
|
||
def teardown(&block) | ||
define_method(:teardown, &block) | ||
end | ||
end | ||
|
||
def assert_set_equal(setlike_a, setlike_b) | ||
assert setlike_a.to_set == setlike_b.to_set, | ||
"#{setlike_a.inspect} is not set equal to #{setlike_b.inspect}" | ||
end | ||
|
||
def read_fixture(name) | ||
File.read("#{FIXTURE_DIR}/#{name}") | ||
end | ||
end | ||
|
||
context_class.singleton_class.instance_eval do | ||
define_method(:name) { name.gsub(/\W/,'_') } | ||
end | ||
|
||
context_class.class_eval(&block) | ||
end | ||
|