Class: SharedShould::SharedProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/shared_should/shared_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_context) ⇒ SharedProxy

Returns a new instance of SharedProxy.



4
5
6
7
# File 'lib/shared_should/shared_proxy.rb', line 4

def initialize(source_context)
  self.setup_block_configs = []
  self.source_context = source_context
end

Instance Attribute Details

#current_actionObject

Returns the value of attribute current_action.



2
3
4
# File 'lib/shared_should/shared_proxy.rb', line 2

def current_action
  @current_action
end

#setup_block_configsObject

Returns the value of attribute setup_block_configs.



2
3
4
# File 'lib/shared_should/shared_proxy.rb', line 2

def setup_block_configs
  @setup_block_configs
end

#source_contextObject

Returns the value of attribute source_context.



2
3
4
# File 'lib/shared_should/shared_proxy.rb', line 2

def source_context
  @source_context
end

#test_blockObject

Returns the value of attribute test_block.



2
3
4
# File 'lib/shared_should/shared_proxy.rb', line 2

def test_block
  @test_block
end

#test_descriptionObject

Returns the value of attribute test_description.



2
3
4
# File 'lib/shared_should/shared_proxy.rb', line 2

def test_description
  @test_description
end

#test_typeObject

Returns the value of attribute test_type.



2
3
4
# File 'lib/shared_should/shared_proxy.rb', line 2

def test_type
  @test_type
end

Instance Method Details

#context(description = nil, &context_block) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/shared_should/shared_proxy.rb', line 52

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



32
33
34
35
36
37
# File 'lib/shared_should/shared_proxy.rb', line 32

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



9
10
11
# File 'lib/shared_should/shared_proxy.rb', line 9

def setup(description = nil, &initialization_block)
  add_setup_block(:setup, description, &initialization_block)
end

#share_executeObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/shared_should/shared_proxy.rb', line 65

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



39
40
41
42
43
44
45
46
# File 'lib/shared_should/shared_proxy.rb', line 39

def should(description = nil, options = {}, &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



61
62
63
# File 'lib/shared_should/shared_proxy.rb', line 61

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



13
14
15
# File 'lib/shared_should/shared_proxy.rb', line 13

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



48
49
50
# File 'lib/shared_should/shared_proxy.rb', line 48

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



28
29
30
# File 'lib/shared_should/shared_proxy.rb', line 28

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



23
24
25
# File 'lib/shared_should/shared_proxy.rb', line 23

def with(share_name = nil, &initialization_block)
  return setup(share_name ? "with #{share_name}" : nil, &initialization_block)
end

#with_setup(share_name) ⇒ Object

deprecated



18
19
20
# File 'lib/shared_should/shared_proxy.rb', line 18

def with_setup(share_name)
  return use_setup(share_name)
end