Module: Shoulda::SharedContext::SharedContextMethods
- Defined in:
- lib/shared_should.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
143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/shared_should.rb', line 143 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
204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/shared_should.rb', line 204 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
139 140 141 |
# File 'lib/shared_should.rb', line 139 def setup(name = nil, &block) return add_shared_proxy.setup(name, &block) end |
#share_context(shared_context_name, &shared_context_block) ⇒ Object
167 168 169 170 171 172 173 174 175 |
# File 'lib/shared_should.rb', line 167 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
187 188 189 190 |
# File 'lib/shared_should.rb', line 187 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
177 178 179 180 181 182 183 184 185 |
# File 'lib/shared_should.rb', line 177 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
192 193 194 |
# File 'lib/shared_should.rb', line 192 def shared_context_blocks @shared_context_blocks ||= {} end |
#shared_proxies ⇒ Object
123 124 125 |
# File 'lib/shared_should.rb', line 123 def shared_proxies @shared_proxies ||= [] end |
#shared_setup_blocks ⇒ Object
200 201 202 |
# File 'lib/shared_should.rb', line 200 def shared_setup_blocks @shared_setup_blocks ||= {} end |
#shared_should_blocks ⇒ Object
196 197 198 |
# File 'lib/shared_should.rb', line 196 def shared_should_blocks @shared_should_blocks ||= {} end |
#should(name = nil, options = {}, &block) ⇒ Object
157 158 159 160 161 162 163 164 165 |
# File 'lib/shared_should.rb', line 157 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
131 132 133 |
# File 'lib/shared_should.rb', line 131 def use_context(shared_name) return add_shared_proxy.use_context(shared_name) end |
#use_setup(shared_name) ⇒ Object
135 136 137 |
# File 'lib/shared_should.rb', line 135 def use_setup(shared_name) return add_shared_proxy.use_setup(shared_name) end |
#use_should(shared_name) ⇒ Object
127 128 129 |
# File 'lib/shared_should.rb', line 127 def use_should(shared_name) return add_shared_proxy.use_should(shared_name) end |