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 +4 -4
- data/README.md +1 -34
- data/lib/minispec-metadata/spec_with_metadata.rb +26 -15
- data/lib/minispec-metadata/version.rb +1 -1
- data/minispec-metadata.gemspec +1 -0
- data/spec/helper.rb +1 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b9aead991197f6c110e3a5f9dcf7d8f2a092c9f
|
4
|
+
data.tar.gz: 58a7d3d21d051cd4421a1c7b1476473da6fa3260
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
2
|
+
module SpecWithMetadata
|
3
3
|
|
4
|
-
|
5
|
-
|
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
|
-
|
14
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
44
|
-
MiniTest::Spec::TYPES[0] = [//, MiniSpecMetadata::SpecWithMetadata]
|
55
|
+
MiniTest::Spec.send :include, MiniSpecMetadata::SpecWithMetadata
|
data/minispec-metadata.gemspec
CHANGED
@@ -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
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.
|
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: []
|