minispec-metadata 3.0.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38ce1b63b96b84af69f5727f5eb38d963fe75e99
4
- data.tar.gz: a8ac8f3f33abc5350eb57d50dd325668121e3803
3
+ metadata.gz: a5bdc75e156393afb15081d9942ca420644c1a90
4
+ data.tar.gz: 50c85c9943c5d9ebf508b6f13ad80b3db146bae0
5
5
  SHA512:
6
- metadata.gz: 341212cc6062f980ddee800d6a17f8c4d0103f6e7d98f6acb7bacaa2a10ef7670f0c75a910e06943329c40a640b3b6bbee14343a40db7b2f90d05e87c3b28df9
7
- data.tar.gz: 607554c3ddc34877eba6fb2cf1810e2deab07d354448512177de7196588b2d5450aa323cde58fa637764b9f0263fd00b7212842ee0c8c5d1ce603ca659f837ac
6
+ metadata.gz: c7c77884c1cb77c561aedf9cb2f6ba827a98b130f28f205977863cd8f52659cc391b6b7eb3de438ab2cc8fa9614507f6c92539b098e66bf8fece0efea301800b
7
+ data.tar.gz: 37d97040831cee14ddeb8145b5321640c026c8ddcb1d046af06bb8190f61c968fa3da61f058b6b6ba502b52310c1814a4cebff287ed55cf1ea685c145442e389
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 3.2.0
2
+
3
+ * Add support for tags for command line filtering.
4
+
5
+ ## 3.1.0
6
+
7
+ * Do not desctructively extract metadata from additional_desc.
8
+ * Use ALL additional_desc as metadata.
9
+
1
10
  ## 3.0.0
2
11
 
3
12
  * Total rewrite.
data/README.md CHANGED
@@ -51,6 +51,14 @@ describe 'Usage', some: 'metadata' do
51
51
  self.class.desc.must_equal MinispecMetadata
52
52
  end
53
53
 
54
+ it 'treats additional descriptions as metadata too', meta: 'data' do
55
+ metadata.must_equal(
56
+ :some => 'metadata',
57
+ 'additional description' => true,
58
+ :meta => 'data',
59
+ )
60
+ end
61
+
54
62
  end
55
63
 
56
64
  # Thanks to @mfpiccolo for this.
@@ -74,6 +82,31 @@ describe 'VCR trick' do
74
82
  end
