minispec-metadata 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b9aead991197f6c110e3a5f9dcf7d8f2a092c9f
4
- data.tar.gz: 58a7d3d21d051cd4421a1c7b1476473da6fa3260
3
+ metadata.gz: 3b3e8197843d0b0115644bd53b223e5cf1855d17
4
+ data.tar.gz: 2d74dd7985cfa56a119b3e354fefb314df0a14a0
5
5
  SHA512:
6
- metadata.gz: 6069c683aecb3aa941c355b6ca48ecfdf606dd4c6d5e217224eaef8d19066f68ffc266b175fce6bedc9164f48f9a57b25a645390f59befaa80b55bd5449b7ce9
7
- data.tar.gz: 2eddcda76ff3209e96de99bced9b758c0132170589d7841e5a3e8bafafc427d1a60754af07cf652ef10bfb1f00e3688c37274b4c3d56ffc5d768c61a19ceecee
6
+ metadata.gz: 32bb94f89f459d02737b0bf1697b7aed6eed25de6225c46c3a0805bb7b77d7a0393e98a4738fe989fd44d59924e4c9c8a92339a4a15f3813991ed45c9be605c1
7
+ data.tar.gz: f47ca8c8c4798c238f82282c6bb69b8f0d05bd3bb10ada125aa9f1b6baf15667d0c3a012da02f7d98eef2fe85efc1a3aab92e5f8ce068e07a62b686a414a23cc
data/README.md CHANGED
@@ -8,6 +8,9 @@ https://github.com/ordinaryzelig/minispec-metadata
8
8
  ## Usage
9
9
 
10
10
  ```ruby
11
+ require 'minitest/autorun'
12
+ require 'minispec-metadata'
13
+
11
14
  describe 'Usage', some: 'metadata' do
12
15
 
13
16
  before do
@@ -50,6 +53,13 @@ describe 'Usage', some: 'metadata' do
50
53
 
51
54
  end
52
55
 
56
+ # Thanks to @mfpiccolo for this.
57
+ it 'allows array of symbols like RSpec', :these, :work, :too do
58
+ metadata[:these].must_equal true
59
+ metadata[:work].must_equal true
60
+ metadata[:too].must_equal true
61
+ end
62
+
53
63
  end
54
64
  ```
55
65
 
@@ -77,3 +87,24 @@ And then execute:
77
87
  Or install it yourself:
78
88
 
79
89
  $ gem install minispec-metadata
90
+
91
+ ## Additional description gotcha
92
+
93
+ By default, 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.
@@ -1,3 +1,5 @@
1
+ # For a bit of backward compatibility.
2
+ # Thanks to @jhsu for discovering the discrepancy.
1
3
  if MiniTest.const_defined?(:Unit)
2
4
  class MiniTest::Unit::TestCase
3
5
  def name
@@ -1,11 +1,27 @@
1
1
  module MiniSpecMetadata
2
2
  module DescribeWithMetadata
3
3
 
4
- def describe(desc, *args, &block)
5
- metadata = args.last.is_a?(Hash) ? args.pop : {}
6
-
7
- additional_description = args.first
8
- description_class = super(desc, args, &block)
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)
9
25
 
10
26
  description_class.send :define_method, :description_metadata do
11
27
  super().merge(metadata)
@@ -6,7 +6,18 @@ module MiniSpecMetadata
6
6
  end
7
7
 
8
8
  module ClassMethods
9
- def it(desc = 'anonymous', _metadata = {}, &block)
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
+
10
21
  metadata =
11
22
  class_variable_defined?(:@@metadata) ?
12
23
  class_variable_get(:@@metadata) :
@@ -1,3 +1,3 @@
1
1
  module MiniSpecMetadata
2
- VERSION = "1.0.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -18,6 +18,13 @@ describe MiniSpecMetadata::DescribeWithMetadata, super_meta: 'data' do
18
18
 
19
19
  end
20
20
 
21
+ describe 'when just a symbol is passed', :axiom, :vcr do
22
+ it 'uses symbols as true values' do
23
+ metadata.fetch(:axiom).must_equal true
24
+ metadata.fetch(:vcr).must_equal true
25
+ end
26
+ end
27
+
21
28
  describe 'duplicate', first: '1st' do
22
29
 
23
30
  it 'correctly scopes metadata to current description' do
@@ -14,6 +14,11 @@ describe MiniSpecMetadata::SpecWithMetadata, description_meta: 'data' do
14
14
  metadata.fetch(:description_meta).must_equal 'data'
15
15
  end
16
16
 
17
+ it "uses symbols as true values", :verity, :words_are_hard do
18
+ metadata.fetch(:verity).must_equal true
19
+ metadata.fetch(:words_are_hard).must_equal true
20
+ end
21
+
17
22
  specify 'it works with #specify', 1 => 2 do
18
23
  metadata.fetch(1).must_equal 2
19
24
  end
@@ -22,6 +27,23 @@ describe MiniSpecMetadata::SpecWithMetadata, description_meta: 'data' do
22
27
  name.must_equal name
23
28
  end
24
29
 
30
+ describe 'in a nested describe', 'with no metadata' do
31
+
32
+ it 'works', works: true do
33
+ metadata[:works].must_equal true
34
+ end
35
+
36
+ end
37
+
38
+ describe 'in a nested describe', with_metadata: true do
39
+
40
+ it 'works', works: true do
41
+ metadata[:with_metadata].must_equal true
42
+ metadata[:works].must_equal true
43
+ end
44
+
45
+ end
46
+
25
47
  end
26
48
 
27
49
  describe MiniSpecMetadata::SpecWithMetadata, 'with no metadata' do
@@ -55,3 +77,12 @@ describe MiniSpecMetadata::SpecWithMetadata, 'test name' do
55
77
  end
56
78
 
57
79
  end
80
+
81
+ describe MiniSpecMetadata::SpecWithMetadata, 'additional description', :respect do
82
+
83
+ it 'respects additional description' do
84
+ self.class.name.must_equal 'MiniSpecMetadata::SpecWithMetadata::additional description'
85
+ metadata.must_equal({respect: true})
86
+ end
87
+
88
+ 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: 1.0.0
4
+ version: 2.0.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: 2013-07-19 00:00:00.000000000 Z
11
+ date: 2014-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  requirements: []
98
98
  rubyforge_project:
99
- rubygems_version: 2.0.0
99
+ rubygems_version: 2.0.3
100
100
  signing_key:
101
101
  specification_version: 4
102
102
  summary: Pass metadata to MiniTest::Spec descriptions and specs like in RSpec.