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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2a209cd49ba2dcf6462a297a09c967f59c1edff
4
- data.tar.gz: c76e48db62fee768e7307da6b14250fa10f706a4
3
+ metadata.gz: 11710019095024e6b7c71230fe7be0f81c9b9588
4
+ data.tar.gz: 2a7bef2e89bb2b583d90542d9884d78a3e01ec94
5
5
  SHA512:
6
- metadata.gz: 434656cd75baf8224f27ff707b9022d71b5d1ca5d5e16a244b9c86b6804e90a92c0ab9a23a9c9a43a4675ea40ee2451a30d27fb9c683496019d07a77fe09b571
7
- data.tar.gz: 7be65f54d0f46526c3835b5abe5efe355bd55557cc1524350148333d0039cbbd2ad0b2c0f9354d213cc0cf3a48240345f8b523a15532228a8984ae596c13c9c1
6
+ metadata.gz: 6f4411008a3917843a7c522988841600e0d590e28e5b924bac1387f9f214e104e557d12c8bfa2a99bce99e9fe2461fb1df54d9b237cc9b766b0d142e7a66f233
7
+ data.tar.gz: 15c34e4091e5b6b2f9ce1ac64739a940beb109df843c56cc80aad3fa3abba2f5872e33584cc25638a7b82481e6a80d46500b6ba2bda2f44135612f0a1056eda1
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  [![Build Status](https://travis-ci.org/sleewoo/tiramisu.svg)](https://travis-ci.org/sleewoo/tiramisu)
2
2
 
3
- ## Tiramisu - a super-simple testing library for Ruby
3
+ ## Tiramisu - super-simple testing library for Ruby
4
4
 
5
- Its base API consist of just 10(yes, ten!) memorable methods:
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
@@ -106,10 +106,6 @@ module Tiramisu
106
106
  def fail reason, caller
107
107
  throw(:__tiramisu_status__, GenericFailure.new(Array(reason), caller))
108
108
  end
109
-
110
- def void_hooks
111
- {before: {}, around: {}, after: {}}
112
- end
113
109
  end
114
110
 
115
111
  require 'tiramisu/core_ext'
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) {__send__(test)}
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 any or specific tests
96
+ # run some code before/around/after tests
93
97
  #
94
- # @example call :define_users before any test (in current spec)
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 run only after :photos test
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 :authorize, :authenticate do |&test|
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 if multiple hooks defined for same test only the last one will run
134
- # @note named hooks will have precedence over wildcard ones
122
+ # @note hooks are inherited from parent spec or context
135
123
  #
136
- # @example named hooks have precedence over wildcard ones
137
- # before :math do
138
- # # named hook, to run only before :math test
139
- # end
124
+ # @example
125
+ # spec Math do
126
+ # before { @n = rand }
140
127
  #
141
- # before do
142
- # # wildcard hook, to run before any test
128
+ # context :PI do
129
+ # test :some_test do
130
+ # # @n available here
131
+ # end
132
+ # end
143
133
  # end
144
134
  #
145
- # test :math do
146
- # # only `bofore :math` hook will run here
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 |*tests,&block|
154
+ define_method hook do |&block|
155
155
  block || raise(ArgumentError, 'block missing')
156
- meth = :"__tiramisu_hooks_#{hook}_#{block.source_location.join}__"
157
- tests = [:__tiramisu_hooks_any__] if tests.empty?
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__ ||= Tiramisu.void_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__ tests[test],
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
- it 'calls wildcard hooks' do
2
+
3
+ it 'calls before and after hooks' do
3
4
  called = 0
4
5
  spec rand do
5
6
  before {called += 1}
6
- test(:a) {}
7
- test(:b) {}
8
- run(:a)
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 named hooks' do
15
- called = 0
14
+ it 'calls around hooks' do
15
+ called = false
16
16
  spec rand do
17
- after(:b) {called += 1}
18
- test(:a) {}
19
- test(:b) {}
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 1, called
21
+ assert_equal true, called
24
22
  end
25
23
 
26
- it 'prefers named hooks over wildcard ones' do
27
- called = nil
24
+ it 'inherits hooks' do
25
+ spec_hooks, context_hooks = nil
28
26
  spec rand do
29
- around(:a) {called = :named}
30
- around {called = :wildcard}
31
- test(:a) {}
32
- run(:a)
27
+ before {}
28
+ context rand do
29
+ context_hooks = hooks
30
+ end
31
+ spec_hooks = hooks
33
32
  end
34
- assert_equal :named, called
33
+ assert_equal context_hooks, spec_hooks
35
34
  end
36
35
  end
data/tiramisu.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'tiramisu'
3
- spec.version = '0.0.3'
3
+ spec.version = '0.0.4'
4
4
  spec.authors = ['Slee Woo']
5
5
  spec.email = ['mail@sleewoo.com']
6
6
  spec.description = 'Super-simple testing library for Ruby'
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.3
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-27 00:00:00.000000000 Z
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.3
194
+ summary: tiramisu-0.0.4
195
195
  test_files: []