shared_should 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -103,7 +103,7 @@ Sharing whole contexts? Schmeasy!
103
103
  use_context "for a book available for checkout"
104
104
  end
105
105
 
106
- ### ...or DRY it up by using .when and an initialization block
106
+ ### ...or DRY it up with chaining
107
107
  setup("with a rentable book") { @book.rentable = true }.use_context("for a book available for checkout")
108
108
  setup("with a purchasable book") { @book.purchasable = true }.use_context("for a book available for checkout")
109
109
  end
@@ -123,7 +123,7 @@ Some rules:
123
123
 
124
124
  Shared Should provides powerful chaining capabilities.
125
125
 
126
- Chained <tt>setup</tt>s and <tt>use\_setup</tt>s are applied to their parent context:
126
+ Chained setups and use\_setups are applied to their parent context.
127
127
 
128
128
  context "Book" do
129
129
  share_setup "for an in-stock book" do
@@ -137,7 +137,7 @@ Chained <tt>setup</tt>s and <tt>use\_setup</tt>s are applied to their parent con
137
137
  end
138
138
  end
139
139
 
140
- Or chained <tt>setup</tt>s and <tt>use\_setup</tt>s can be chained to a <tt>should</tt>, <tt>use\_should</tt>, <tt>context</tt>, or <tt>use\_context</tt>:
140
+ Or chained setups and use\_setups can be chained to a <tt>should</tt>, <tt>use\_should</tt>, <tt>context</tt>, or <tt>use\_context</tt>. These setups will not be applied to the parent context.
141
141
 
142
142
  context "Book" do
143
143
  share_setup "for an in-stock book" do
@@ -151,7 +151,7 @@ Or chained <tt>setup</tt>s and <tt>use\_setup</tt>s can be chained to a <tt>shou
151
151
 
152
152
  ### Parameterizing Shares
153
153
 
154
- Shared functions can also be parameterized using block parameters. This can be done for shared setups, shared shoulds, and the <tt>setup</tt>s and <tt>should</tt>s contained within a shared context. The value passed to the shared function is the return value of the <tt>given</tt> parameterization block. The below example parameterizes a shared setup.
154
+ Shared functions can also be parameterized using block parameters. This can be done for shared setups, shared shoulds, and the setups and shoulds contained within a shared context. The value passed to the shared function is the return value of the <tt>given</tt> parameterization block. The below example parameterizes a shared setup.
155
155
 
156
156
  context "Book" do
157
157
  share_setup "for an in-stock book" do |rentable|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.8.1
data/lib/shared_should.rb CHANGED
@@ -14,7 +14,7 @@ class Test::Unit::TestCase
14
14
  # assuming 'suite' is called before executing any tests - may be a poor assumption. Find something better?
15
15
  unless @@shared_proxies_executed[self]
16
16
  shared_proxies.each do |shared_proxy|
17
- shared_proxy.execute
17
+ shared_proxy.share_execute
18
18
  end
19
19
  @@shared_proxies_executed[self] = true
20
20
  end
@@ -45,6 +45,7 @@ class Test::Unit::TestCase
45
45
  end
46
46
 
47
47
  def call_block_with_shared_value(test_block)
48
+ return nil unless test_block
48
49
  execute_class_shared_setups_if_not_executed
49
50
  if test_block.arity == 1
50
51
  # check arity of 1 before checking if value is an array. If one parameter, never treat the shared_value as variable args
@@ -56,8 +57,9 @@ class Test::Unit::TestCase
56
57
  end
57
58
  end
58
59
 
59
- def call_block_shared_value(test_block)
60
- self.shared_value = call_block_with_shared_value(test_block)
60
+ def call_block_config(block_config)
61
+ ret_val = call_block_with_shared_value(block_config[:block])
62
+ self.shared_value = ret_val if block_config[:action] == :given
61
63
  end
62
64
  end
63
65
 
@@ -107,7 +109,7 @@ module Shoulda::SharedContext
107
109
  def use_setup(shared_name)
108
110
  return add_shared_proxy.use_setup(shared_name)
109
111
  end
110
-
112
+
111
113
  def setup(name = nil, &block)
112
114
  return add_shared_proxy.setup(name, &block)
113
115
  end
@@ -118,7 +120,7 @@ module Shoulda::SharedContext
118
120
  block.bind(self).call
119
121
 
120
122
  shared_proxies.each do |shared_proxy|
121
- shared_proxy.execute
123
+ shared_proxy.share_execute
122
124
  end
123
125
  end
124
126
  shared_proxies_executing_block.bind(eval("self", block.binding))
@@ -263,6 +265,21 @@ class Shoulda::SharedProxy
263
265
  add_setup_block(:use_setup, share_name, &source_context.find_shared_block(:setup, share_name))
264
266
  end
265
267
 
268
+ # deprecated
269
+ def with_setup(share_name)
270
+ return use_setup(share_name)
271
+ end
272
+
273
+ # deprecated
274
+ def with(share_name = nil, &initialization_block)
275
+ return setup(share_name ? "with #{share_name}" : nil, &initialization_block)
276
+ end
277
+
278
+ # deprecated
279
+ def when(share_name = nil, &initialization_block)
280
+ return setup(share_name ? "when #{share_name}" : nil, &initialization_block)
281
+ end
282
+
266
283
  def given(description = nil, &initialization_block)
267
284
  valid_share_types = [:use_setup, :use_should, :use_context]
268
285
  @failed = true and raise ArgumentError, "'given' can only appear after #{valid_share_types.join(', ')}" unless valid_share_types.include?(current_action)
@@ -296,7 +313,7 @@ class Shoulda::SharedProxy
296
313
  add_test_block(:use_context, share_name, &source_context.find_shared_block(:context, share_name))
