tiramisu 0.0.3 → 0.0.4
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 +4 -4
- data/README.md +2 -2
- data/lib/tiramisu.rb +0 -4
- data/lib/tiramisu/run.rb +1 -1
- data/lib/tiramisu/unit.rb +35 -40
- data/test/context_inheritance_test.rb +0 -13
- data/test/hooks_test.rb +19 -20
- data/tiramisu.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11710019095024e6b7c71230fe7be0f81c9b9588
|
4
|
+
data.tar.gz: 2a7bef2e89bb2b583d90542d9884d78a3e01ec94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f4411008a3917843a7c522988841600e0d590e28e5b924bac1387f9f214e104e557d12c8bfa2a99bce99e9fe2461fb1df54d9b237cc9b766b0d142e7a66f233
|
7
|
+
data.tar.gz: 15c34e4091e5b6b2f9ce1ac64739a940beb109df843c56cc80aad3fa3abba2f5872e33584cc25638a7b82481e6a80d46500b6ba2bda2f44135612f0a1056eda1
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
[](https://travis-ci.org/sleewoo/tiramisu)
|
2
2
|
|
3
|
-
## Tiramisu -
|
3
|
+
## Tiramisu - super-simple testing library for Ruby
|
4
4
|
|
5
|
-
Its base API consist of just 10
|
5
|
+
Its base API consist of just 10 memorable methods:
|
6
6
|
|
7
7
|
- spec, context
|
8
8
|
- before, around, after
|
data/lib/tiramisu.rb
CHANGED
data/lib/tiramisu/run.rb
CHANGED
@@ -64,7 +64,7 @@ module Tiramisu
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def render_exception indent, failure
|
67
|
-
progress.log indent + underline.bright_red(failure.message)
|
67
|
+
progress.log indent + underline.bright_red([failure.class, failure.message]*': ')
|
68
68
|
pretty_backtrace(failure).each {|l| progress.log(indent + l)}
|
69
69
|
end
|
70
70
|
|
data/lib/tiramisu/unit.rb
CHANGED
@@ -34,7 +34,7 @@ module Tiramisu
|
|
34
34
|
def __run__ test, before, around, after
|
35
35
|
__send__(before) if before
|
36
36
|
if around
|
37
|
-
__send__(around
|
37
|
+
__send__(around, proc {__send__(test)})
|
38
38
|
else
|
39
39
|
__send__(test)
|
40
40
|
end
|
@@ -58,6 +58,10 @@ module Tiramisu
|
|
58
58
|
|
59
59
|
class << Unit
|
60
60
|
|
61
|
+
def inherited base
|
62
|
+
base.instance_variable_set(:@__tiramisu_hooks__, Marshal.load(Marshal.dump(hooks)))
|
63
|
+
end
|
64
|
+
|
61
65
|
def spec
|
62
66
|
raise(NotImplementedError, 'Nested specs not supported. Please use a context instead')
|
63
67
|
end
|
@@ -89,9 +93,9 @@ module Tiramisu
|
|
89
93
|
@__tiramisu_tests__ ||= {}
|
90
94
|
end
|
91
95
|
|
92
|
-
# run some code before/around/after
|
96
|
+
# run some code before/around/after tests
|
93
97
|
#
|
94
|
-
# @example
|
98
|
+
# @example
|
95
99
|
# spec User do
|
96
100
|
# before do
|
97
101
|
# @users = ...
|
@@ -102,20 +106,9 @@ module Tiramisu
|
|
102
106
|
# end
|
103
107
|
# end
|
104
108
|
#
|
105
|
-
# @example
|
106
|
-
# spec User do
|
107
|
-
# after :photos do
|
108
|
-
# ...
|
109
|
-
# end
|
110
|
-
#
|
111
|
-
# test :photos do
|
112
|
-
# ...
|
113
|
-
# end
|
114
|
-
# end
|
115
|
-
#
|
116
|
-
# @example run around :authorize and :authenticate tests
|
109
|
+
# @example
|
117
110
|
# spec User do
|
118
|
-
# around
|
111
|
+
# around |&test|
|
119
112
|
# SomeApi.with_auth do
|
120
113
|
# test.call # run the test
|
121
114
|
# end
|
@@ -124,26 +117,33 @@ module Tiramisu
|
|
124
117
|
# test :authorize do
|
125
118
|
# # will run inside `with_auth` block
|
126
119
|
# end
|
127
|
-
#
|
128
|
-
# test :authenticate do
|
129
|
-
# # same
|
130
|
-
# end
|
131
120
|
# end
|
132
121
|
#
|
133
|
-
# @note
|
134
|
-
# @note named hooks will have precedence over wildcard ones
|
122
|
+
# @note hooks are inherited from parent spec or context
|
135
123
|
#
|
136
|
-
# @example
|
137
|
-
#
|
138
|
-
#
|
139
|
-
# end
|
124
|
+
# @example
|
125
|
+
# spec Math do
|
126
|
+
# before { @n = rand }
|
140
127
|
#
|
141
|
-
#
|
142
|
-
#
|
128
|
+
# context :PI do
|
129
|
+
# test :some_test do
|
130
|
+
# # @n available here
|
131
|
+
# end
|
132
|
+
# end
|
143
133
|
# end
|
144
134
|
#
|
145
|
-
#
|
146
|
-
#
|
135
|
+
# @note defined hooks will override inherited ones
|
136
|
+
#
|
137
|
+
# @example
|
138
|
+
# spec Math do
|
139
|
+
# before { @n = 1 }
|
140
|
+
#
|
141
|
+
# context :x do
|
142
|
+
# before { @n = 0 }
|
143
|
+
# test :some_test do
|
144
|
+
# # @n is zero here
|
145
|
+
# end
|
146
|
+
# end
|
147
147
|
# end
|
148
148
|
#
|
149
149
|
[
|
@@ -151,17 +151,15 @@ module Tiramisu
|
|
151
151
|
:around,
|
152
152
|
:after
|
153
153
|
].each do |hook|
|
154
|
-
define_method hook do
|
154
|
+
define_method hook do |&block|
|
155
155
|
block || raise(ArgumentError, 'block missing')
|
156
|
-
|
157
|
-
|
158
|
-
tests.each {|t| (hooks[hook] ||= {})[t] = meth}
|
159
|
-
define_method(meth, &block)
|
156
|
+
hooks[hook] = :"__tiramisu__#{hook}_hook__"
|
157
|
+
define_method(hooks[hook], &block)
|
160
158
|
end
|
161
159
|
end
|
162
160
|
|
163
161
|
def hooks
|
164
|
-
@__tiramisu_hooks__ ||=
|
162
|
+
@__tiramisu_hooks__ ||= {}
|
165
163
|
end
|
166
164
|
|
167
165
|
# skipping a whole spec/context
|
@@ -180,10 +178,7 @@ module Tiramisu
|
|
180
178
|
def run test
|
181
179
|
tests[test] || raise(StandardError, 'Undefined test %s at "%s"' % [test.inspect, __identity__])
|
182
180
|
catch :__tiramisu_status__ do
|
183
|
-
allocate.__run__
|
184
|
-
hooks[:before][test] || hooks[:before][:__tiramisu_hooks_any__],
|
185
|
-
hooks[:around][test] || hooks[:around][:__tiramisu_hooks_any__],
|
186
|
-
hooks[:after][test] || hooks[:after][:__tiramisu_hooks_any__]
|
181
|
+
allocate.__run__(tests[test], hooks[:before], hooks[:around], hooks[:after])
|
187
182
|
end
|
188
183
|
end
|
189
184
|
end
|
@@ -49,17 +49,4 @@ describe :context_inheritance_test do
|
|
49
49
|
assert_equal 1, spec_tests
|
50
50
|
assert_equal 0, context_tests
|
51
51
|
end
|
52
|
-
|
53
|
-
it 'does not inherit hooks' do
|
54
|
-
spec_hooks, context_hooks = nil
|
55
|
-
spec rand do
|
56
|
-
before {}
|
57
|
-
context rand do
|
58
|
-
context_hooks = hooks[:before].size
|
59
|
-
end
|
60
|
-
spec_hooks = hooks[:before].size
|
61
|
-
end
|
62
|
-
assert_equal 1, spec_hooks
|
63
|
-
assert_equal 0, context_hooks
|
64
|
-
end
|
65
52
|
end
|
data/test/hooks_test.rb
CHANGED
@@ -1,36 +1,35 @@
|
|
1
1
|
describe :hooks do
|
2
|
-
|
2
|
+
|
3
|
+
it 'calls before and after hooks' do
|
3
4
|
called = 0
|
4
5
|
spec rand do
|
5
6
|
before {called += 1}
|
6
|
-
|
7
|
-
test(:
|
8
|
-
run(:
|
9
|
-
run(:b)
|
7
|
+
after {called += 1}
|
8
|
+
test(:x) {}
|
9
|
+
run(:x)
|
10
10
|
end
|
11
11
|
assert_equal 2, called
|
12
12
|
end
|
13
13
|
|
14
|
-
it 'calls
|
15
|
-
called =
|
14
|
+
it 'calls around hooks' do
|
15
|
+
called = false
|
16
16
|
spec rand do
|
17
|
-
|
18
|
-
test(:
|
19
|
-
|
20
|
-
run(:a)
|
21
|
-
run(:b)
|
17
|
+
around {|test| test.call}
|
18
|
+
test(:x) {called = true}
|
19
|
+
run(:x)
|
22
20
|
end
|
23
|
-
assert_equal
|
21
|
+
assert_equal true, called
|
24
22
|
end
|
25
23
|
|
26
|
-
it '
|
27
|
-
|
24
|
+
it 'inherits hooks' do
|
25
|
+
spec_hooks, context_hooks = nil
|
28
26
|
spec rand do
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
before {}
|
28
|
+
context rand do
|
29
|
+
context_hooks = hooks
|
30
|
+
end
|
31
|
+
spec_hooks = hooks
|
33
32
|
end
|
34
|
-
assert_equal
|
33
|
+
assert_equal context_hooks, spec_hooks
|
35
34
|
end
|
36
35
|
end
|
data/tiramisu.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiramisu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Slee Woo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-progressbar
|
@@ -191,5 +191,5 @@ rubyforge_project:
|
|
191
191
|
rubygems_version: 2.4.5
|
192
192
|
signing_key:
|
193
193
|
specification_version: 4
|
194
|
-
summary: tiramisu-0.0.
|
194
|
+
summary: tiramisu-0.0.4
|
195
195
|
test_files: []
|