lib/shared_should.rb in shared_should-0.6.2 vs lib/shared_should.rb in shared_should-0.6.3
- old
+ new
@@ -16,41 +16,43 @@
end
class Test::Unit::TestCase
attr_accessor :shared_value
attr_accessor :shared_name
- @@shared_proxies_executed = false
- @@setup_blocks = []
+ @@shared_proxies_executed = {}
+ @@setup_blocks = {}
class << self
# these methods need to be aliased for both the test class and the should context
alias_method :suite_without_shared_should_execute, :suite
end
def self.suite
- unless @@shared_proxies_executed
+ # 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(self)
end
- @@shared_proxies_executed = true
+ @@shared_proxies_executed[self] = true
end
suite_without_shared_should_execute
end
def self.shared_context_block_owner(context_or_test_class)
return context_or_test_class.kind_of?(Shoulda::Context) ? context_or_test_class : Test::Unit::TestCase
end
def setup
- @@setup_blocks.each do |setup_block|
+ (@@setup_blocks[self.class] || []).each do |setup_block|
setup_block.bind(self).call
end
end
def self.setup(&setup_block)
- @@setup_blocks << setup_block
+ @@setup_blocks[self] = [] unless @@setup_blocks[self]
+ @@setup_blocks[self] << setup_block
end
def setup_shared_values(name, initialization_block)
self.shared_value = initialization_block.nil? ? nil : initialization_block.bind(self).call
self.shared_name = name
@@ -315,18 +317,20 @@
def initialize(shared_name)
self.shared_name = shared_name
self.initialization_blocks = []
end
+ def with(description = nil, &initialization_block)
+ with_helper("with", description, &initialization_block)
+ end
+
def when(description = nil, &initialization_block)
- when_helper("when", description, &initialization_block)
- return self
+ with_helper("when", description, &initialization_block)
end
- def with(description = nil, &initialization_block)
- when_helper("with", description, &initialization_block)
- return nil
+ def given(description = nil, &initialization_block)
+ with_helper("given", description, :disable_and => true, &initialization_block)
end
def execute(context)
method_name = context.send(:shared_method_name, :should, shared_name)
context.send(method_name, description, &initialization_block)
@@ -339,12 +343,14 @@
end
end
private
- def when_helper(conditional, description = nil, &initialization_block)
+ def with_helper(conditional, description, options = {}, &initialization_block)
if description
- self.description = "#{self.description}#{self.description.nil? ? nil : ' and '}#{conditional} #{description}"
+ and_text = options[:disable_and] ? ' ' : ' and '
+ self.description = "#{self.description}#{self.description.nil? ? nil : and_text}#{conditional} #{description}"
end
self.initialization_blocks << initialization_block
+ return self
end
end