Created
October 22, 2012 23:24
Describe your unit tests in an easy to read format
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
namespace :test do | |
# Describe the tests that are run for the provided class or all classes | |
task :describe, :klass do |t, args| | |
name = args[:klass] ? args[:klass].underscore : '*' | |
classes = {} | |
files = Dir["test/*/#{name}_test.rb"] | |
files.each do |f| | |
file = File.read(f) | |
test_class = file.scan(/class\s([A-Z][\w]+)Test/).flatten | |
next unless test_class | |
test_class = test_class.first if test_class.is_a?(Array) | |
classes[test_class] = file.scan(/\s+test\s*\"(.*)\"\s*do/).flatten | |
end | |
classes.each do |name, tests| | |
print "#{name}\n" | |
tests.each do |test| | |
print " - #{test}\n" | |
end | |
puts "" | |
end | |
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
> rake test:describe[ClassName] (ex: User) | |
User | |
- should have a valid email address | |
- should have a valid phone number | |
... | |
> rake test:describe | |
# describes all tested classes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment