minitest-shared_description 1.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 +7 -0
- data/CHANGELOG +3 -0
- data/MIT-LICENSE +18 -0
- data/README.rdoc +79 -0
- data/Rakefile +45 -0
- data/lib/minitest/shared_description.rb +88 -0
- data/spec/minitest-shared_description_spec.rb +74 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9db8a45f2939cd0b19df4a55e37e937b69ecfcb6
|
4
|
+
data.tar.gz: 5b97a1ce66372a2fd5bd66c55f1d5fb6e7c4f8cd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5d649b2cc35c7d792256b2b3e2b5d09a8d7d83fd273a3d97f6808df405e7261fc0ade5da119511de874bb90687fb21f76ac87554523ef71ab209d349b617f170
|
7
|
+
data.tar.gz: 96d2fb33ad27ee6e3cd07e31d4dd73d85cfc411ebc92f4f9f92d26e1abb79a7a1a8008840c7d4056a74536d1b6b5457409e0d900f19fa021bf24d4f53607ace5
|
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2015 Jeremy Evans
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
= minitest-shared_description
|
2
|
+
|
3
|
+
minitest-shared_description adds support for shared specs and shared spec subclasses
|
4
|
+
to Minitest. Minitest supports shared specs by default using plain ruby modules, but
|
5
|
+
does not support shared spec subclasses. In addition to making it possible to share
|
6
|
+
subclasses, minitest-shared_desciption also provides a slightly nicer interface for
|
7
|
+
sharing specs.
|
8
|
+
|
9
|
+
= Installation
|
10
|
+
|
11
|
+
gem install minitest-shared_description
|
12
|
+
|
13
|
+
= Source Code
|
14
|
+
|
15
|
+
Source code is available on GitHub at https://github.com/jeremyevans/minitest-shared_description
|
16
|
+
|
17
|
+
= Usage
|
18
|
+
|
19
|
+
require 'minitest/shared_description'
|
20
|
+
|
21
|
+
SharedExamples = shared_description do
|
22
|
+
# You can do regular specs
|
23
|
+
it "should do something" do
|
24
|
+
# something
|
25
|
+
end
|
26
|
+
|
27
|
+
# You can also have spec subclasses
|
28
|
+
describe "nested specs" do
|
29
|
+
# Called inside the before/after of the class that includes SharedExamples
|
30
|
+
before {}
|
31
|
+
after {}
|
32
|
+
|
33
|
+
# Called inside the before/after of the class that includes SharedExamples
|
34
|
+
# and the before/after in this class
|
35
|
+
it "should do something else" do
|
36
|
+
# something
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "something" do
|
42
|
+
include SharedExamples
|
43
|
+
end
|
44
|
+
|
45
|
+
You can also have shared descriptions that are included in other shared descriptions:
|
46
|
+
|
47
|
+
SharedExample1 = shared_description do
|
48
|
+
describe "nested specs 1" do
|
49
|
+
before {}
|
50
|
+
after {}
|
51
|
+
it "should do something" do end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
SharedExample2 = shared_description do
|
56
|
+
describe "nested specs 2" do
|
57
|
+
before {}
|
58
|
+
after {}
|
59
|
+
it "should do something else" do end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
SharedExamples = shared_description do
|
64
|
+
# Include shared description in shared description block
|
65
|
+
include SharedExample1
|
66
|
+
|
67
|
+
describe "nested shared description use" do
|
68
|
+
# Include shared description in shared description class
|
69
|
+
include SharedExample2
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
= License
|
74
|
+
|
75
|
+
MIT
|
76
|
+
|
77
|
+
= Author
|
78
|
+
|
79
|
+
Jeremy Evans <code@jeremyevans.net>
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require "rake"
|
2
|
+
require "rake/clean"
|
3
|
+
|
4
|
+
CLEAN.include ["minitest-shared_description-*.gem", "rdoc", "coverage"]
|
5
|
+
|
6
|
+
desc "Build minitest-hooks gem"
|
7
|
+
task :package=>[:clean] do |p|
|
8
|
+
sh %{#{FileUtils::RUBY} -S gem build minitest-shared_description.gemspec}
|
9
|
+
end
|
10
|
+
|
11
|
+
### Specs
|
12
|
+
|
13
|
+
desc "Run specs"
|
14
|
+
task :spec do
|
15
|
+
sh %{#{FileUtils::RUBY} -I lib -rubygems ./spec/minitest-shared_description_spec.rb}
|
16
|
+
end
|
17
|
+
|
18
|
+
task :default=>:spec
|
19
|
+
|
20
|
+
### RDoc
|
21
|
+
|
22
|
+
RDOC_DEFAULT_OPTS = ["--quiet", "--line-numbers", "--inline-source", '--title', 'minitest-shared_description: support for shared specs and shared spec subclasses']
|
23
|
+
|
24
|
+
begin
|
25
|
+
gem 'hanna-nouveau'
|
26
|
+
RDOC_DEFAULT_OPTS.concat(['-f', 'hanna'])
|
27
|
+
rescue Gem::LoadError
|
28
|
+
end
|
29
|
+
|
30
|
+
rdoc_task_class = begin
|
31
|
+
require "rdoc/task"
|
32
|
+
RDoc::Task
|
33
|
+
rescue LoadError
|
34
|
+
require "rake/rdoctask"
|
35
|
+
Rake::RDocTask
|
36
|
+
end
|
37
|
+
|
38
|
+
RDOC_OPTS = RDOC_DEFAULT_OPTS + ['--main', 'README.rdoc']
|
39
|
+
|
40
|
+
rdoc_task_class.new do |rdoc|
|
41
|
+
rdoc.rdoc_dir = "rdoc"
|
42
|
+
rdoc.options += RDOC_OPTS
|
43
|
+
rdoc.rdoc_files.add %w"README.rdoc CHANGELOG MIT-LICENSE lib/**/*.rb"
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
|
3
|
+
module Minitest::Spec::SharedDescription
|
4
|
+
class DSL < Module
|
5
|
+
include Minitest::Spec::DSL
|
6
|
+
|
7
|
+
# An array of arguments and blocks to pass to describe for classes that
|
8
|
+
# include the current module.
|
9
|
+
attr_reader :shared_descriptions
|
10
|
+
|
11
|
+
# Add a describe block that will be shared by all classes including the current module.
|
12
|
+
# Example:
|
13
|
+
#
|
14
|
+
# EmptyBehavior = shared_description do
|
15
|
+
# describe "empty" do
|
16
|
+
# before do
|
17
|
+
# @that = double
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# it "must be empty?" do
|
21
|
+
# @that.must_be :empty?
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# it "must have size equal to 0" do
|
25
|
+
# @that.size.must_equal 0
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# describe "array" do
|
31
|
+
# def double; @this + @this end
|
32
|
+
#
|
33
|
+
# before do
|
34
|
+
# @this = []
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# include EmptyBehavior
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# describe "hash" do
|
41
|
+
# def double; @this.merge(@this) end
|
42
|
+
#
|
43
|
+
# before do
|
44
|
+
# @this = {}
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# include EmptyBehavior
|
48
|
+
# end
|
49
|
+
def describe(*desc, &block)
|
50
|
+
(@shared_descriptions ||= []) << [desc, block]
|
51
|
+
end
|
52
|
+
|
53
|
+
# If including another shared description module, copy the shared
|
54
|
+
# description class definition blocks into the receiver's.
|
55
|
+
def include(*mods)
|
56
|
+
mods.each do |mod|
|
57
|
+
if mod.is_a?(DSL) && mod.shared_descriptions
|
58
|
+
(@shared_descriptions ||= []).concat(mod.shared_descriptions)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
super
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
module TestMethods
|
66
|
+
# If including a shared description module, create subclasses using
|
67
|
+
# each of the shared description class definition blocks.
|
68
|
+
def include(*mods)
|
69
|
+
mods.each do |mod|
|
70
|
+
if mod.is_a?(DSL) && mod.shared_descriptions
|
71
|
+
mod.shared_descriptions.each do |desc, block|
|
72
|
+
describe(*desc, &block)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
super
|
77
|
+
end
|
78
|
+
|
79
|
+
Minitest::Spec.extend(self)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
module Kernel
|
84
|
+
# Support creating shared descriptions anywhere.
|
85
|
+
def shared_description(&block)
|
86
|
+
Minitest::Spec::SharedDescription::DSL.new(&block)
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/shared_description'
|
3
|
+
|
4
|
+
describe "minitest/shared_description" do
|
5
|
+
def run_runnables(runnables)
|
6
|
+
runnables.each do |runnable|
|
7
|
+
runnable.runnable_methods.each do |method_name|
|
8
|
+
Minitest.run_one_method(runnable, method_name)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
before do
|
14
|
+
@runnables = self.class.runnables.dup
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should handle standard spec inclusion" do
|
18
|
+
runs = []
|
19
|
+
|
20
|
+
x = shared_description do
|
21
|
+
before{(@order ||= []) << :bx}
|
22
|
+
after{@order << :ax; runs << [self.class.name, @order]}
|
23
|
+
it("x"){@order << :x}
|
24
|
+
end
|
25
|
+
|
26
|
+
z = describe "z" do
|
27
|
+
before{(@order ||= []) << :bz}
|
28
|
+
after{@order << :az}
|
29
|
+
it("z"){@order << :z}
|
30
|
+
include x
|
31
|
+
end
|
32
|
+
|
33
|
+
new_runnables = self.class.runnables.dup - @runnables
|
34
|
+
assert_equal %w'z', new_runnables.map(&:name)
|
35
|
+
|
36
|
+
run_runnables(new_runnables)
|
37
|
+
assert_equal [["z", [:bx, :bz, :x, :az, :ax]], ["z", [:bx, :bz, :z, :az, :ax]]], runs.sort_by{|a| a.flatten.map(&:to_s)}
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should handle describe under shared_description" do
|
41
|
+
runs = []
|
42
|
+
|
43
|
+
x = shared_description do
|
44
|
+
describe "x" do
|
45
|
+
before{@order << :bx}
|
46
|
+
after{@order << :ax}
|
47
|
+
it("x"){@order << :x}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
y = shared_description do
|
52
|
+
include x
|
53
|
+
describe "y" do
|
54
|
+
include x
|
55
|
+
before{@order << :by}
|
56
|
+
after{@order << :ay}
|
57
|
+
it("y"){@order << :y}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
z = describe "z" do
|
62
|
+
before{(@order = []) << :bz}
|
63
|
+
after{@order << :az; runs << [self.class.name, @order]}
|
64
|
+
it("z"){@order << :z}
|
65
|
+
include y
|
66
|
+
end
|
67
|
+
|
68
|
+
new_runnables = self.class.runnables.dup - @runnables
|
69
|
+
assert_equal %w'z z::x z::y z::y::x', new_runnables.map(&:name).sort
|
70
|
+
|
71
|
+
run_runnables(new_runnables)
|
72
|
+
assert_equal [["z", [:bz, :z, :az]], ["z::x", [:bz, :bx, :x, :ax, :az]], ["z::y", [:bz, :by, :y, :ay, :az]], ["z::y::x", [:bz, :by, :bx, :x, :ax, :ay, :az]]], runs.sort
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minitest-shared_description
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeremy Evans
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5'
|
27
|
+
description: |
|
28
|
+
minitest-shared_description adds support for shared specs and shared spec subclasses
|
29
|
+
to Minitest. Minitest supports shared specs by default using plain ruby modules, but
|
30
|
+
does not support shared spec subclasses. In addition to making it possible to share
|
31
|
+
subclasses, minitest-shared_desciption also provides a slightly nicer interface for
|
32
|
+
sharing specs.
|
33
|
+
email: code@jeremyevans.net
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files:
|
37
|
+
- README.rdoc
|
38
|
+
- CHANGELOG
|
39
|
+
- MIT-LICENSE
|
40
|
+
files:
|
41
|
+
- CHANGELOG
|
42
|
+
- MIT-LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
- Rakefile
|
45
|
+
- lib/minitest/shared_description.rb
|
46
|
+
- spec/minitest-shared_description_spec.rb
|
47
|
+
homepage: http://github.com/jeremyevans/minitest-shared_description
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- "--quiet"
|
54
|
+
- "--line-numbers"
|
55
|
+
- "--inline-source"
|
56
|
+
- "--title"
|
57
|
+
- 'minitest-shared_description: support for shared specs and shared spec subclasses'
|
58
|
+
- "--main"
|
59
|
+
- README.rdoc
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.4.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Support for shared specs and shared spec subclasses for Minitest
|
78
|
+
test_files: []
|