minispec-metadata 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create 1.9.3-p327@minispec-metadata
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in minispec-metadata.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jared Ning
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ Minispec::Metadata
2
+ ==================
3
+
4
+ [![Build Status](https://secure.travis-ci.org/ordinaryzelig/minispec-metadata.png?branch=master)](http://travis-ci.org/ordinaryzelig/minispec-metadata)
5
+
6
+ https://github.com/ordinaryzelig/minispec-metadata
7
+
8
+ ## Usage
9
+
10
+ ```ruby
11
+ describe 'Usage', some: 'metadata' do
12
+
13
+ it 'defines a metadata method', more: 'metadata' do
14
+ metadata.must_equal(
15
+ some: 'metadata',
16
+ more: 'metadata',
17
+ )
18
+ end
19
+
20
+ it 'gives priority to closest metadata', some: 'different metadata' do
21
+ metadata.must_equal(
22
+ some: 'different metadata',
23
+ )
24
+ end
25
+
26
+ end
27
+ ```
28
+
29
+ ## Installation
30
+
31
+ Add this line to your application's Gemfile:
32
+
33
+ gem 'minispec-metadata'
34
+
35
+ And then execute:
36
+
37
+ $ bundle
38
+
39
+ Or install it yourself as:
40
+
41
+ $ gem install minispec-metadata
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task :default => :test
5
+
6
+ Rake::TestTask.new :test do |t|
7
+ t.pattern = 'spec/**/*.spec.rb'
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'minitest/spec'
2
+
3
+ require "minispec-metadata/version"
4
+ require 'minispec-metadata/describe_with_metadata'
5
+ require 'minispec-metadata/spec_with_metadata'
6
+
7
+ module MiniSpecMetadata
8
+ end
@@ -0,0 +1,24 @@
1
+ module MiniSpecMetadata
2
+ module DescribeWithMetadata
3
+
4
+ def describe(desc, *args, &block)
5
+ metadata = args.last.is_a?(Hash) ? args.pop : {}
6
+
7
+ description_class = super(desc, args, &block)
8
+
9
+ description_class.send :define_method, :description_metadata do
10
+ super().merge(metadata)
11
+ end
12
+
13
+ description_class
14
+ end
15
+
16
+ # Top-level method so all subclasses can call super.
17
+ def description_metadata
18
+ {}
19
+ end
20
+
21
+ end
22
+ end
23
+
24
+ Object.send :include, MiniSpecMetadata::DescribeWithMetadata
@@ -0,0 +1,23 @@
1
+ module MiniSpecMetadata
2
+ class SpecWithMetadata < MiniTest::Spec
3
+
4
+ @@metadata = {}
5
+
6
+ def self.it(desc = 'anonymous', metadata = {}, &block)
7
+ name = super desc, &block
8
+ @@metadata[name] = metadata
9
+ name
10
+ end
11
+ class << self
12
+ alias :specify :it
13
+ end
14
+
15
+ def metadata
16
+ description_metadata.merge @@metadata.fetch(__name__, {})
17
+ end
18
+
19
+ end
20
+ end
21
+
22
+ # Override the default spec type.
23
+ MiniTest::Spec::TYPES[0] = [//, MiniSpecMetadata::SpecWithMetadata]
@@ -0,0 +1,3 @@
1
+ module MiniSpecMetadata
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'minispec-metadata/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "minispec-metadata"
8
+ gem.version = MiniSpecMetadata::VERSION
9
+ gem.authors = ["Jared Ning"]
10
+ gem.email = ["jared@redningja.com"]
11
+ gem.description = %q{MiniTest::Spec metadata}
12
+ gem.summary = %q{Pass metadata to MiniTest::Spec descriptions and specs like in RSpec.}
13
+ gem.homepage = "https://github.com/ordinaryzelig/minispec-metadata"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'minitest'
21
+
22
+ gem.add_development_dependency 'awesome_print'
23
+ gem.add_development_dependency 'rake'
24
+ end
@@ -0,0 +1,66 @@
1
+ require_relative 'helper'
2
+
3
+ describe MiniSpecMetadata::DescribeWithMetadata, super_meta: 'data' do
4
+
5
+ describe 'as 2nd arg after description', second: '2nd' do
6
+
7
+ it 'is accessible with metadata method' do
8
+ metadata.fetch(:second).must_equal '2nd'
9
+ end
10
+
11
+ end
12
+
13
+ describe 'as 3rd arg after additional description', 'more description', third: '3rd' do
14
+
15
+ it 'is accessible with metadata method' do
16
+ metadata.fetch(:third).must_equal '3rd'
17
+ end
18
+
19
+ end
20
+
21
+ describe 'duplicate', first: '1st' do
22
+
23
+ it 'correctly scopes metadata to current description' do
24
+ metadata.fetch(:first).must_equal '1st'
25
+ metadata.key?(:second).must_equal false
26
+ end
27
+
28
+ end
29
+
30
+ describe 'duplicate', second: '2nd' do
31
+
32
+ it 'correctly scopes metadata to current description' do
33
+ metadata.fetch(:second).must_equal '2nd'
34
+ metadata.key?(:first).must_equal false
35
+ end
36
+
37
+ end
38
+
39
+ describe 'nested', sub: 'desc' do
40
+
41
+ it 'inherits from surrounding description', lowest: 'totem' do
42
+ metadata.must_equal(
43
+ super_meta: 'data',
44
+ sub: 'desc',
45
+ lowest: 'totem',
46
+ )
47
+ end
48
+
49
+ it 'gives nearest metadata priority', sub: 'zero', super_meta: 'priority' do
50
+ metadata.must_equal(
51
+ sub: 'zero',
52
+ super_meta: 'priority',
53
+ )
54
+ end
55
+
56
+ end
57
+
58
+ desc_class = describe 'return value' do
59
+
60
+ it 'equals description class' do
61
+ desc_class.must_equal self.class
62
+ end
63
+
64
+ end
65
+
66
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/setup'
2
+
3
+ require 'minitest/autorun'
4
+ require 'minitest/pride'
5
+ require 'minispec-metadata'
6
+
7
+ require 'awesome_print'
8
+
9
+ class MiniTest::Unit::TestCase
10
+ parallelize_me!
11
+ end
@@ -0,0 +1,49 @@
1
+ require_relative 'helper'
2
+
3
+ describe MiniSpecMetadata::SpecWithMetadata, description_meta: 'data' do
4
+
5
+ it 'accepts metadata arg', {} do
6
+ pass
7
+ end
8
+
9
+ it 'stores metadata for current spec', meta: 'data' do
10
+ metadata.fetch(:meta).must_equal 'data'
11
+ end
12
+
13
+ it 'inherits metadata from description' do
14
+ metadata.fetch(:description_meta).must_equal 'data'
15
+ end
16
+
17
+ specify 'it works with #specify', 1 => 2 do
18
+ metadata.fetch(1).must_equal 2
19
+ end
20
+
21
+ name = it 'returns name' do
22
+ name.must_equal __name__
23
+ end
24
+
25
+ end
26
+
27
+ describe MiniSpecMetadata::SpecWithMetadata, 'with no metadata' do
28
+
29
+ it 'returns empty hash when no metadata set' do
30
+ metadata.must_equal({})
31
+ end
32
+
33
+ end
34
+
35
+ describe MiniSpecMetadata::SpecWithMetadata do
36
+
37
+ before do
38
+ metadata.fetch(:before).must_equal 'accessible'
39
+ end
40
+
41
+ it 'is accessible in hooks', before: 'accessible', after: 'also accessible' do
42
+ pass
43
+ end
44
+
45
+ after do
46
+ metadata.fetch(:after).must_equal 'also accessible'
47
+ end
48
+
49
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minispec-metadata
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jared Ning
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: awesome_print
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: MiniTest::Spec metadata
63
+ email:
64
+ - jared@redningja.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rvmrc
71
+ - .travis.yml
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - lib/minispec-metadata.rb
77
+ - lib/minispec-metadata/describe_with_metadata.rb
78
+ - lib/minispec-metadata/spec_with_metadata.rb
79
+ - lib/minispec-metadata/version.rb
80
+ - minispec-metadata.gemspec
81
+ - spec/describe_with_metadata.spec.rb
82
+ - spec/helper.rb
83
+ - spec/spec_with_metadata.spec.rb
84
+ homepage: https://github.com/ordinaryzelig/minispec-metadata
85
+ licenses: []
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.24
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Pass metadata to MiniTest::Spec descriptions and specs like in RSpec.
108
+ test_files:
109
+ - spec/describe_with_metadata.spec.rb
110
+ - spec/helper.rb
111
+ - spec/spec_with_metadata.spec.rb