lib/shared_should.rb in shared_should-0.8.0 vs lib/shared_should.rb in shared_should-0.8.1
- old
+ new
@@ -12,11 +12,11 @@
def self.suite
# assuming 'suite' is called before executing any tests - may be a poor assumption. Find something better?
unless @@shared_proxies_executed[self]
shared_proxies.each do |shared_proxy|
- shared_proxy.execute
+ shared_proxy.share_execute
end
@@shared_proxies_executed[self] = true
end
suite_without_shared_should_execute
@@ -43,10 +43,11 @@
def setup_shared_value(initialization_block)
self.shared_value = initialization_block.nil? ? nil : initialization_block.bind(self).call
end
def call_block_with_shared_value(test_block)
+ return nil unless test_block
execute_class_shared_setups_if_not_executed
if test_block.arity == 1
# check arity of 1 before checking if value is an array. If one parameter, never treat the shared_value as variable args
test_block.bind(self).call(self.shared_value)
elsif self.shared_value.class == Array && test_block.arity == self.shared_value.length
@@ -54,12 +55,13 @@
else
test_block.bind(self).call()
end
end
- def call_block_shared_value(test_block)
- self.shared_value = call_block_with_shared_value(test_block)
+ def call_block_config(block_config)
+ ret_val = call_block_with_shared_value(block_config[:block])
+ self.shared_value = ret_val if block_config[:action] == :given
end
end
module Shoulda::SharedContext
# class methods for Test::Unit::TestCase
@@ -105,22 +107,22 @@
end
def use_setup(shared_name)
return add_shared_proxy.use_setup(shared_name)
end
-
+
def setup(name = nil, &block)
return add_shared_proxy.setup(name, &block)
end
def context(name = nil, &block)
if block
shared_proxies_executing_block = Proc.new do
block.bind(self).call
shared_proxies.each do |shared_proxy|
- shared_proxy.execute
+ shared_proxy.share_execute
end
end
shared_proxies_executing_block.bind(eval("self", block.binding))
context_without_shared_proxies_executing(name, &shared_proxies_executing_block)
end
@@ -261,10 +263,25 @@
def use_setup(share_name)
add_setup_block(:use_setup, share_name, &source_context.find_shared_block(:setup, share_name))
end
+ # deprecated
+ def with_setup(share_name)
+ return use_setup(share_name)
+ end
+
+ # deprecated
+ def with(share_name = nil, &initialization_block)
+ return setup(share_name ? "with #{share_name}" : nil, &initialization_block)
+ end
+
+ # deprecated
+ def when(share_name = nil, &initialization_block)
+ return setup(share_name ? "when #{share_name}" : nil, &initialization_block)
+ end
+
def given(description = nil, &initialization_block)
valid_share_types = [:use_setup, :use_should, :use_context]
@failed = true and raise ArgumentError, "'given' can only appear after #{valid_share_types.join(', ')}" unless valid_share_types.include?(current_action)
add_setup_block(:given, description ? "given #{description}" : nil, &initialization_block)
@@ -294,20 +311,20 @@
def use_context(share_name)
add_test_block(:use_context, share_name, &source_context.find_shared_block(:context, share_name))
end
- def execute
+ def share_execute
return if @failed
shared_proxy = self
if test_type == :should || test_type == :context || test_type == :use_should || test_type == :use_context
# create a new context for setups and should/context
source_context.context setup_block_configs_description do
setup_without_param_support do
shared_proxy.setup_block_configs.each do |config|
- call_block_shared_value(config[:block])
+ call_block_config(config)
end
end
# share_description called when creating test names
eval("def share_description; #{shared_proxy.send(:escaped_test_description)}; end")
@@ -315,11 +332,11 @@
end
else
# call setups directly in this context
source_context.setup_without_param_support do
shared_proxy.setup_block_configs.each do |config|
- call_block_shared_value(config[:block])
+ call_block_config(config)
end
end
end
end
@@ -343,10 +360,10 @@
return self
end
def add_setup_block(action, description, &block)
if test_type
- @failed = true and raise ArgumentError, "'#{action}' may not be applied" unless action == :given
+ #@failed = true and raise ArgumentError, "'#{action}' may not be applied" unless action == :given
# add final given description to test description
self.test_description = "#{test_description} #{description}" if description
description = nil
end