75
83
  ```
76
84
 
85
+ ### Tags
86
+
87
+ (Only for Ruby >= 2 and Minitest >= 5)
88
+
89
+ Use the `--tag TAG` or `-tTAG` option to focus on certain tests according to metadata (will match both string/symbol as key/value).
90
+ E.g. Run only the slow tests below with option `--tag js`:
91
+
92
+ ```ruby
93
+ describe 'integration tests' do
94
+ it 'runs super slow JS stuff', :js do
95
+ # Will run.
96
+ end
97
+ it 'runs fast stuff' do
98
+ # Will not run.
99
+ end
100
+ end
101
+ ```
102
+
103
+ You can use `--tag` more than once to include more tags to be run (any matching tags will run).
104
+
105
+ If an exclusive tag, e.g. `~slow`, is used alone, all tests except those tagged slow will be run.
106
+ If an exclusive tag is used in addition to any inclusive tags, then the exclusive tag will just filter those included.
107
+
108
+ Note that when using `rake`, you need to wrap Minitest's options like this: `rake test TESTOPTS='--tag js'`.
109
+
77
110
  ## Installation
78
111
 
79
112
  Add this line to your application's Gemfile:
@@ -88,27 +121,6 @@ Or install it yourself:
88
121
 
89
122
  $ gem install minispec-metadata
90
123
 
91
- ## Additional description gotcha
92
-
93
- In Minitest <= 4, Minitest allows 2 descriptions:
94
-
95
- ```ruby
96
- describe 'Description 1', 'Description 2'
97
- ```
98
-
99
- But this gem allows symbols as metadata:
100
-
101
- ```ruby
102
- describe 'Description', :additional
103
- ```
104
-
105
- Technically, this gem breaks Minitest behavior here.
106
- With this gem, `:additional` is used as metadata.
107
- But in pure Minitest, it would have been used as the additional description.
108
- I personally have never seen anybody use the additional description,
109
- and I think the "symbols as metadata" feature is more useful.
110
- So I allowed this breakage of Minitest behavior.
111
-
112
124
  ## Compatibility
113
125
 
114
126
  Tested with Minitest 4 and up.
data/Rakefile CHANGED
@@ -1,8 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'rake/testtask'
3
3
 
4
- task :default => :test
4
+ task :default => [:test]
5
5
 
6
6
  Rake::TestTask.new :test do |t|
7
7
  t.pattern = 'spec/**/*.spec.rb'
8
8
  end
9
+
data/lib/backwards.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # For a bit of backward compatibility.
2
2
  # Thanks to @jhsu for discovering the discrepancy.
3
- if MiniTest.const_defined?(:Unit)
3
+ if Minitest::Versions::MAJOR <= 4
4
4
  class MiniTest::Unit::TestCase
5
5
  def name
6
6
  __name__
@@ -1,25 +1,26 @@
1
1
  require 'minitest/spec'
2
+
3
+ require 'minitest/versions'
2
4
  require_relative 'backwards'
3
5
 
4
- require "minispec-metadata/version"
6
+ require 'minispec-metadata/version'
5
7
 
6
8
  require 'minispec-metadata/it'
7
9
  require 'minispec-metadata/describe'
10
+ require 'minispec-metadata/tags'
8
11
 
9
12
  module MinispecMetadata
10
13
 
11
14
  module_function
12
15
 
13
- def extract_metadata!(args)
16
+ def extract_metadata(args)
14
17
  metadata = {}
15
- args.delete_if do |arg|
18
+ args.each do |arg|
16
19
  case arg
17
20
  when Hash
18
21
  metadata.merge! arg
19
- when Symbol
20
- metadata.merge!(arg => true)
21
22
  else
22
- false
23
+ metadata.merge!(arg => true)
23
24
  end
24
25
  end
25
26
  metadata
@@ -2,9 +2,19 @@ module MinispecMetadata
2
2
  module Describe
3
3
 
4
4
  def describe(desc, *additional_desc, &block)
5
- metadata = MinispecMetadata.extract_metadata! additional_desc
6
-
7
- cls = super(desc, *additional_desc, &block)
5
+ metadata = MinispecMetadata.extract_metadata additional_desc
6
+
7
+ # Minitest 5 allows unlimited additional_desc.
8
+ # Minitest 4 allows max 1 additional_desc.
9
+ # So we need to pass up only the number of allowed additional_desc.
10
+ additional_allowed =
11
+ if Minitest::Versions::MAJOR <= 4
12
+ additional_desc.first(1)
13
+ else
14
+ additional_desc
15
+ end
16
+
17
+ cls = super(desc, *additional_allowed.compact, &block)
8
18
  cls.extend ClassMethods
9
19
 
10
20
  cls.additional_desc = additional_desc
@@ -10,7 +10,7 @@ module MinispecMetadata
10
10
  def it(description, *metadata, &block)
11
11
  name = super description, &block
12
12
 
13
- metadata = MinispecMetadata.extract_metadata!(metadata)
13
+ metadata = MinispecMetadata.extract_metadata(metadata)
14
14
 
15
15
  self.it_descriptions[name] = description
16
16
  self.metadata_by_test_name[name] = metadata
@@ -27,12 +27,16 @@ module MinispecMetadata
27
27
  @it_descriptions ||= {}
28
28
  end
29
29
 
30
+ def metadata_for_test_name(test_name)
31
+ describe_metadata.merge(
32
+ metadata_by_test_name.fetch(test_name)
33
+ )
34
+ end
35
+
30
36
  end
31
37
 
32
38
  def metadata
33
- self.class.describe_metadata.merge(
34
- self.class.metadata_by_test_name.fetch(name)
35
- )
39
+ self.class.metadata_for_test_name(name)
36
40
  end
37
41
 
38
42
  def desc
@@ -0,0 +1,107 @@
1
+ module MinispecMetadata
2
+
3
+ module_function
4
+
5
+ def tags
6
+ @tags ||= []
7
+ end
8
+
9
+ def add_tag_string(tag_string)
10
+ tags << Tag.new(tag_string)
11
+ end
12
+
13
+ def supports_tags?
14
+ minitest_version_supports_tags? && ruby_version_supports_tags?
15
+ end
16
+
17
+ # Because of plugin system.
18
+ def minitest_version_supports_tags?
19
+ Minitest::Versions::MAJOR >= 5
20
+ end
21
+
22
+ # Because of #prepend.
23
+ def ruby_version_supports_tags?
24
+ RUBY_VERSION.to_i >= 2
25
+ end
26
+
27
+ end
28
+
29
+ module MinispecMetadata
30
+
31
+ module Tags
32
+
33
+ def runnable_methods
34
+ methods = super.dup
35
+
36
+ if MinispecMetadata.tags.select(&:inclusive?).any?
37
+ methods.select! do |runnable_method|
38
+ runnable_method_matches_any_inclusive_tag?(runnable_method)
39
+ end
40
+ end
41
+
42
+ methods.reject do |runnable_method|
43
+ runnable_method_matches_any_exclusive_tag?(runnable_method)
44
+ end
45
+ end
46
+
47
+ def runnable_method_matches_any_inclusive_tag?(runnable_method)
48
+ tags = MinispecMetadata.tags.select(&:inclusive?)
49
+ runnable_method_matches_any_tags?(runnable_method, tags)
50
+ end
51
+
52
+ def runnable_method_matches_any_exclusive_tag?(runnable_method)
53
+ tags = MinispecMetadata.tags.select(&:exclusive?)
54
+ runnable_method_matches_any_tags?(runnable_method, tags)
55
+ end
56
+
57
+ private
58
+
59
+ def runnable_method_matches_any_tags?(runnable_method, tags)
60
+ tags.any? do |tag|
61
+ metadata = metadata_for_test_name(runnable_method)
62
+ value = metadata[tag.key] || metadata[tag.key.to_sym]
63
+ matches =
64
+ if tag.value?
65
+ value.to_s == tag.value
66
+ else
67
+ !!value
68
+ end
69
+ matches
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ class Tag
76
+
77
+ def initialize(tag_string)
78
+ @tag_string = tag_string
79
+ end
80
+
81
+ def exclusive?
82
+ @tag_string.start_with? '~'
83
+ end
84
+
85
+ def inclusive?
86
+ !exclusive?
87
+ end
88
+
89
+ def key
90
+ @key ||= @tag_string[/\w+/]
91
+ end
92
+
93
+ def value
94
+ @value ||= @tag_string.split(':').last if value?
95
+ end
96
+
97
+ def value?
98
+ !!@tag_string[/:/]
99
+ end
100
+
101
+ end
102
+
103
+ end
104
+
105
+ if MinispecMetadata.supports_tags?
106
+ Minitest::Test.singleton_class.send :prepend, MinispecMetadata::Tags
107
+ end
@@ -1,3 +1,3 @@
1
1
  module MinispecMetadata
2
- VERSION = "3.0.0"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -0,0 +1,25 @@
1
+ # This file gets auto required/executed by Minitest >= v5.
2
+ # Any other version won't find this file automatically.
3
+
4
+ require 'minispec-metadata'
5
+
6
+ module Minitest
7
+
8
+ def self.plugin_minispec_metadata_options(opts, options)
9
+ opts.on '-t', '--tag TAG'do |tag_string|
10
+ options[:tag_strings] ||= []
11
+ options[:tag_strings] << tag_string
12
+ end
13
+ end
14
+
15
+ def self.plugin_minispec_metadata_init(options)
16
+ if RUBY_VERSION.to_i >= 2
17
+ options.fetch(:tag_strings, []).each do |tag_string|
18
+ MinispecMetadata.add_tag_string tag_string
19
+ end
20
+ else
21
+ warn 'tags requires Ruby 2. If you really want it, please open an issue.'
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,9 @@
1
+ module Minitest
2
+
3
+ module Versions
4
+
5
+ MAJOR, MINOR, PATCH = Minitest::Unit::VERSION.split('.').map(&:to_i)
6
+
7
+ end
8
+
9
+ end
@@ -72,48 +72,40 @@ describe MinispecMetadata::Describe, super_meta: 'data' do
72
72
 
73
73
  end
74
74
 
75
- if MiniTest.const_defined?(:Unit) # Minitest version 4 (maybe before too?)
75
+ # Only allows 1 additional description.
76
+ describe MinispecMetadata::Describe, 'additional description' do
76
77
 
77
- # Only allows 1 additional description.
78
- describe MinispecMetadata::Describe, 'additional description' do
79
-
80
- it 'provides a method to get the descriptions' do
81
- self.class.descs.must_equal [MinispecMetadata::Describe, 'additional description']
82
- end
83
-
84
- it 'provides a method to get only the additional description' do
85
- self.class.additional_desc.must_equal ['additional description']
86
- end
78
+ it 'provides a method to get the descriptions' do
79
+ self.class.descs.must_equal [MinispecMetadata::Describe, 'additional description']
80
+ end
87
81
 
88
- describe 'nested describe with no additional description' do
82
+ it 'provides a method to get only the additional description' do
83
+ self.class.additional_desc.must_equal ['additional description']
84
+ end
89
85
 
90
- it 'does not inherit additional description from parent' do
91
- self.class.additional_desc.must_be_empty
92
- end
86
+ describe 'nested describe with no additional description' do
93
87
 
88
+ it 'does not inherit additional description from parent' do
89
+ self.class.additional_desc.must_be_empty
94
90
  end
95
91
 
96
92
  end
97
93
 
98
- else
99
-
100
- # Minitest version 5
101
- describe MinispecMetadata::Describe, 'additional description', 'even more' do
102
-
103
- it 'provides a method to get the descriptions' do
104
- self.class.descs.must_equal [MinispecMetadata::Describe, 'additional description', 'even more']
105
- end
106
-
107
- it 'provides a method to get only the additional description' do
108
- self.class.additional_desc.must_equal ['additional description', 'even more']
109
- end
94
+ end
110
95
 
111
- describe 'nested describe with no additional description' do
96
+ if Minitest::Versions::MAJOR >= 5
112
97
 
113
- it 'does not inherit additional description from parent' do
114
- self.class.additional_desc.must_be_empty
115
- end
98
+ describe 'stuff', 'more stuff', {even_more: 'stuff'}, :holy_cow_that_is_a_lot_of_stuff, :minitest_5 do
116
99
 
100
+ it 'preserves additional description but still allows any value for metadata', :more? => 'yeah' do
101
+ self.class.descs.must_equal ['stuff', 'more stuff', {even_more: 'stuff'}, :holy_cow_that_is_a_lot_of_stuff, :minitest_5]
102
+ metadata.must_equal(
103
+ 'more stuff' => true,
104
+ :even_more => 'stuff',
105
+ :holy_cow_that_is_a_lot_of_stuff => true,
106
+ :more? => 'yeah',
107
+ :minitest_5 => true,
108
+ )
117
109
  end
118
110
 
119
111
  end
@@ -123,8 +115,15 @@ end
123
115
  describe MinispecMetadata::Describe, 'additional description', :respect do
124
116
 
125
117
  it 'respects additional description' do
126
- self.class.name.must_equal 'MinispecMetadata::Describe::additional description'
127
- metadata.must_equal(respect: true)
118
+ if Minitest::Versions::MAJOR <= 4
119
+ self.class.name.must_equal 'MinispecMetadata::Describe::additional description'
120
+ else
121
+ self.class.name.must_equal 'MinispecMetadata::Describe::additional description::respect'
122
+ end
123
+ metadata.must_equal(
124
+ 'additional description' => true,
125
+ :respect => true,
126
+ )
128
127
  end
129
128
 
130
129
  end
data/spec/it.spec.rb CHANGED
@@ -51,7 +51,11 @@ describe MinispecMetadata::It do
51
51
  describe 'in a nested describe', 'with no metadata' do
52
52
 
53
53
  it 'works', works: true do
54
- metadata.must_equal(description_meta: 'data', works: true)
54
+ metadata.must_equal(
55
+ :description_meta => 'data',
56
+ 'with no metadata' => true,
57
+ :works => true,
58
+ )
55
59
  end
56
60
 
57
61
  end
@@ -2,27 +2,27 @@ require_relative 'helper'
2
2
 
3
3
  describe MinispecMetadata do
4
4
 
5
- describe '#extract_metadata!' do
5
+ describe '#extract_metadata' do
6
6
 
7
7
  it 'extracts from a hash' do
8
- metadata = MinispecMetadata.extract_metadata! [{asdf: true}]
8
+ metadata = MinispecMetadata.extract_metadata [{asdf: true}]
9
9
  metadata.must_equal asdf: true
10
10
  end
11
11
 
12
12
  it 'extracts from symbols, returns hash keys with true values' do
13
- metadata = MinispecMetadata.extract_metadata! [:asdf, :fdsa]
13
+ metadata = MinispecMetadata.extract_metadata [:asdf, :fdsa]
14
14
  metadata.must_equal asdf: true, fdsa: true
15
15
  end
16
16
 
17
17
  it 'extracts a mix' do
18
- metadata = MinispecMetadata.extract_metadata! [:asdf, {fdsa: true}]
18
+ metadata = MinispecMetadata.extract_metadata [:asdf, {fdsa: true}]
19
19
  metadata.must_equal asdf: true, fdsa: true
20
20
  end
21
21
 
22
- it 'descructively removes metadata from args' do
22
+ it 'does not remove metadata from args' do
23
23
  args = [:asdf, 'description']
24
- metadata = MinispecMetadata.extract_metadata! args
25
- args.must_equal ['description']
24
+ metadata = MinispecMetadata.extract_metadata args
25
+ args.must_equal [:asdf, 'description']
26
26
  end
27
27
 
28
28
  end
@@ -2,7 +2,7 @@ require_relative 'helper'
2
2
 
3
3
  # Confirmed to not work with v2.0.0.
4
4
  # Thanks to @jrochkind.
5
- describe "top level describe" do
5
+ describe "top level describe" do
6
6
  describe "an inner describe" do
7
7
  before do
8
8
  desc.wont_be_nil
data/spec/tags.spec.rb ADDED
@@ -0,0 +1,110 @@
1
+ require_relative 'helper'
2
+ #require_relative 'test_tags_verifier' if ENV['TEST_TAGS'] && MinispecMetadata.supports_tags?
3
+
4
+ if MinispecMetadata.supports_tags?
5
+
6
+ module MinispecMetadata
7
+ describe Tag do
8
+
9
+ it 'captures the metadata key' do
10
+ tag = Tag.new('~sure')
11
+ tag.key.must_equal 'sure'
12
+ tag.value?.must_equal false
13
+ end
14
+
15
+ it 'captures metadata key/value' do
16
+ tag = Tag.new('key:value')
17
+ tag.key.must_equal 'key'
18
+ tag.value.must_equal 'value'
19
+ end
20
+
21
+ it 'captures inclusivity' do
22
+ tag = Tag.new('sure')
23
+ tag.must_be :inclusive?
24
+ end
25
+
26
+ it 'captures exclusivity' do
27
+ tag = Tag.new('~sure')
28
+ tag.must_be :exclusive?
29
+ end
30
+
31
+ end
32
+
33
+ TAGS_TEST = describe Tags do
34
+ def self.passing_test(*args)
35
+ it *args do
36
+ pass
37
+ end
38
+ end
39
+
40
+ passing_test '1', :minitest_5
41
+ passing_test '2', 'minitest_5', :slow
42
+ passing_test '3', :minitest_4
43
+ passing_test '4', :minitest_4, 'slow'
44
+ passing_test '5', :slow, specific: 'value'
45
+ passing_test '6', 'specific' => :value, unmatched: :value
46
+ passing_test '7', 'specific' => 'value'
47
+ end
48
+
49
+ # Test the #runnable_methods of tags_test above with different sets of Tags.
50
+ describe '#runnable_methods' do
51
+
52
+ def stub_tags(tag_strings, &block)
53
+ tags = tag_strings.map { |tag_string| Tag.new(tag_string) }
54
+ MinispecMetadata.stub :tags, tags, &block
55
+ end
56
+
57
+ def strip_prefix(name)
58
+ name.sub /^test_\d{4}_/, ''
59
+ end
60
+
61
+ def self.assert_runnable_methods_with_tags(tag_strings, expected_runnable_methods)
62
+ it "returns runnable_methods with tag_strings #{tag_strings.inspect}" do
63
+ stub_tags tag_strings do
64
+ TAGS_TEST
65
+ .runnable_methods
66
+ .map(&method(:strip_prefix))
67
+ .sort
68
+ .must_equal expected_runnable_methods
69
+ end
70
+ end
71
+ end
72
+
73
+ assert_runnable_methods_with_tags ['minitest_5'], %w[
74
+ 1
75
+ 2
76
+ ]
77
+
78
+ assert_runnable_methods_with_tags ['~minitest_4'], %w[
79
+ 1
80
+ 2
81
+ 5
82
+ 6
83
+ 7
84
+ ]
85
+
86
+ assert_runnable_methods_with_tags ['specific:value'], %w[
87
+ 5
88
+ 6
89
+ 7
90
+ ]
91
+
92
+ assert_runnable_methods_with_tags ['~unmatched:value'], %w[
93
+ 1
94
+ 2
95
+ 3
96
+ 4
97
+ 5
98
+ 7
99
+ ]
100
+
101
+ assert_runnable_methods_with_tags ['minitest_5', 'minitest_4', 'specific:value', '~unmatched:value', '~slow'], %w[
102
+ 1
103
+ 3
104
+ 7
105
+ ]
106
+
107
+ end
108
+
109
+ end
110
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minispec-metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Ning
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-26 00:00:00.000000000 Z
11
+ date: 2014-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -71,10 +71,11 @@ files:
71
71
  - lib/backwards.rb
72
72
  - lib/minispec-metadata.rb
73
73
  - lib/minispec-metadata/describe.rb
74
- - lib/minispec-metadata/describe_with_metadata.rb
75
74
  - lib/minispec-metadata/it.rb
76
- - lib/minispec-metadata/spec_with_metadata.rb
75
+ - lib/minispec-metadata/tags.rb
77
76
  - lib/minispec-metadata/version.rb
77
+ - lib/minitest/minispec_metadata_plugin.rb
78
+ - lib/minitest/versions.rb
78
79
  - minispec-metadata.gemspec
79
80
  - spec/describe.spec.rb
80
81
  - spec/helper.rb
@@ -82,6 +83,7 @@ files:
82
83
  - spec/minispec_metadata.spec.rb
83
84
  - spec/readme.spec.rb
84
85
  - spec/regression.spec.rb
86
+ - spec/tags.spec.rb
85
87
  homepage: https://github.com/ordinaryzelig/minispec-metadata
86
88
  licenses:
87
89
  - MIT
@@ -113,3 +115,4 @@ test_files:
113
115
  - spec/minispec_metadata.spec.rb
114
116
  - spec/readme.spec.rb
115
117
  - spec/regression.spec.rb
118
+ - spec/tags.spec.rb
@@ -1,45 +0,0 @@
1
- module MinispecMetadata
2
- module DescribeWithMetadata
3
-
4
- def describe(desc, *_args, &block)
5
- args = _args.dup
6
-
7
- metadata =
8
- case args.last
9
- when Hash
10
- args.pop
11
- when Symbol
12
- # We're changing Minitest behavior here.
13
- # If args.first is anything but a Symbol, use it as additional_description.
14
- # If it's a symbol, assume it is metadata.
15
- additional_description = args.shift unless args.first.is_a?(Symbol)
16
- args.each_with_object({}) do |arg, hash|
17
- hash[arg] = true
18
- end
19
- else
20
- {}
21
- end
22
-
23
- additional_description ||= args.first
24
- description_class = super(desc, additional_description, &block)
25
-
26
- description_class.send :define_method, :description_metadata do
27
- super().merge(metadata)
28
- end
29
-
30
- description_class.send :define_method, :spec_additional_description do
31
- additional_description
32
- end
33
-
34
- description_class
35
- end
36
-
37
- # Top-level method so all subclasses can call super.
38
- def description_metadata
39
- {}
40
- end
41
-
42
- end
43
- end
44
-
45
- Object.send :include, MinispecMetadata::DescribeWithMetadata
@@ -1,66 +0,0 @@
1
- module MinispecMetadata
2
- module SpecWithMetadata
3
-
4
- def self.included(spec_class)
5
- spec_class.extend(ClassMethods)
6
- end
7
-
8
- module ClassMethods
9
- def it(desc = 'anonymous', *_args, &block)
10
- args = _args.dup
11
-
12
- _metadata =
13
- if args.last.is_a?(Hash)
14
- args.last
15
- else
16
- args.each_with_object({}) do |arg, hash|
17
- hash[arg] = true
18
- end
19
- end
20
-
21
- metadata =
22
- class_variable_defined?(:@@metadata) ?
23
- class_variable_get(:@@metadata) :
24
- class_variable_set(:@@metadata, {})
25
- spec_names =
26
- class_variable_defined?(:@@spec_names) ?
27
- class_variable_get(:@@spec_names) :
28
- class_variable_set(:@@spec_names, {})
29
-
30
- name = super desc, &block
31
-
32
- metadata[name] = _metadata
33
- spec_names[name] = desc
34
- name
35
- end
36
- alias_method :specify, :it
37
- end
38
-
39
- def metadata
40
- class_metadata = self.class.class_variable_get(:@@metadata).fetch(name, {})
41
- description_metadata.merge class_metadata
42
- end
43
-
44
- # First arg passed to it block.
45
- def spec_name
46
- self.class.class_variable_get(:@@spec_names)[name]
47
- end
48
-
49
- # Description args passed to describe.
50
- # Additional description is included if given.
51
- def spec_descriptions
52
- [spec_description, spec_additional_description].compact
53
- end
54
-
55
- def spec_description
56
- self.class.desc
57
- end
58
-
59
- def spec_additional_description
60
- self.class.spec_additional_description
61
- end
62
-
63
- end
64
- end
65
-
66
- MiniTest::Spec.send :include, MinispecMetadata::SpecWithMetadata