297
314
  end
298
315
 
299
- def execute
316
+ def share_execute
300
317
  return if @failed
301
318
 
302
319
  shared_proxy = self
@@ -305,7 +322,7 @@ class Shoulda::SharedProxy
305
322
  source_context.context setup_block_configs_description do
306
323
  setup_without_param_support do
307
324
  shared_proxy.setup_block_configs.each do |config|
308
- call_block_shared_value(config[:block])
325
+ call_block_config(config)
309
326
  end
310
327
  end
311
328
 
@@ -317,7 +334,7 @@ class Shoulda::SharedProxy
317
334
  # call setups directly in this context
318
335
  source_context.setup_without_param_support do
319
336
  shared_proxy.setup_block_configs.each do |config|
320
- call_block_shared_value(config[:block])
337
+ call_block_config(config)
321
338
  end
322
339
  end
323
340
  end
@@ -345,7 +362,7 @@ private
345
362
 
346
363
  def add_setup_block(action, description, &block)
347
364
  if test_type
348
- @failed = true and raise ArgumentError, "'#{action}' may not be applied" unless action == :given
365
+ #@failed = true and raise ArgumentError, "'#{action}' may not be applied" unless action == :given
349
366
  # add final given description to test description
350
367
  self.test_description = "#{test_description} #{description}" if description
351
368
  description = nil
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{shared_should}
8
- s.version = "0.8.0"
8
+ s.version = "0.8.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Pearce"]
12
- s.date = %q{2011-04-05}
12
+ s.date = %q{2011-05-24}
13
13
  s.description = %q{Share and reuse shoulds, contexts, and setup in Shoulda.}
14
14
  s.email = %q{michael.pearce@bookrenter.com}
15
15
  s.extra_rdoc_files = [
@@ -221,6 +221,30 @@ class TestSharedShould < Test::Unit::TestCase
221
221
  end
222
222
  end
223
223
 
224
+ context "deprecated features" do
225
+ share_should "be true value" do
226
+ assert @value
227
+ end
228
+
229
+ context "with_setup" do
230
+ share_setup "for a true value" do
231
+ @value = true
232
+ end
233
+
234
+ use_should("be true value").use_setup("for a true value")
235
+ end
236
+
237
+ context "with" do
238
+ use_should("be true value").with { @value = true }
239
+ use_should("be true value").with("a true value") { @value = true }
240
+ end
241
+
242
+ context "when" do
243
+ use_should("be true value").when { @value = true }
244
+ use_should("be true value").when("a true value") { @value = true }
245
+ end
246
+ end
247
+
224
248
  context "context directly under test class" do
225
249
  share_setup "for a true value" do
226
250
  @value = true
@@ -306,32 +330,32 @@ class TestSharedShould < Test::Unit::TestCase
306
330
  end
307
331
  end
308
332
 
309
- context "with invalid setup chain to should" do
310
- begin
311
- setup {}.should("1") { assert false }.setup { assert false }
312
- raise "Should not allow setup chained after should"
313
- rescue ArgumentError
314
- # correct
315
- end
316
- end
317
-
318
- context "with invalid chain to should" do
319
- begin
320
- setup {}.should("1") { assert false }.should("2") { assert false }
321
- raise "Should not allow chained shoulds"
322
- rescue ArgumentError
323
- # correct
324
- end
325
- end
326
-
327
- context "with invalid chained contexts" do
328
- begin
329
- setup {}.context("1") { should("1") { assert false } }.should("2") { assert false }
330
- raise "Should not allow chain to context"
331
- rescue ArgumentError
332
- # correct
333
- end
334
- end
333
+ # context "with invalid setup chain to should" do
334
+ # begin
335
+ # setup {}.should("1") { assert false }.setup { assert false }
336
+ # raise "Should not allow setup chained after should"
337
+ # rescue ArgumentError
338
+ # # correct
339
+ # end
340
+ # end
341
+ #
342
+ # context "with invalid chain to should" do
343
+ # begin
344
+ # setup {}.should("1") { assert false }.should("2") { assert false }
345
+ # raise "Should not allow chained shoulds"
346
+ # rescue ArgumentError
347
+ # # correct
348
+ # end
349
+ # end
350
+ #
351
+ # context "with invalid chained contexts" do
352
+ # begin
353
+ # setup {}.context("1") { should("1") { assert false } }.should("2") { assert false }
354
+ # raise "Should not allow chain to context"
355
+ # rescue ArgumentError
356
+ # # correct
357
+ # end
358
+ # end
335
359
 
336
360
  context "with should" do
337
361
  setup("for true value") { @value = true }.should("be true value") do
@@ -456,7 +480,12 @@ class TestSharedShould < Test::Unit::TestCase
456
480
  "test: .share_setup without params without initialization block should have a true value from shared setup. ",
457
481
  "test: SharedShould should execute setup instance method. ",
458
482
  "test: with unusual characters in name -- \\ ' \" -- should be valid. ",
459
- "test: with unusual characters in name should -- \\ ' \" --. "
483
+ "test: with unusual characters in name should -- \\ ' \" --. ",
484
+ "test: deprecated features with_setup should be true value for a true value. ",
485
+ "test: deprecated features when should be true value. ",
486
+ "test: deprecated features with should be true value. ",
487
+ "test: deprecated features with should be true value with a true value. ",
488
+ "test: deprecated features when should be true value when a true value. "
460
489
  ].inject({}) do |hash, expected_method_name|
461
490
  hash[expected_method_name] = true
462
491
  hash
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shared_should
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 0
10
- version: 0.8.0
9
+ - 1
10
+ version: 0.8.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Pearce
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-05 00:00:00 -07:00
18
+ date: 2011-05-24 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency