Permalink
Browse files

Reorganize file structure, extract MiniTest::Metadata

  • Loading branch information...
1 parent ef6ef4d commit 42907273d81bfa33574e241565d438bb0278d154 @wojtekmach committed Nov 14, 2012
View
4 Gemfile.lock
@@ -1,13 +1,13 @@
PATH
remote: .
specs:
- minitest-metadata (0.1.0)
+ minitest-metadata (0.2.0)
minitest (>= 2.12)
GEM
remote: http://rubygems.org/
specs:
- minitest (2.12.0)
+ minitest (4.2.0)
rake (0.9.2.2)
PLATFORMS
View
4 HISTORY.md
@@ -1,3 +1,7 @@
+# HEAD
+
+* Reorganize file structure, extract MiniTest::Metadata
+
# 0.2.0
* No need for calculation of test method name - @splattael
View
17 README.md
@@ -57,7 +57,24 @@ class UsersAcceptanceTest < AcceptanceTest
end
end
```
+## Note about speed
+minitest-metadata adds some overhead so you might want to limit it to only
+acceptance specs. If that's the case do this:
+
+```ruby
+# Gemfile
+
+group :test do
+ gem 'minitest-metadata', :require => false
+end
+
+# test/acceptance_test_helper.rb
+
+class AcceptanceTest < MiniTest::Spec
+ include MiniTest::Metadata
+end
+```
## Requirements
View
27 lib/minitest-metadata.rb
@@ -1,27 +1,6 @@
-require 'minitest/spec'
-
-require 'minitest-metadata/version'
+require 'minitest/metadata/version'
+require 'minitest/metadata'
class MiniTest::Spec
- # Returns Hash metadata for class' test methods
- def self.metadata
- @metadata ||= {}
- end
-
- # Returns Hash metadata for currently running test
- def metadata
- self.class.metadata[__name__] || {}
- end
-
- class << self
- # @private
- alias :old_it :it
-
- # @private
- def it(description = "", metadata = {}, &block)
- old_it(description, &block).tap do |name|
- self.metadata[name] = metadata
- end
- end
- end
+ include MiniTest::Metadata
end
View
31 lib/minitest/metadata.rb
@@ -0,0 +1,31 @@
+module MiniTest::Metadata
+ module ClassMethods
+ # Returns Hash metadata for class' test methods
+ def metadata
+ @metadata ||= {}
+ end
+ end
+
+ def self.included(klass)
+ klass.extend ClassMethods
+ klass.class_eval do
+ class << self
+ # @private
+ alias :old_it :it
+
+ # @private
+ def it(description = "", metadata = {}, &block)
+ old_it(description, &block).tap do |name|
+ self.metadata[name] = metadata
+ end
+ end
+ end
+ end
+ super
+ end
+
+ # Returns Hash metadata for currently running test
+ def metadata
+ self.class.metadata[__name__] || {}
+ end
+end
View
0 lib/minitest-metadata/version.rb → lib/minitest/metadata/version.rb
File renamed without changes.
View
2 minitest-metadata.gemspec
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
-require "minitest-metadata/version"
+require "minitest/metadata/version"
Gem::Specification.new do |s|
s.name = "minitest-metadata"
View
6 test/minitest-metadata_test.rb
@@ -1,9 +1,13 @@
require "minitest/autorun"
-require "minitest-metadata"
+require "minitest/metadata"
describe MiniTest::Spec do
+ include MiniTest::Metadata
+
it "::metadata returns metadata hash for each test method" do
@cls = describe "A spec" do
+ include MiniTest::Metadata
+
it "test1", :js => true do; end
it "test2" do; end

2 comments on commit 4290727

@blowmage

Somehow I missed this change. Good stuff.

@wojtekmach
Please sign in to comment.