minitest-metadata 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.travis.yml +7 -0
- data/.yardopts +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +16 -0
- data/README.md +101 -0
- data/Rakefile +10 -0
- data/lib/minitest-metadata/version.rb +5 -0
- data/lib/minitest-metadata.rb +29 -0
- data/minitest-metadata.gemspec +23 -0
- data/test/minitest-metadata_test.rb +27 -0
- metadata +80 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--no-private
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
minitest-metadata
|
2
|
+
=================
|
3
|
+
|
4
|
+
[![Build Status](https://secure.travis-ci.org/wojtekmach/minitest-metadata.png?branch=master)](http://travis-ci.org/wojtekmach/minitest-metadata)
|
5
|
+
|
6
|
+
- **Source code:** <https://github.com/wojtekmach/minitest-metadata>
|
7
|
+
- **API reference:** <http://rubydoc.info/github/wojtekmach/minitest-metadata/master/frames>
|
8
|
+
|
9
|
+
## Description
|
10
|
+
|
11
|
+
minitest-metadata allows you to set metadata (key-value) for your test cases so that
|
12
|
+
before and after hooks can use them.
|
13
|
+
|
14
|
+
You can use it to:
|
15
|
+
|
16
|
+
* change environments (prepare drivers, mocks etc)
|
17
|
+
* mark tests as slow, fast or (God forbid) order dependant
|
18
|
+
|
19
|
+
## Example
|
20
|
+
|
21
|
+
Suppose you want to tag some of your Capybara acceptance tests to
|
22
|
+
use JavaScript driver
|
23
|
+
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class AcceptanceTest < MiniTest::Spec
|
27
|
+
include Capybara::DSL
|
28
|
+
|
29
|
+
before do
|
30
|
+
if metadata[:js] == true
|
31
|
+
Capybara.current_driver = Capybara.javascript_driver
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
after do
|
36
|
+
Capybara.current_driver = Capybara.default_driver
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class UsersAcceptanceTest < AcceptanceTest
|
41
|
+
it "basic pagination" do
|
42
|
+
visit "/users"
|
43
|
+
assert page.has_content?("Current page: 1")
|
44
|
+
|
45
|
+
click_link "Next page"
|
46
|
+
|
47
|
+
assert page.has_content?("Current page: 2")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "keyboard shortcuts pagination", :js => true do
|
51
|
+
visit "/users"
|
52
|
+
assert page.has_content?("Current page: 1")
|
53
|
+
|
54
|
+
press_key "n"
|
55
|
+
|
56
|
+
assert page.has_content?("Current page: 2")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
|
62
|
+
## Requirements
|
63
|
+
|
64
|
+
- minitest
|
65
|
+
|
66
|
+
## Instalation
|
67
|
+
|
68
|
+
```
|
69
|
+
gem install minitest-metadata
|
70
|
+
```
|
71
|
+
|
72
|
+
or put in a Gemfile:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
gem 'minitest-metadata'
|
76
|
+
```
|
77
|
+
|
78
|
+
## License
|
79
|
+
|
80
|
+
(The MIT License)
|
81
|
+
|
82
|
+
Copyright (c) 2012 Wojciech Mach
|
83
|
+
|
84
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
85
|
+
a copy of this software and associated documentation files (the
|
86
|
+
'Software'), to deal in the Software without restriction, including
|
87
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
88
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
89
|
+
permit persons to whom the Software is furnished to do so, subject to
|
90
|
+
the following conditions:
|
91
|
+
|
92
|
+
The above copyright notice and this permission notice shall be
|
93
|
+
included in all copies or substantial portions of the Software.
|
94
|
+
|
95
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
96
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
97
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
98
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
99
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
100
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
101
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
|
3
|
+
require 'minitest-metadata/version'
|
4
|
+
|
5
|
+
class MiniTest::Spec
|
6
|
+
# Returns Hash metadata for class' test methods
|
7
|
+
def self.metadata
|
8
|
+
@metadata ||= {}
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns Hash metadata for currently running test
|
12
|
+
def metadata
|
13
|
+
self.class.metadata[__name__] || {}
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
# @private
|
18
|
+
alias :old_it :it
|
19
|
+
|
20
|
+
# @private
|
21
|
+
def it(description = "", metadata = {}, &block)
|
22
|
+
methods = test_methods
|
23
|
+
ret = old_it description, &block
|
24
|
+
name = (test_methods - methods).first
|
25
|
+
self.metadata[name] = metadata
|
26
|
+
ret
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "minitest-metadata/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "minitest-metadata"
|
7
|
+
s.version = MiniTest::Metadata::VERSION
|
8
|
+
s.authors = ["Wojciech Mach"]
|
9
|
+
s.email = ["wojtek@wojtekmach.pl"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Metadata (key-value) support for minitest/spec}
|
12
|
+
s.description = s.summary
|
13
|
+
|
14
|
+
s.rubyforge_project = "minitest-metadata"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
s.add_development_dependency "minitest", ">= 2.5"
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "minitest/spec"
|
2
|
+
require "minitest/autorun"
|
3
|
+
require "minitest-metadata"
|
4
|
+
|
5
|
+
describe MiniTest::Spec do
|
6
|
+
it "::metadata returns metadata hash for each test method" do
|
7
|
+
@cls = describe "A spec" do
|
8
|
+
it "test1", :js => true do; end
|
9
|
+
|
10
|
+
it "test2" do; end
|
11
|
+
|
12
|
+
it "test3", :js => false do; end
|
13
|
+
end
|
14
|
+
|
15
|
+
@cls.metadata["test_0001_test1"].must_equal :js => true
|
16
|
+
@cls.metadata["test_0002_test2"].must_equal({})
|
17
|
+
@cls.metadata["test_0003_test3"].must_equal :js => false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "#meta returns empty hash when nothing passed to ::it" do
|
21
|
+
metadata.must_equal({})
|
22
|
+
end
|
23
|
+
|
24
|
+
it "#meta returns metadata hash when passed to ::it", :js => true do
|
25
|
+
metadata.must_equal :js => true
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minitest-metadata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Wojciech Mach
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70096496164140 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70096496164140
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: minitest
|
27
|
+
requirement: &70096496161300 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.5'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70096496161300
|
36
|
+
description: Metadata (key-value) support for minitest/spec
|
37
|
+
email:
|
38
|
+
- wojtek@wojtekmach.pl
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- .travis.yml
|
45
|
+
- .yardopts
|
46
|
+
- Gemfile
|
47
|
+
- Gemfile.lock
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- lib/minitest-metadata.rb
|
51
|
+
- lib/minitest-metadata/version.rb
|
52
|
+
- minitest-metadata.gemspec
|
53
|
+
- test/minitest-metadata_test.rb
|
54
|
+
homepage: ''
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project: minitest-metadata
|
74
|
+
rubygems_version: 1.8.11
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Metadata (key-value) support for minitest/spec
|
78
|
+
test_files:
|
79
|
+
- test/minitest-metadata_test.rb
|
80
|
+
has_rdoc:
|