pork 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitmodules +3 -0
- data/.travis.yml +9 -0
- data/LICENSE +201 -0
- data/README.md +51 -0
- data/Rakefile +14 -0
- data/lib/pork.rb +203 -0
- data/lib/pork/task.rb +2 -0
- data/lib/pork/version.rb +4 -0
- data/pkg/pork-0.1.0.gem +0 -0
- data/pork.gemspec +36 -0
- data/task/README.md +54 -0
- data/task/gemgem.rb +262 -0
- data/test/test_bacon.rb +375 -0
- data/test/test_nested.rb +39 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bcad9c9f6829b54485ba10be4c5f66f353c55b15
|
4
|
+
data.tar.gz: e4e717a01aa1816bbdcb916d55cb062cc1f0ca34
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: edcf6930fe9463137140ef9ed0f6ff7693d6d45d710c15a86fe8332e9ac8d2e60b37b7d39467ecf09c86d7dfe82ea60d229ed1a231c2dcc1519bdadf0de57220
|
7
|
+
data.tar.gz: ab819c314b0fbca15889e258fefadb68238d50bded7fa105a4fa882216038cbb5140959e8cf6bb7eeb05f8a00634740b1b54ac612987f05527307a44470998eb
|
data/.gitmodules
ADDED
data/.travis.yml
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Pork [![Build Status](https://secure.travis-ci.org/godfat/pork.png?branch=master)](http://travis-ci.org/godfat/pork)
|
2
|
+
|
3
|
+
by Lin Jen-Shin ([godfat](http://godfat.org))
|
4
|
+
|
5
|
+
## LINKS:
|
6
|
+
|
7
|
+
* [github](https://github.com/godfat/pork)
|
8
|
+
* [rubygems](https://rubygems.org/gems/pork)
|
9
|
+
* [rdoc](http://rdoc.info/github/godfat/pork)
|
10
|
+
|
11
|
+
## DESCRIPTION:
|
12
|
+
|
13
|
+
[Bacon][] reimplemented in an even more lightweight manner.
|
14
|
+
|
15
|
+
[Bacon]: https://github.com/chneukirchen/bacon
|
16
|
+
|
17
|
+
## WHY?
|
18
|
+
|
19
|
+
[Bacon][] has some issues which can't be easily worked around.
|
20
|
+
|
21
|
+
## REQUIREMENTS:
|
22
|
+
|
23
|
+
* Tested with MRI (official CRuby), Rubinius and JRuby.
|
24
|
+
|
25
|
+
## INSTALLATION:
|
26
|
+
|
27
|
+
gem install pork
|
28
|
+
|
29
|
+
## SYNOPSIS:
|
30
|
+
|
31
|
+
## CONTRIBUTORS:
|
32
|
+
|
33
|
+
* Lin Jen-Shin (@godfat)
|
34
|
+
|
35
|
+
## LICENSE:
|
36
|
+
|
37
|
+
Apache License 2.0
|
38
|
+
|
39
|
+
Copyright (c) 2014, Lin Jen-Shin (godfat)
|
40
|
+
|
41
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
42
|
+
you may not use this file except in compliance with the License.
|
43
|
+
You may obtain a copy of the License at
|
44
|
+
|
45
|
+
<http://www.apache.org/licenses/LICENSE-2.0>
|
46
|
+
|
47
|
+
Unless required by applicable law or agreed to in writing, software
|
48
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
49
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
50
|
+
See the License for the specific language governing permissions and
|
51
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
begin
|
3
|
+
require "#{dir = File.dirname(__FILE__)}/task/gemgem"
|
4
|
+
rescue LoadError
|
5
|
+
sh 'git submodule update --init'
|
6
|
+
exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
|
7
|
+
end
|
8
|
+
|
9
|
+
Gemgem.init(dir) do |s|
|
10
|
+
require 'pork/version'
|
11
|
+
s.name = 'pork'
|
12
|
+
s.version = Pork::VERSION
|
13
|
+
%w[].each{ |g| s.add_runtime_dependency(g) }
|
14
|
+
end
|
data/lib/pork.rb
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
|
2
|
+
require 'thread'
|
3
|
+
|
4
|
+
module Pork
|
5
|
+
class Stats < Struct.new(:tests, :assertions, :skips, :failures, :errors)
|
6
|
+
def initialize
|
7
|
+
@mutex = Mutex.new
|
8
|
+
super(0, 0, 0, [], [])
|
9
|
+
end
|
10
|
+
def assertions= num; @mutex.synchronize{ super }; end
|
11
|
+
def tests= num; @mutex.synchronize{ super }; end
|
12
|
+
def skips= num; @mutex.synchronize{ super ; print('s')}; end
|
13
|
+
def add_failure *e ; @mutex.synchronize{ failures << e; print('F')}; end
|
14
|
+
def add_error *e ; @mutex.synchronize{ errors << e; print('E')}; end
|
15
|
+
def numbers
|
16
|
+
[tests, assertions, failures.size, errors.size, skips]
|
17
|
+
end
|
18
|
+
def start
|
19
|
+
@start ||= Time.now
|
20
|
+
end
|
21
|
+
def report
|
22
|
+
puts
|
23
|
+
puts (failures + errors).map{ |(e, m)|
|
24
|
+
"\n#{m}\n#{e.class}: #{e.message}\n #{backtrace(e)}"
|
25
|
+
}
|
26
|
+
printf("\nFinished in %f seconds.\n", Time.now - @start)
|
27
|
+
printf("%d tests, %d assertions, %d failures, %d errors, %d skips\n",
|
28
|
+
*numbers)
|
29
|
+
end
|
30
|
+
private
|
31
|
+
def backtrace e
|
32
|
+
if $VERBOSE
|
33
|
+
e.backtrace
|
34
|
+
else
|
35
|
+
e.backtrace.reject{ |line| line =~ %r{/pork\.rb:\d+} }
|
36
|
+
end.join("\n ")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.stats ; @stats ||= Stats.new; end
|
41
|
+
def self.reset ; @stats = nil ; end
|
42
|
+
def self.report; stats.report; reset ; end
|
43
|
+
|
44
|
+
module API
|
45
|
+
module_function
|
46
|
+
def describe desc, &suite
|
47
|
+
Pork.stats.start
|
48
|
+
Pork::Executor.execute(self, desc, &suite)
|
49
|
+
Pork.stats.tests += 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
Error = Class.new(Exception)
|
54
|
+
Failure = Class.new(Error)
|
55
|
+
Skip = Class.new(Error)
|
56
|
+
|
57
|
+
class Executor < Struct.new(:name)
|
58
|
+
extend Pork::API
|
59
|
+
def self.execute caller, desc, &suite
|
60
|
+
parent = if caller.kind_of?(Class) then caller else self end
|
61
|
+
Class.new(parent){
|
62
|
+
@desc, @before, @after = "#{desc}:", [], []
|
63
|
+
}.module_eval(&suite)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.would name, &test
|
67
|
+
assertions = Pork.stats.assertions
|
68
|
+
context = new(name)
|
69
|
+
run_before(context)
|
70
|
+
context.instance_eval(&test)
|
71
|
+
if assertions == Pork.stats.assertions
|
72
|
+
raise Error.new('Missing assertions')
|
73
|
+
end
|
74
|
+
rescue Error, StandardError => e
|
75
|
+
case e
|
76
|
+
when Skip
|
77
|
+
Pork.stats.skips += 1
|
78
|
+
when Failure
|
79
|
+
Pork.stats.add_failure(e, description_for("would #{name}"))
|
80
|
+
when Error, StandardError
|
81
|
+
Pork.stats.add_error( e, description_for("would #{name}"))
|
82
|
+
end
|
83
|
+
else
|
84
|
+
print '.'
|
85
|
+
ensure
|
86
|
+
run_after(context)
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.before &block
|
90
|
+
if block_given? then @before << block else @before end
|
91
|
+
end
|
92
|
+
def self.after &block
|
93
|
+
if block_given? then @after << block else @after end
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.super_executor
|
97
|
+
@super_executor ||= ancestors[1..-1].find{ |a| a < Executor }
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.description_for name=''
|
101
|
+
supername = if super_executor
|
102
|
+
" #{super_executor.description_for}"
|
103
|
+
else
|
104
|
+
' '
|
105
|
+
end
|
106
|
+
"#{@desc}#{supername}#{name}"
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.run_before context
|
110
|
+
super_executor.run_before(context) if super_executor
|
111
|
+
before.each{ |b| context.instance_eval(&b) }
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.run_after context
|
115
|
+
super_executor.run_after(context) if super_executor
|
116
|
+
after.each{ |b| context.instance_eval(&b) }
|
117
|
+
end
|
118
|
+
|
119
|
+
def skip
|
120
|
+
raise Skip.new("Skipping #{name}")
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
class Should < BasicObject
|
125
|
+
instance_methods.each{ |m| undef_method(m) unless m =~ /^__|^object_id$/ }
|
126
|
+
|
127
|
+
def initialize object, message, &checker
|
128
|
+
@object = object
|
129
|
+
@negate = false
|
130
|
+
@message = message
|
131
|
+
satisfy(&checker) if checker
|
132
|
+
end
|
133
|
+
|
134
|
+
def method_missing msg, *args, &block
|
135
|
+
satisfy("#{@object.inspect}.#{msg}(#{args.join(', ')}) to" \
|
136
|
+
" return #{!@negate}") do
|
137
|
+
@object.public_send(msg, *args, &block)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def satisfy desc=@object
|
142
|
+
result = yield(@object)
|
143
|
+
if !!result == @negate
|
144
|
+
::Kernel.raise Failure.new("Expect #{desc}\n#{@message}".chomp)
|
145
|
+
else
|
146
|
+
::Pork.stats.assertions += 1
|
147
|
+
end
|
148
|
+
result
|
149
|
+
end
|
150
|
+
|
151
|
+
def not &checker
|
152
|
+
@negate = !@negate
|
153
|
+
satisfy(&checker) if checker
|
154
|
+
self
|
155
|
+
end
|
156
|
+
|
157
|
+
def eq rhs
|
158
|
+
self == rhs
|
159
|
+
end
|
160
|
+
|
161
|
+
def raise exception=::RuntimeError
|
162
|
+
satisfy("#{__not__}raising #{exception}") do
|
163
|
+
begin
|
164
|
+
if ::Kernel.block_given? then yield else @object.call end
|
165
|
+
rescue exception => e
|
166
|
+
e
|
167
|
+
else
|
168
|
+
false
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def throw msg
|
174
|
+
satisfy("#{__not__}throwing #{msg}") do
|
175
|
+
flag = true
|
176
|
+
::Kernel.catch(msg) do
|
177
|
+
if ::Kernel.block_given? then yield else @object.call end
|
178
|
+
flag = false
|
179
|
+
end
|
180
|
+
flag
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def flunk reason='Flunked'
|
185
|
+
::Kernel.raise Error.new(reason)
|
186
|
+
end
|
187
|
+
|
188
|
+
private
|
189
|
+
def __not__
|
190
|
+
if @negate == true
|
191
|
+
'not '
|
192
|
+
else
|
193
|
+
''
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
module Kernel
|
200
|
+
def should message=nil, &checker
|
201
|
+
Pork::Should.new(self, message, &checker)
|
202
|
+
end
|
203
|
+
end
|
data/lib/pork/task.rb
ADDED
data/lib/pork/version.rb
ADDED
data/pkg/pork-0.1.0.gem
ADDED
Binary file
|
data/pork.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# stub: pork 0.1.0 ruby lib
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "pork"
|
6
|
+
s.version = "0.1.0"
|
7
|
+
|
8
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
|
+
s.require_paths = ["lib"]
|
10
|
+
s.authors = ["Lin Jen-Shin (godfat)"]
|
11
|
+
s.date = "2014-07-09"
|
12
|
+
s.description = "[Bacon][] reimplemented in an even more lightweight manner.\n\n[Bacon]: https://github.com/chneukirchen/bacon"
|
13
|
+
s.email = ["godfat (XD) godfat.org"]
|
14
|
+
s.files = [
|
15
|
+
".gitmodules",
|
16
|
+
".travis.yml",
|
17
|
+
"LICENSE",
|
18
|
+
"README.md",
|
19
|
+
"Rakefile",
|
20
|
+
"lib/pork.rb",
|
21
|
+
"lib/pork/task.rb",
|
22
|
+
"lib/pork/version.rb",
|
23
|
+
"pkg/pork-0.1.0.gem",
|
24
|
+
"pork.gemspec",
|
25
|
+
"task/README.md",
|
26
|
+
"task/gemgem.rb",
|
27
|
+
"test/test_bacon.rb",
|
28
|
+
"test/test_nested.rb"]
|
29
|
+
s.homepage = "https://github.com/godfat/pork"
|
30
|
+
s.licenses = ["Apache License 2.0"]
|
31
|
+
s.rubygems_version = "2.3.0"
|
32
|
+
s.summary = "[Bacon][] reimplemented in an even more lightweight manner."
|
33
|
+
s.test_files = [
|
34
|
+
"test/test_bacon.rb",
|
35
|
+
"test/test_nested.rb"]
|
36
|
+
end
|
data/task/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Gemgem
|
2
|
+
|
3
|
+
## DESCRIPTION:
|
4
|
+
|
5
|
+
Provided tasks:
|
6
|
+
|
7
|
+
rake clean # Remove ignored files
|
8
|
+
rake gem:build # Build gem
|
9
|
+
rake gem:install # Install gem
|
10
|
+
rake gem:release # Release gem
|
11
|
+
rake gem:spec # Generate gemspec
|
12
|
+
rake test # Run tests in memory
|
13
|
+
|
14
|
+
## REQUIREMENTS:
|
15
|
+
|
16
|
+
* Tested with MRI (official CRuby) 1.9.3, 2.0.0, Rubinius and JRuby.
|
17
|
+
|
18
|
+
## INSTALLATION:
|
19
|
+
|
20
|
+
git submodule add git://github.com/godfat/gemgem.git task
|
21
|
+
|
22
|
+
And in Rakefile:
|
23
|
+
|
24
|
+
``` ruby
|
25
|
+
begin
|
26
|
+
require "#{dir = File.dirname(__FILE__)}/task/gemgem"
|
27
|
+
rescue LoadError
|
28
|
+
sh 'git submodule update --init'
|
29
|
+
exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
|
30
|
+
end
|
31
|
+
|
32
|
+
Gemgem.init(dir) do |s|
|
33
|
+
s.name = 'your-gem'
|
34
|
+
s.version = '0.1.0'
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
## LICENSE:
|
39
|
+
|
40
|
+
Apache License 2.0
|
41
|
+
|
42
|
+
Copyright (c) 2011-2013, Lin Jen-Shin (godfat)
|
43
|
+
|
44
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
45
|
+
you may not use this file except in compliance with the License.
|
46
|
+
You may obtain a copy of the License at
|
47
|
+
|
48
|
+
<http://www.apache.org/licenses/LICENSE-2.0>
|
49
|
+
|
50
|
+
Unless required by applicable law or agreed to in writing, software
|
51
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
52
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
53
|
+
See the License for the specific language governing permissions and
|
54
|
+
limitations under the License.
|
data/task/gemgem.rb
ADDED
@@ -0,0 +1,262 @@
|
|
1
|
+
|
2
|
+
module Gemgem
|
3
|
+
class << self
|
4
|
+
attr_accessor :dir, :spec, :spec_create
|
5
|
+
end
|
6
|
+
|
7
|
+
module_function
|
8
|
+
def gem_tag ; "#{spec.name}-#{spec.version}" ; end
|
9
|
+
def gem_path ; "#{pkg_dir}/#{gem_tag}.gem" ; end
|
10
|
+
def spec_path ; "#{dir}/#{spec.name}.gemspec" ; end
|
11
|
+
def pkg_dir ; "#{dir}/pkg" ; end
|
12
|
+
def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
|
13
|
+
|
14
|
+
def init dir, &block
|
15
|
+
self.dir = dir
|
16
|
+
$LOAD_PATH.unshift("#{dir}/lib")
|
17
|
+
ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
|
18
|
+
ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
|
19
|
+
self.spec_create = block
|
20
|
+
end
|
21
|
+
|
22
|
+
def create
|
23
|
+
spec = Gem::Specification.new do |s|
|
24
|
+
s.authors = ['Lin Jen-Shin (godfat)']
|
25
|
+
s.email = ['godfat (XD) godfat.org']
|
26
|
+
|
27
|
+
s.description = description.join
|
28
|
+
s.summary = description.first
|
29
|
+
s.license = readme['LICENSE'].sub(/.+\n\n/, '').lines.first.strip
|
30
|
+
|
31
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
32
|
+
s.files = gem_files
|
33
|
+
s.test_files = test_files
|
34
|
+
s.executables = bin_files
|
35
|
+
end
|
36
|
+
spec_create.call(spec)
|
37
|
+
spec.homepage ||= "https://github.com/godfat/#{spec.name}"
|
38
|
+
self.spec = spec
|
39
|
+
end
|
40
|
+
|
41
|
+
def write
|
42
|
+
File.open(spec_path, 'w'){ |f| f << split_lines(spec.to_ruby) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def split_lines ruby
|
46
|
+
ruby.gsub(/(.+?)\s*=\s*\[(.+?)\]/){ |s|
|
47
|
+
if $2.index(',')
|
48
|
+
"#{$1} = [\n #{$2.split(',').map(&:strip).join(",\n ")}]"
|
49
|
+
else
|
50
|
+
s
|
51
|
+
end
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def strip_path path
|
56
|
+
strip_home_path(strip_cwd_path(path))
|
57
|
+
end
|
58
|
+
|
59
|
+
def strip_home_path path
|
60
|
+
path.sub(ENV['HOME'], '~')
|
61
|
+
end
|
62
|
+
|
63
|
+
def strip_cwd_path path
|
64
|
+
path.sub(Dir.pwd, '.')
|
65
|
+
end
|
66
|
+
|
67
|
+
def git *args
|
68
|
+
`git --git-dir=#{dir}/.git #{args.join(' ')}`
|
69
|
+
end
|
70
|
+
|
71
|
+
def sh_git *args
|
72
|
+
Rake.sh('git', "--git-dir=#{dir}/.git", *args)
|
73
|
+
end
|
74
|
+
|
75
|
+
def sh_gem *args
|
76
|
+
Rake.sh(Gem.ruby, '-S', 'gem', *args)
|
77
|
+
end
|
78
|
+
|
79
|
+
def glob path=dir
|
80
|
+
Dir.glob("#{path}/**/*", File::FNM_DOTMATCH)
|
81
|
+
end
|
82
|
+
|
83
|
+
def readme
|
84
|
+
@readme ||=
|
85
|
+
if (path = "#{Gemgem.dir}/README.md") && File.exist?(path)
|
86
|
+
ps = "##{File.read(path)}".
|
87
|
+
scan(/((#+)[^\n]+\n\n.+?(?=(\n\n\2[^#\n]+\n)|\Z))/m).map(&:first)
|
88
|
+
ps.inject('HEADER' => ps.first){ |r, s, i|
|
89
|
+
r[s[/\w+/]] = s
|
90
|
+
r
|
91
|
+
}
|
92
|
+
else
|
93
|
+
{}
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def description
|
98
|
+
# JRuby String#lines is returning an enumerator
|
99
|
+
@description ||= (readme['DESCRIPTION']||'').sub(/.+\n\n/, '').lines.to_a
|
100
|
+
end
|
101
|
+
|
102
|
+
def all_files
|
103
|
+
@all_files ||= fold_files(glob).sort
|
104
|
+
end
|
105
|
+
|
106
|
+
def fold_files files
|
107
|
+
files.inject([]){ |r, path|
|
108
|
+
if File.file?(path) && path !~ %r{/\.git(/|$)} &&
|
109
|
+
(rpath = path[%r{^#{escaped_dir}/(.*$)}, 1])
|
110
|
+
r << rpath
|
111
|
+
elsif File.symlink?(path) # walk into symlinks...
|
112
|
+
r.concat(fold_files(glob(File.expand_path(path,
|
113
|
+
File.readlink(path)))))
|
114
|
+
else
|
115
|
+
r
|
116
|
+
end
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
def gem_files
|
121
|
+
@gem_files ||= all_files.reject{ |f|
|
122
|
+
f =~ ignored_pattern && !git_files.include?(f)
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_files
|
127
|
+
@test_files ||= gem_files.grep(%r{^test/(.+?/)*test_.+?\.rb$})
|
128
|
+
end
|
129
|
+
|
130
|
+
def bin_files
|
131
|
+
@bin_files ||= gem_files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
132
|
+
end
|
133
|
+
|
134
|
+
def git_files
|
135
|
+
@git_files ||= if File.exist?("#{dir}/.git")
|
136
|
+
git('ls-files').split("\n")
|
137
|
+
else
|
138
|
+
[]
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def ignored_files
|
143
|
+
@ignored_files ||= all_files.grep(ignored_pattern)
|
144
|
+
end
|
145
|
+
|
146
|
+
def ignored_pattern
|
147
|
+
@ignored_pattern ||= if gitignore.empty?
|
148
|
+
/^$/
|
149
|
+
else
|
150
|
+
Regexp.new(expand_patterns(gitignore).join('|'))
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def expand_patterns pathes
|
155
|
+
# http://git-scm.com/docs/gitignore
|
156
|
+
pathes.flat_map{ |path|
|
157
|
+
# we didn't implement negative pattern for now
|
158
|
+
Regexp.escape(path).sub(%r{^/}, '^').gsub(/\\\*/, '[^/]*')
|
159
|
+
}
|
160
|
+
end
|
161
|
+
|
162
|
+
def gitignore
|
163
|
+
@gitignore ||= if File.exist?(path = "#{dir}/.gitignore")
|
164
|
+
File.read(path).lines.
|
165
|
+
reject{ |l| l == /^\s*(#|\s+$)/ }.map(&:strip)
|
166
|
+
else
|
167
|
+
[]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
namespace :gem do
|
173
|
+
|
174
|
+
desc 'Install gem'
|
175
|
+
task :install => [:build] do
|
176
|
+
Gemgem.sh_gem('install', Gemgem.gem_path)
|
177
|
+
end
|
178
|
+
|
179
|
+
desc 'Build gem'
|
180
|
+
task :build => [:spec] do
|
181
|
+
require 'fileutils'
|
182
|
+
require 'rubygems/package'
|
183
|
+
gem = nil
|
184
|
+
Dir.chdir(Gemgem.dir) do
|
185
|
+
gem = Gem::Package.build(Gem::Specification.load(Gemgem.spec_path))
|
186
|
+
FileUtils.mkdir_p(Gemgem.pkg_dir)
|
187
|
+
FileUtils.mv(gem, Gemgem.pkg_dir) # gem is relative path, but might be ok
|
188
|
+
end
|
189
|
+
puts "\e[35mGem built: \e[33m" \
|
190
|
+
"#{Gemgem.strip_path("#{Gemgem.pkg_dir}/#{gem}")}\e[0m"
|
191
|
+
end
|
192
|
+
|
193
|
+
desc 'Generate gemspec'
|
194
|
+
task :spec do
|
195
|
+
Gemgem.create
|
196
|
+
Gemgem.write
|
197
|
+
end
|
198
|
+
|
199
|
+
desc 'Release gem'
|
200
|
+
task :release => [:spec, :check, :build] do
|
201
|
+
Gemgem.module_eval do
|
202
|
+
sh_git('tag', Gemgem.gem_tag)
|
203
|
+
sh_git('push')
|
204
|
+
sh_git('push', '--tags')
|
205
|
+
sh_gem('push', Gemgem.gem_path)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
task :check do
|
210
|
+
ver = Gemgem.spec.version.to_s
|
211
|
+
|
212
|
+
if ENV['VERSION'].nil?
|
213
|
+
puts("\e[35mExpected " \
|
214
|
+
"\e[33mVERSION\e[35m=\e[33m#{ver}\e[0m")
|
215
|
+
exit(1)
|
216
|
+
|
217
|
+
elsif ENV['VERSION'] != ver
|
218
|
+
puts("\e[35mExpected \e[33mVERSION\e[35m=\e[33m#{ver} " \
|
219
|
+
"\e[35mbut got\n " \
|
220
|
+
"\e[33mVERSION\e[35m=\e[33m#{ENV['VERSION']}\e[0m")
|
221
|
+
exit(2)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
end # of gem namespace
|
226
|
+
|
227
|
+
desc 'Run tests'
|
228
|
+
task :test do
|
229
|
+
next if Gemgem.test_files.empty?
|
230
|
+
|
231
|
+
# require 'bacon'
|
232
|
+
# Bacon.extend(Bacon::TestUnitOutput)
|
233
|
+
# Bacon.summary_on_exit
|
234
|
+
Gemgem.test_files.each{ |file| require "#{Gemgem.dir}/#{file[0..-4]}" }
|
235
|
+
end
|
236
|
+
|
237
|
+
desc 'Trash ignored files'
|
238
|
+
task :clean => ['gem:spec'] do
|
239
|
+
next if Gemgem.ignored_files.empty?
|
240
|
+
|
241
|
+
require 'fileutils'
|
242
|
+
trash = File.expand_path("~/.Trash/#{Gemgem.spec.name}")
|
243
|
+
puts "Move the following files into:" \
|
244
|
+
" \e[35m#{Gemgem.strip_path(trash)}\e[33m"
|
245
|
+
|
246
|
+
Gemgem.ignored_files.each do |file|
|
247
|
+
from = "#{Gemgem.dir}/#{file}"
|
248
|
+
to = "#{trash}/#{File.dirname(file)}"
|
249
|
+
puts Gemgem.strip_path(from)
|
250
|
+
|
251
|
+
FileUtils.mkdir_p(to)
|
252
|
+
FileUtils.mv(from, to)
|
253
|
+
end
|
254
|
+
|
255
|
+
print "\e[0m"
|
256
|
+
end
|
257
|
+
|
258
|
+
task :default do
|
259
|
+
# Is there a reliable way to do this in the current process?
|
260
|
+
# It failed miserably before between Rake versions...
|
261
|
+
exec "#{Gem.ruby} -S #{$PROGRAM_NAME} -f #{Rake.application.rakefile} -T"
|
262
|
+
end
|
data/test/test_bacon.rb
ADDED
@@ -0,0 +1,375 @@
|
|
1
|
+
|
2
|
+
require 'pork'
|
3
|
+
|
4
|
+
# Hooray for meta-testing.
|
5
|
+
module MetaTests
|
6
|
+
def succeed block
|
7
|
+
block.should.not.raise Pork::Error
|
8
|
+
end
|
9
|
+
|
10
|
+
def fail block
|
11
|
+
block.should.raise Pork::Error
|
12
|
+
end
|
13
|
+
|
14
|
+
def equal_string x
|
15
|
+
lambda{ |s| x == s.to_s }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Pork::API.describe Pork do
|
20
|
+
include MetaTests
|
21
|
+
|
22
|
+
would "have should.satisfy" do
|
23
|
+
succeed lambda { should.satisfy { 1 == 1 } }
|
24
|
+
succeed lambda { should.satisfy { 1 } }
|
25
|
+
|
26
|
+
fail lambda { should.satisfy { 1 != 1 } }
|
27
|
+
fail lambda { should.satisfy { false } }
|
28
|
+
|
29
|
+
fail lambda { 1.should.satisfy { |n| n % 2 == 0 } }
|
30
|
+
succeed lambda { 2.should.satisfy { |n| n % 2 == 0 } }
|
31
|
+
end
|
32
|
+
|
33
|
+
would "have should.==" do
|
34
|
+
succeed lambda { "string1".should == "string1" }
|
35
|
+
fail lambda { "string1".should == "string2" }
|
36
|
+
|
37
|
+
succeed lambda { [1,2,3].should == [1,2,3] }
|
38
|
+
fail lambda { [1,2,3].should == [1,2,4] }
|
39
|
+
end
|
40
|
+
|
41
|
+
would "have should.eq" do
|
42
|
+
succeed lambda { "string1".should == "string1" }
|
43
|
+
fail lambda { "string1".should == "string2" }
|
44
|
+
fail lambda { "1".should == 1 }
|
45
|
+
|
46
|
+
succeed lambda { "string1".should.eq "string1" }
|
47
|
+
fail lambda { "string1".should.eq "string2" }
|
48
|
+
fail lambda { "1".should.eq 1 }
|
49
|
+
end
|
50
|
+
|
51
|
+
would "have should.raise" do
|
52
|
+
succeed lambda { lambda { raise "Error" }.should.raise }
|
53
|
+
succeed lambda { lambda { raise "Error" }.should.raise RuntimeError }
|
54
|
+
fail lambda { lambda { raise "Error" }.should.not.raise }
|
55
|
+
fail lambda { lambda { raise "Error" }.should.not.raise RuntimeError }
|
56
|
+
|
57
|
+
fail lambda { lambda { 1 + 1 }.should.raise }
|
58
|
+
lambda {
|
59
|
+
lambda { raise "Error" }.should.raise(Interrupt)
|
60
|
+
}.should.raise
|
61
|
+
end
|
62
|
+
|
63
|
+
would "should.raise with a block" do
|
64
|
+
succeed lambda { should.raise { raise "Error" } }
|
65
|
+
succeed lambda { should.raise(RuntimeError) { raise "Error" } }
|
66
|
+
fail lambda { should.not.raise { raise "Error" } }
|
67
|
+
fail lambda { should.not.raise(RuntimeError) { raise "Error" } }
|
68
|
+
|
69
|
+
fail lambda { should.raise { 1 + 1 } }
|
70
|
+
lambda {
|
71
|
+
should.raise(Interrupt) { raise "Error" }
|
72
|
+
}.should.raise
|
73
|
+
end
|
74
|
+
|
75
|
+
would "have a should.raise should return the exception" do
|
76
|
+
ex = lambda { raise "foo!" }.should.raise
|
77
|
+
ex.should.kind_of? RuntimeError
|
78
|
+
ex.message.should =~ /foo/
|
79
|
+
end
|
80
|
+
|
81
|
+
would "have should.nil?" do
|
82
|
+
succeed lambda { nil.should.nil? }
|
83
|
+
fail lambda { nil.should.not.nil? }
|
84
|
+
fail lambda { "foo".should.nil? }
|
85
|
+
succeed lambda { "foo".should.not.nil? }
|
86
|
+
end
|
87
|
+
|
88
|
+
would "have should.include?" do
|
89
|
+
succeed lambda { [1,2,3].should.include? 2 }
|
90
|
+
fail lambda { [1,2,3].should.include? 4 }
|
91
|
+
|
92
|
+
succeed lambda { {1=>2, 3=>4}.should.include? 1 }
|
93
|
+
fail lambda { {1=>2, 3=>4}.should.include? 2 }
|
94
|
+
end
|
95
|
+
|
96
|
+
would "have should.kind_of?" do
|
97
|
+
succeed lambda { Array.should.kind_of? Module }
|
98
|
+
succeed lambda { "string".should.kind_of? Object }
|
99
|
+
succeed lambda { 1.should.kind_of? Comparable }
|
100
|
+
|
101
|
+
succeed lambda { Array.should.kind_of? Module }
|
102
|
+
fail lambda { "string".should.kind_of? Class }
|
103
|
+
end
|
104
|
+
|
105
|
+
would "have should.match" do
|
106
|
+
succeed lambda { "string".should.match(/strin./) }
|
107
|
+
succeed lambda { "string".should =~ /strin./ }
|
108
|
+
|
109
|
+
fail lambda { "string".should.match(/slin./) }
|
110
|
+
fail lambda { "string".should =~ /slin./ }
|
111
|
+
end
|
112
|
+
|
113
|
+
would "have should.not.raise" do
|
114
|
+
succeed lambda { lambda { 1 + 1 }.should.not.raise }
|
115
|
+
succeed lambda { lambda { 1 + 1 }.should.not.raise(Interrupt) }
|
116
|
+
|
117
|
+
succeed lambda {
|
118
|
+
lambda {
|
119
|
+
lambda {
|
120
|
+
raise ZeroDivisionError.new("ArgumentError")
|
121
|
+
}.should.not.raise(RuntimeError)
|
122
|
+
}.should.raise(ZeroDivisionError)
|
123
|
+
}
|
124
|
+
|
125
|
+
fail lambda { lambda { raise "Error" }.should.not.raise }
|
126
|
+
end
|
127
|
+
|
128
|
+
would "have should.throw" do
|
129
|
+
succeed lambda { lambda { throw :foo }.should.throw(:foo) }
|
130
|
+
fail lambda { lambda { :foo }.should.throw(:foo) }
|
131
|
+
|
132
|
+
should.throw(:foo) { throw :foo }
|
133
|
+
end
|
134
|
+
|
135
|
+
would "have should.not.satisfy" do
|
136
|
+
succeed lambda { should.not.satisfy { 1 == 2 } }
|
137
|
+
fail lambda { should.not.satisfy { 1 == 1 } }
|
138
|
+
end
|
139
|
+
|
140
|
+
would "have should.not.equal" do
|
141
|
+
succeed lambda { "string1".should.not == "string2" }
|
142
|
+
fail lambda { "string1".should.not == "string1" }
|
143
|
+
end
|
144
|
+
|
145
|
+
would "have should.not.match" do
|
146
|
+
succeed lambda { "string".should.not.match(/sling/) }
|
147
|
+
fail lambda { "string".should.not.match(/string/) }
|
148
|
+
fail lambda { "string".should.not.match("strin") }
|
149
|
+
|
150
|
+
succeed lambda { "string".should.not =~ /sling/ }
|
151
|
+
fail lambda { "string".should.not =~ /string/ }
|
152
|
+
end
|
153
|
+
|
154
|
+
would "have should.respond_to" do
|
155
|
+
succeed lambda { "foo".should.respond_to? :to_s }
|
156
|
+
fail lambda { 5.should.respond_to? :to_str }
|
157
|
+
fail lambda { :foo.should.respond_to? :nx }
|
158
|
+
end
|
159
|
+
|
160
|
+
would "support multiple negation" do
|
161
|
+
succeed lambda { 1.should.eq 1 }
|
162
|
+
fail lambda { 1.should.not.eq 1 }
|
163
|
+
succeed lambda { 1.should.not.not.eq 1 }
|
164
|
+
fail lambda { 1.should.not.not.not.eq 1 }
|
165
|
+
|
166
|
+
fail lambda { 1.should.eq 2 }
|
167
|
+
succeed lambda { 1.should.not.eq 2 }
|
168
|
+
fail lambda { 1.should.not.not.eq 2 }
|
169
|
+
succeed lambda { 1.should.not.not.not.eq 2 }
|
170
|
+
end
|
171
|
+
|
172
|
+
would "have should.<predicate>" do
|
173
|
+
succeed lambda { [].should.empty? }
|
174
|
+
succeed lambda { [1,2,3].should.not.empty? }
|
175
|
+
|
176
|
+
fail lambda { [].should.not.empty? }
|
177
|
+
fail lambda { [1,2,3].should.empty? }
|
178
|
+
|
179
|
+
succeed lambda { {1=>2, 3=>4}.should.has_key? 1 }
|
180
|
+
succeed lambda { {1=>2, 3=>4}.should.not.has_key? 2 }
|
181
|
+
|
182
|
+
lambda { nil.should.bla }.should.raise(NoMethodError)
|
183
|
+
lambda { nil.should.not.bla }.should.raise(NoMethodError)
|
184
|
+
end
|
185
|
+
|
186
|
+
would "have should <operator> (>, >=, <, <=, ===)" do
|
187
|
+
succeed lambda { 2.should > 1 }
|
188
|
+
fail lambda { 1.should > 2 }
|
189
|
+
|
190
|
+
succeed lambda { 1.should < 2 }
|
191
|
+
fail lambda { 2.should < 1 }
|
192
|
+
|
193
|
+
succeed lambda { 2.should >= 1 }
|
194
|
+
succeed lambda { 2.should >= 2 }
|
195
|
+
fail lambda { 2.should >= 2.1 }
|
196
|
+
|
197
|
+
fail lambda { 2.should <= 1 }
|
198
|
+
succeed lambda { 2.should <= 2 }
|
199
|
+
succeed lambda { 2.should <= 2.1 }
|
200
|
+
|
201
|
+
succeed lambda { Array.should === [1,2,3] }
|
202
|
+
fail lambda { Integer.should === [1,2,3] }
|
203
|
+
|
204
|
+
succeed lambda { /foo/.should === "foobar" }
|
205
|
+
fail lambda { "foobar".should === /foo/ }
|
206
|
+
end
|
207
|
+
|
208
|
+
would "allow for custom shoulds" do
|
209
|
+
f = equal_string("2")
|
210
|
+
succeed lambda { (1+1).should(&f) }
|
211
|
+
fail lambda { (1+2).should(&f) }
|
212
|
+
|
213
|
+
succeed lambda { (1+1).should(&f) }
|
214
|
+
fail lambda { (1+2).should(&f) }
|
215
|
+
|
216
|
+
fail lambda { (1+1).should.not(&f) }
|
217
|
+
succeed lambda { (1+2).should.not(&f) }
|
218
|
+
fail lambda { (1+2).should.not.not(&f) }
|
219
|
+
|
220
|
+
fail lambda { (1+1).should.not(&f) }
|
221
|
+
succeed lambda { (1+2).should.not(&f) }
|
222
|
+
end
|
223
|
+
|
224
|
+
would "have should.flunk" do
|
225
|
+
fail lambda { should.flunk }
|
226
|
+
fail lambda { should.flunk "yikes" }
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
Pork::API.describe "before/after" do
|
231
|
+
before do
|
232
|
+
@a = 1
|
233
|
+
@b = 2
|
234
|
+
@c = nil
|
235
|
+
end
|
236
|
+
|
237
|
+
before do
|
238
|
+
@a = 2
|
239
|
+
end
|
240
|
+
|
241
|
+
after do
|
242
|
+
@a.should.eq 2
|
243
|
+
@a = 3
|
244
|
+
end
|
245
|
+
|
246
|
+
after do
|
247
|
+
@a.should.eq 3
|
248
|
+
end
|
249
|
+
|
250
|
+
would "run in the right order" do
|
251
|
+
@a.should.eq 2
|
252
|
+
@b.should.eq 2
|
253
|
+
end
|
254
|
+
|
255
|
+
describe "when nested" do
|
256
|
+
before do
|
257
|
+
@c = 5
|
258
|
+
end
|
259
|
+
|
260
|
+
would "run from higher level" do
|
261
|
+
@a.should.eq 2
|
262
|
+
@b.should.eq 2
|
263
|
+
end
|
264
|
+
|
265
|
+
would "run at the nested level" do
|
266
|
+
@c.should.eq 5
|
267
|
+
end
|
268
|
+
|
269
|
+
before do
|
270
|
+
@a = 5
|
271
|
+
end
|
272
|
+
|
273
|
+
would "run in the right order" do
|
274
|
+
@a.should.eq 5
|
275
|
+
@a = 2
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
would "not run from lower level" do
|
280
|
+
@c.should.nil?
|
281
|
+
end
|
282
|
+
|
283
|
+
describe "when nested at a sibling level" do
|
284
|
+
would "not run from sibling level" do
|
285
|
+
@c.should.nil?
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
# shared "a shared context" do
|
291
|
+
# it "gets called where it is included" do
|
292
|
+
# true.should.be.true
|
293
|
+
# end
|
294
|
+
# end
|
295
|
+
|
296
|
+
# shared "another shared context" do
|
297
|
+
# it "can access data" do
|
298
|
+
# @magic.should.be.equal 42
|
299
|
+
# end
|
300
|
+
# end
|
301
|
+
|
302
|
+
# describe "shared/behaves_like" do
|
303
|
+
# behaves_like "a shared context"
|
304
|
+
|
305
|
+
# ctx = self
|
306
|
+
# it "raises NameError when the context is not found" do
|
307
|
+
# lambda {
|
308
|
+
# ctx.behaves_like "whoops"
|
309
|
+
# }.should.raise NameError
|
310
|
+
# end
|
311
|
+
|
312
|
+
# behaves_like "a shared context"
|
313
|
+
|
314
|
+
# before {
|
315
|
+
# @magic = 42
|
316
|
+
# }
|
317
|
+
# behaves_like "another shared context"
|
318
|
+
# end
|
319
|
+
|
320
|
+
# describe "Methods" do
|
321
|
+
# def the_meaning_of_life
|
322
|
+
# 42
|
323
|
+
# end
|
324
|
+
|
325
|
+
# def the_towels
|
326
|
+
# yield "DON'T PANIC"
|
327
|
+
# end
|
328
|
+
|
329
|
+
# it "should be accessible in a test" do
|
330
|
+
# the_meaning_of_life.should == 42
|
331
|
+
# end
|
332
|
+
|
333
|
+
# describe "when in a sibling context" do
|
334
|
+
# it "should be accessible in a test" do
|
335
|
+
# the_meaning_of_life.should == 42
|
336
|
+
# end
|
337
|
+
|
338
|
+
# it "should pass the block" do
|
339
|
+
# the_towels do |label|
|
340
|
+
# label.should == "DON'T PANIC"
|
341
|
+
# end.should == true
|
342
|
+
# end
|
343
|
+
# end
|
344
|
+
# end
|
345
|
+
|
346
|
+
# describe 'describe arguments' do
|
347
|
+
|
348
|
+
# def check(ctx,name)
|
349
|
+
# ctx.should.be.an.instance_of Bacon::Context
|
350
|
+
# ctx.instance_variable_get('@name').should == name
|
351
|
+
# end
|
352
|
+
|
353
|
+
# it 'should work with string' do
|
354
|
+
# check(describe('string') {},'string')
|
355
|
+
# end
|
356
|
+
|
357
|
+
# it 'should work with symbols' do
|
358
|
+
# check(describe(:behaviour) {},'behaviour')
|
359
|
+
# end
|
360
|
+
|
361
|
+
# it 'should work with modules' do
|
362
|
+
# check(describe(Bacon) {},'Bacon')
|
363
|
+
# end
|
364
|
+
|
365
|
+
# it 'should work with namespaced modules' do
|
366
|
+
# check(describe(Bacon::Context) {},'Bacon::Context')
|
367
|
+
# end
|
368
|
+
|
369
|
+
# it 'should work with multiple arguments' do
|
370
|
+
# check(describe(Bacon::Context, :empty) {},'Bacon::Context empty')
|
371
|
+
# end
|
372
|
+
|
373
|
+
# end
|
374
|
+
|
375
|
+
Pork.report
|
data/test/test_nested.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
require 'pork'
|
3
|
+
|
4
|
+
module M
|
5
|
+
def m
|
6
|
+
object_id
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
Pork::API.describe 'A' do
|
11
|
+
include M
|
12
|
+
|
13
|
+
def f
|
14
|
+
object_id
|
15
|
+
end
|
16
|
+
|
17
|
+
would 'f' do
|
18
|
+
f.should.eq m
|
19
|
+
f.should.kind_of? Fixnum
|
20
|
+
lambda{ f.should.eq '' }.should.raise Pork::Failure
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'B' do
|
24
|
+
would 'have the same context' do
|
25
|
+
f.should == m
|
26
|
+
m.should.not.kind_of? String
|
27
|
+
lambda{ throw :halt }.should.throw :halt
|
28
|
+
lambda{ lambda{ throw :halt }.should.not.throw :halt }.
|
29
|
+
should.raise Pork::Failure
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
would 'skip' do
|
34
|
+
skip
|
35
|
+
true.should.eq false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Pork.report
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pork
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lin Jen-Shin (godfat)
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
[Bacon][] reimplemented in an even more lightweight manner.
|
15
|
+
|
16
|
+
[Bacon]: https://github.com/chneukirchen/bacon
|
17
|
+
email:
|
18
|
+
- godfat (XD) godfat.org
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- ".gitmodules"
|
24
|
+
- ".travis.yml"
|
25
|
+
- LICENSE
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- lib/pork.rb
|
29
|
+
- lib/pork/task.rb
|
30
|
+
- lib/pork/version.rb
|
31
|
+
- pkg/pork-0.1.0.gem
|
32
|
+
- pork.gemspec
|
33
|
+
- task/README.md
|
34
|
+
- task/gemgem.rb
|
35
|
+
- test/test_bacon.rb
|
36
|
+
- test/test_nested.rb
|
37
|
+
homepage: https://github.com/godfat/pork
|
38
|
+
licenses:
|
39
|
+
- Apache License 2.0
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.3.0
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: "[Bacon][] reimplemented in an even more lightweight manner."
|
61
|
+
test_files:
|
62
|
+
- test/test_bacon.rb
|
63
|
+
- test/test_nested.rb
|