Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 432ad6a2e1e13a5537f521aba8821107bcd24faf 0 parents
@wojtekmach authored
2  .gitignore
@@ -0,0 +1,2 @@
+pkg
+.*.sw*
3  Gemfile
@@ -0,0 +1,3 @@
+source "http://rubygems.org"
+
+gemspec
16 Gemfile.lock
@@ -0,0 +1,16 @@
+PATH
+ remote: .
+ specs:
+ minitest-metadata (0.0.1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ minitest (2.10.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ minitest (>= 2.5)
+ minitest-metadata!
93 README.md
@@ -0,0 +1,93 @@
+# minitest-metadata
+
+* https://github.com/wojtekmach/minitest-metadata
+
+## Description
+
+minitest-metadata allows you to set metadata (key-value) for your test cases so that
+before and after hooks can use them.
+
+You can use it to:
+
+* change environments (prepare drivers, mocks etc)
+* mark tests as slow, fast or (God forbid) order dependant
+
+## Example
+
+Suppose you want to tag some of your Capybara acceptance tests to
+use JavaScript driver
+
+
+```ruby
+class AcceptanceTest < MiniTest::Spec
+ include Capybara::DSL
+
+ before do
+ if metadata[:js] == true
+ Capybara.current_driver = Capybara.javascript_driver
+ end
+ end
+
+ after do
+ Capybara.current_driver = Capybara.default_driver
+ end
+end
+
+class UsersAcceptanceTest < AcceptanceTest
+ it "basic pagination" do
+ visit "/users"
+ assert page.has_content?("Current page: 1")
+
+ click_link "Next page"
+
+ assert page.has_content?("Current page: 2")
+ end
+
+ it "keyboard shortcuts pagination", :js => true do
+ visit "/users"
+ assert page.has_content?("Current page: 1")
+
+ press_key "n"
+
+ assert page.has_content?("Current page: 2")
+ end
+end
+```
+
+
+## Requirements
+
+* minitest
+
+## Instalation
+
+ gem install minitest-metadata
+
+or put in a Gemfile
+
+ gem 'minitest-metadata'
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2012 Wojciech Mach
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 Rakefile
@@ -0,0 +1,10 @@
+require "bundler/gem_tasks"
+require "rake/testtask"
+
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = false
+end
+
+task :default => :test
29 lib/minitest-metadata.rb
@@ -0,0 +1,29 @@
+require 'minitest/spec'
+
+class MiniTest::Metadata
+ VERSION = '0.1.0'
+end
+
+class MiniTest::Spec
+ # Returns Hash metadata for each test method
+ def self.metadata
+ @metadata ||= {}
+ end
+
+ # Returns Hash metadata for current test method
+ def metadata
+ self.class.metadata[__name__] || {}
+ end
+
+ class << self
+ alias old_it it
+
+ def it(description = "", metadata = {}, &block)
+ methods = test_methods
+ ret = old_it description, &block
+ name = (test_methods - methods).first
+ self.metadata[name] = metadata
+ ret
+ end
+ end
+end
22 minitest-metadata.gemspec
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "minitest-metadata"
+
+Gem::Specification.new do |s|
+ s.name = "minitest-metadata"
+ s.version = MiniTest::Metadata::VERSION
+ s.authors = ["Wojciech Mach"]
+ s.email = ["wojtek@wojtekmach.pl"]
+ s.homepage = ""
+ s.summary = %q{Metadata (key-value) support for minitest/spec}
+ s.description = s.summary
+
+ s.rubyforge_project = "minitest-metadata"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_development_dependency "minitest", ">= 2.5"
+end
27 test/minitest-metadata_test.rb
@@ -0,0 +1,27 @@
+require "minitest/spec"
+require "minitest/autorun"
+require "minitest-metadata"
+
+describe MiniTest::Spec do
+ it "::metadata returns metadata hash for each test method" do
+ @cls = describe "A spec" do
+ it "test1", :js => true do; end
+
+ it "test2" do; end
+
+ it "test3", :js => false do; end
+ end
+
+ @cls.metadata["test_0001_test1"].must_equal :js => true
+ @cls.metadata["test_0002_test2"].must_equal({})
+ @cls.metadata["test_0003_test3"].must_equal :js => false
+ end
+
+ it "#meta returns empty hash when nothing passed to ::it" do
+ metadata.must_equal({})
+ end
+
+ it "#meta returns metadata hash when passed to ::it", :js => true do
+ metadata.must_equal :js => true
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.