Class: Shoulda::SharedProxy
- Inherits:
-
Object
- Object
- Shoulda::SharedProxy
- Defined in:
- lib/shared_should.rb
Instance Attribute Summary collapse
-
#current_action ⇒ Object
Returns the value of attribute current_action.
-
#setup_block_configs ⇒ Object
Returns the value of attribute setup_block_configs.
-
#source_context ⇒ Object
Returns the value of attribute source_context.
-
#test_block ⇒ Object
Returns the value of attribute test_block.
-
#test_description ⇒ Object
Returns the value of attribute test_description.
-
#test_type ⇒ Object
Returns the value of attribute test_type.
Instance Method Summary collapse
- #context(description = nil, &context_block) ⇒ Object
- #given(description = nil, &initialization_block) ⇒ Object
-
#initialize(source_context) ⇒ SharedProxy
constructor
A new instance of SharedProxy.
- #setup(description = nil, &initialization_block) ⇒ Object
- #share_execute ⇒ Object
- #should(description = nil, options = {}, &should_block) ⇒ Object
- #use_context(share_name) ⇒ Object
- #use_setup(share_name) ⇒ Object
- #use_should(share_name) ⇒ Object
-
#when(share_name = nil, &initialization_block) ⇒ Object
deprecated.
-
#with(share_name = nil, &initialization_block) ⇒ Object
deprecated.
-
#with_setup(share_name) ⇒ Object
deprecated.
Constructor Details
#initialize(source_context) ⇒ SharedProxy
Returns a new instance of SharedProxy.
281 282 283 284 |
# File 'lib/shared_should.rb', line 281 def initialize(source_context) self.setup_block_configs = [] self.source_context = source_context end |
Instance Attribute Details
#current_action ⇒ Object
Returns the value of attribute current_action.
279 280 281 |
# File 'lib/shared_should.rb', line 279 def current_action @current_action end |
#setup_block_configs ⇒ Object
Returns the value of attribute setup_block_configs.
279 280 281 |
# File 'lib/shared_should.rb', line 279 def setup_block_configs @setup_block_configs end |
#source_context ⇒ Object
Returns the value of attribute source_context.
279 280 281 |
# File 'lib/shared_should.rb', line 279 def source_context @source_context end |
#test_block ⇒ Object
Returns the value of attribute test_block.
279 280 281 |
# File 'lib/shared_should.rb', line 279 def test_block @test_block end |
#test_description ⇒ Object
Returns the value of attribute test_description.
279 280 281 |
# File 'lib/shared_should.rb', line 279 def test_description @test_description end |
#test_type ⇒ Object
Returns the value of attribute test_type.
279 280 281 |
# File 'lib/shared_should.rb', line 279 def test_type @test_type end |
Instance Method Details
#context(description = nil, &context_block) ⇒ Object
329 330 331 332 333 334 335 336 |
# File 'lib/shared_should.rb', line 329 def context(description = nil, &context_block) shared_context_block = Proc.new do context share_description do merge_block(&context_block) end end add_test_block(:context, description, &shared_context_block) end |
#given(description = nil, &initialization_block) ⇒ Object
309 310 311 312 313 314 |
# File 'lib/shared_should.rb', line 309 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) end |
#setup(description = nil, &initialization_block) ⇒ Object
286 287 288 |
# File 'lib/shared_should.rb', line 286 def setup(description = nil, &initialization_block) add_setup_block(:setup, description, &initialization_block) end |
#share_execute ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/shared_should.rb', line 342 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_config(config) end end # share_description called when creating test names self.instance_variable_set("@share_description", shared_proxy.send(:test_description)) def self.share_description; @share_description; end merge_block(&shared_proxy.test_block) 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_config(config) end end end end |
#should(description = nil, options = {}, &should_block) ⇒ Object
316 317 318 319 320 321 322 323 |
# File 'lib/shared_should.rb', line 316 def should(description = nil, = {}, &should_block) shared_context_block = Proc.new do should share_description do call_block_with_shared_value(should_block) end end add_test_block(:should, description, &shared_context_block) end |
#use_context(share_name) ⇒ Object
338 339 340 |
# File 'lib/shared_should.rb', line 338 def use_context(share_name) add_test_block(:use_context, share_name, &source_context.find_shared_block(:context, share_name)) end |
#use_setup(share_name) ⇒ Object
290 291 292 |
# File 'lib/shared_should.rb', line 290 def use_setup(share_name) add_setup_block(:use_setup, share_name, &source_context.find_shared_block(:setup, share_name)) end |
#use_should(share_name) ⇒ Object
325 326 327 |
# File 'lib/shared_should.rb', line 325 def use_should(share_name) add_test_block(:use_should, share_name, &source_context.find_shared_block(:should, share_name)) end |
#when(share_name = nil, &initialization_block) ⇒ Object
deprecated
305 306 307 |
# File 'lib/shared_should.rb', line 305 def when(share_name = nil, &initialization_block) return setup(share_name ? "when #{share_name}" : nil, &initialization_block) end |
#with(share_name = nil, &initialization_block) ⇒ Object
deprecated
300 301 302 |
# File 'lib/shared_should.rb', line 300 def with(share_name = nil, &initialization_block) return setup(share_name ? "with #{share_name}" : nil, &initialization_block) end |
#with_setup(share_name) ⇒ Object
deprecated
295 296 297 |
# File 'lib/shared_should.rb', line 295 def with_setup(share_name) return use_setup(share_name) end |