Module: SharedShould::SharedContext::SharedContextMethods
- Defined in:
- lib/shared_should/shared_context.rb
Instance Method Summary collapse
- #context(name = nil, &block) ⇒ Object
- #find_shared_block(share_type, shared_name) ⇒ Object
- #setup(name = nil, &block) ⇒ Object
- #share_context(shared_context_name, &shared_context_block) ⇒ Object
- #share_setup(shared_name, &setup_block) ⇒ Object
- #share_should(shared_should_name, &shared_should_block) ⇒ Object
- #shared_context_blocks ⇒ Object
- #shared_proxies ⇒ Object
- #shared_setup_blocks ⇒ Object
- #shared_should_blocks ⇒ Object
- #should(name = nil, options = {}, &block) ⇒ Object
- #use_context(shared_name) ⇒ Object
- #use_setup(shared_name) ⇒ Object
- #use_should(shared_name) ⇒ Object
Instance Method Details
#context(name = nil, &block) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/shared_should/shared_context.rb', line 52 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.share_execute end end shared_proxies_executing_block.bind(eval("self", block.binding)) context_without_shared_proxies_executing(name, &shared_proxies_executing_block) end end |
#find_shared_block(share_type, shared_name) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/shared_should/shared_context.rb', line 113 def find_shared_block(share_type, shared_name) current_context = self while current_context.kind_of?(Shoulda::Context) || current_context < Test::Unit::TestCase do if shared_block = Test::Unit::TestCase.shared_context_block_owner(current_context).send("shared_#{share_type}_blocks")[shared_name] return shared_block end raise "Unable to find share_#{share_type}('#{shared_name}')" if current_context.kind_of?(Class) break unless current_context.kind_of?(Shoulda::Context) current_context = current_context.parent end raise "Unable to find share_#{share_type}('#{shared_name}')" end |
#setup(name = nil, &block) ⇒ Object
48 49 50 |
# File 'lib/shared_should/shared_context.rb', line 48 def setup(name = nil, &block) return add_shared_proxy.setup(name, &block) end |
#share_context(shared_context_name, &shared_context_block) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/shared_should/shared_context.rb', line 76 def share_context(shared_context_name, &shared_context_block) wrapping_shared_context_block = Proc.new do context share_description do merge_block(&shared_context_block) end end Test::Unit::TestCase.shared_context_block_owner(shared_context_for_block(shared_context_block)).shared_context_blocks[shared_context_name] = wrapping_shared_context_block end |
#share_setup(shared_name, &setup_block) ⇒ Object
96 97 98 99 |
# File 'lib/shared_should/shared_context.rb', line 96 def share_setup(shared_name, &setup_block) current_context = eval('self', setup_block.binding) Test::Unit::TestCase.shared_context_block_owner(current_context).shared_setup_blocks[shared_name] = setup_block end |
#share_should(shared_should_name, &shared_should_block) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/shared_should/shared_context.rb', line 86 def share_should(shared_should_name, &shared_should_block) shared_context_block = Proc.new do should share_description do call_block_with_shared_value(shared_should_block) end end Test::Unit::TestCase.shared_context_block_owner(shared_context_for_block(shared_should_block)).shared_should_blocks[shared_should_name] = shared_context_block end |
#shared_context_blocks ⇒ Object
101 102 103 |
# File 'lib/shared_should/shared_context.rb', line 101 def shared_context_blocks @shared_context_blocks ||= {} end |
#shared_proxies ⇒ Object
32 33 34 |
# File 'lib/shared_should/shared_context.rb', line 32 def shared_proxies @shared_proxies ||= [] end |
#shared_setup_blocks ⇒ Object
109 110 111 |
# File 'lib/shared_should/shared_context.rb', line 109 def shared_setup_blocks @shared_setup_blocks ||= {} end |
#shared_should_blocks ⇒ Object
105 106 107 |
# File 'lib/shared_should/shared_context.rb', line 105 def shared_should_blocks @shared_should_blocks ||= {} end |
#should(name = nil, options = {}, &block) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/shared_should/shared_context.rb', line 66 def should(name = nil, = {}, &block) if block.nil? should_without_param_support(name, ) else should_without_param_support(name, ) do call_block_with_shared_value(block) end end end |
#use_context(shared_name) ⇒ Object
40 41 42 |
# File 'lib/shared_should/shared_context.rb', line 40 def use_context(shared_name) return add_shared_proxy.use_context(shared_name) end |
#use_setup(shared_name) ⇒ Object
44 45 46 |
# File 'lib/shared_should/shared_context.rb', line 44 def use_setup(shared_name) return add_shared_proxy.use_setup(shared_name) end |
#use_should(shared_name) ⇒ Object
36 37 38 |
# File 'lib/shared_should/shared_context.rb', line 36 def use_should(shared_name) return add_shared_proxy.use_should(shared_name) end |