Class: Test::Unit::TestCase
- Inherits:
-
Object
- Object
- Test::Unit::TestCase
- Extended by:
- Shoulda::SharedContext
- Defined in:
- lib/shared_should.rb,
lib/shared_should.rb,
lib/shared_should.rb
Constant Summary collapse
{}
- @@setup_blocks =
{}
Instance Attribute Summary collapse
-
#shared_value ⇒ Object
Returns the value of attribute shared_value.
Class Method Summary collapse
- .execute_class_shared_proxies ⇒ Object
- .setup(&setup_block) ⇒ Object
- .shared_context_block_owner(context_or_test_class) ⇒ Object
- .suite ⇒ Object
-
.suite_without_shared_should_execute ⇒ Object
these methods need to be aliased for both the test class and the should context.
Instance Method Summary collapse
- #call_block_config(block_config) ⇒ Object
- #call_block_with_shared_value(test_block) ⇒ Object
- #execute_class_shared_setups_if_not_executed ⇒ Object
- #setup_shared_value(initialization_block) ⇒ Object
Instance Attribute Details
#shared_value ⇒ Object
Returns the value of attribute shared_value.
38 39 40 |
# File 'lib/shared_should.rb', line 38 def shared_value @shared_value end |
Class Method Details
.execute_class_shared_proxies ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/shared_should.rb', line 42 def self.execute_class_shared_proxies unless @@shared_proxies_executed[self] shared_proxies.each do |shared_proxy| shared_proxy.share_execute end @@shared_proxies_executed[self] = true end end |
.setup(&setup_block) ⇒ Object
64 65 66 67 |
# File 'lib/shared_should.rb', line 64 def self.setup(&setup_block) @@setup_blocks[self] = [] unless @@setup_blocks[self] @@setup_blocks[self] << setup_block end |
.shared_context_block_owner(context_or_test_class) ⇒ Object
51 52 53 |
# File 'lib/shared_should.rb', line 51 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 |
.suite ⇒ Object
27 28 29 30 31 32 |
# File 'lib/shared_should.rb', line 27 def self.suite # assuming 'suite' is called before executing any tests - may be a poor assumption. Find something better? execute_class_shared_proxies suite_without_shared_should_execute end |
.suite_without_shared_should_execute ⇒ Object
these methods need to be aliased for both the test class and the should context
24 |
# File 'lib/shared_should.rb', line 24 alias_method :suite_without_shared_should_execute, :suite |
Instance Method Details
#call_block_config(block_config) ⇒ Object
86 87 88 89 |
# File 'lib/shared_should.rb', line 86 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 |
#call_block_with_shared_value(test_block) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/shared_should.rb', line 73 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 test_block.bind(self).call(*self.shared_value) else test_block.bind(self).call() end end |
#execute_class_shared_setups_if_not_executed ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/shared_should.rb', line 55 def execute_class_shared_setups_if_not_executed if !@shared_setups_executed @shared_setups_executed = true (@@setup_blocks[self.class] || []).each do |setup_block| setup_block.bind(self).call end end end |
#setup_shared_value(initialization_block) ⇒ Object
69 70 71 |
# File 'lib/shared_should.rb', line 69 def setup_shared_value(initialization_block) self.shared_value = initialization_block.nil? ? nil : initialization_block.bind(self).call end |