minispec-metadata 0.3.0 → 1.0.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: 3cce2a61ca40964ed06d9e2e649c1002133b9b8f
4
- data.tar.gz: 285a42529861f70d7cc3a2d0c900ba6a4ce4a0af
3
+ metadata.gz: 9b9aead991197f6c110e3a5f9dcf7d8f2a092c9f
4
+ data.tar.gz: 58a7d3d21d051cd4421a1c7b1476473da6fa3260
5
5
  SHA512:
6
- metadata.gz: 42b1922f175708ff7e050bdab7905cb34ab50d275ab5e02fdb26721ecec836c13d4dc6bed76d8aa7a49dde0d422bba9d63befd4a7007723921212c52ca006630
7
- data.tar.gz: e7abea1f81addc0bd9fea33e5cc4af02d8ca2744fdcd2834546ee53d0ff502d6aa591b94ed39673859f48ec2641fe5ddf8a943e58502393e5a8b35d62366dea2
6
+ metadata.gz: 6069c683aecb3aa941c355b6ca48ecfdf606dd4c6d5e217224eaef8d19066f68ffc266b175fce6bedc9164f48f9a57b25a645390f59befaa80b55bd5449b7ce9
7
+ data.tar.gz: 2eddcda76ff3209e96de99bced9b758c0132170589d7841e5a3e8bafafc427d1a60754af07cf652ef10bfb1f00e3688c37274b4c3d56ffc5d768c61a19ceecee
data/README.md CHANGED
@@ -57,7 +57,6 @@ Another great use is to do a version of [Ryan Bates' VCR trick](http://railscast
57
57
 
58
58
  ```ruby
59
59
  describe 'VCR trick' do
60
-
61
60
  it 'allows you to name your cassettes the same as the spec' do
62
61
  VCR.use_cassette spec_name do
63
62
  end
@@ -65,30 +64,6 @@ describe 'VCR trick' do
65
64
  end
66
65
  ```
67
66
 
68
- ### Gotchas
69
-
70
- If you registered a custom spec type and made it a subclass of MiniTest::Spec, e.g.:
71
-
72
- ```ruby
73
- class IntegrationSpec < MiniTest::Spec
74
- register_spec_type(/integration$/, self)
75
- end
76
- MiniTest
77
- ```
78
-
79
- then you will need to change your superclass to be a subclass of the spec type that allows metadata
80
- (see Implementation below).
81
- Just change it like this:
82
-
83
- ```ruby
84
- class IntegrationSpec < MiniTest::Spec.spec_type(//)
85
- register_spec_type(/integration$/, self)
86
- end
87
- MiniTest
88
- ```
89
-
90
- `MiniTest::Spec.spec_type` will always give you the top-level spec type, even if you don't use this gem.
91
-
92
67
  ## Installation
93
68
 
94
69
  Add this line to your application's Gemfile:
@@ -99,14 +74,6 @@ And then execute:
99
74
 
100
75
  $ bundle
101
76
 
102
- Or install it yourself as:
77
+ Or install it yourself:
103
78
 
104
79
  $ gem install minispec-metadata
105
-
106
- ## Implementation (for transparency)
107
-
108
- To add metadata to `it` blocks, I subclassed MiniTest::Spec.
109
- In order to ensure that it gets used out of the box,
110
- I changed the default Spec class to be the new subclass.
111
-
112
- To add metadata to `describe` blocks, I included a module into the Object class.
@@ -1,26 +1,38 @@
1
1
  module MiniSpecMetadata
2
- class SpecWithMetadata < MiniTest::Spec
2
+ module SpecWithMetadata
3
3
 
4
- @@metadata = {}
5
- @@spec_names = {}
6
-
7
- def self.it(desc = 'anonymous', metadata = {}, &block)
8
- name = super desc, &block
9
- @@metadata[name] = metadata
10
- @@spec_names[name] = desc
11
- name
4
+ def self.included(spec_class)
5
+ spec_class.extend(ClassMethods)
12
6
  end
13
- class << self
14
- alias :specify :it
7
+
8
+ module ClassMethods
9
+ def it(desc = 'anonymous', _metadata = {}, &block)
10
+ metadata =
11
+ class_variable_defined?(:@@metadata) ?
12
+ class_variable_get(:@@metadata) :
13
+ class_variable_set(:@@metadata, {})
14
+ spec_names =
15
+ class_variable_defined?(:@@spec_names) ?
16
+ class_variable_get(:@@spec_names) :
17
+ class_variable_set(:@@spec_names, {})
18
+
19
+ name = super desc, &block
20
+
21
+ metadata[name] = _metadata
22
+ spec_names[name] = desc
23
+ name
24
+ end
25
+ alias_method :specify, :it
15
26
  end
16
27
 
17
28
  def metadata
18
- description_metadata.merge @@metadata.fetch(name, {})
29
+ class_metadata = self.class.class_variable_get(:@@metadata).fetch(name, {})
30
+ description_metadata.merge class_metadata
19
31
  end
20
32
 
21
33
  # First arg passed to it block.
22
34
  def spec_name
23
- @@spec_names[name]
35
+ self.class.class_variable_get(:@@spec_names)[name]
24
36
  end
25
37
 
26
38
  # Description args passed to describe.
@@ -40,5 +52,4 @@ module MiniSpecMetadata
40
52
  end
41
53
  end
42
54
 
43
- # Override the default spec type.
44
- MiniTest::Spec::TYPES[0] = [//, MiniSpecMetadata::SpecWithMetadata]
55
+ MiniTest::Spec.send :include, MiniSpecMetadata::SpecWithMetadata
@@ -1,3 +1,3 @@
1
1
  module MiniSpecMetadata
2
- VERSION = "0.3.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -11,6 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.description = %q{MiniTest::Spec metadata}
12
12
  gem.summary = %q{Pass metadata to MiniTest::Spec descriptions and specs like in RSpec.}
13
13
  gem.homepage = "https://github.com/ordinaryzelig/minispec-metadata"
14
+ gem.license = 'MIT'
14
15
 
15
16
  gem.files = `git ls-files`.split($/)
16
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
data/spec/helper.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  require 'bundler/setup'
2
+ require 'awesome_print'
2
3
 
3
4
  require 'minitest/autorun'
4
5
  require 'minitest/pride'
5
6
  require 'minispec-metadata'
6
7
 
7
- require 'awesome_print'
8
-
9
8
  class MiniTest::Unit::TestCase
10
9
  parallelize_me!
11
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minispec-metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Ning
@@ -77,7 +77,8 @@ files:
77
77
  - spec/helper.rb
78
78
  - spec/spec_with_metadata.spec.rb
79
79
  homepage: https://github.com/ordinaryzelig/minispec-metadata
80
- licenses: []
80
+ licenses:
81
+ - MIT
81
82
  metadata: {}
82
83
  post_install_message:
83
84
  rdoc_options: []