Class: Nutrasuite::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/nutrasuite/contexts.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Context

Returns a new instance of Context.



74
75
76
77
78
79
80
# File 'lib/nutrasuite/contexts.rb', line 74

def initialize(name, &block)
  @name = name
  @block = block

  @setups = []
  @teardowns = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



72
73
74
# File 'lib/nutrasuite/contexts.rb', line 72

def name
  @name
end

#setupsObject (readonly)

Returns the value of attribute setups.



72
73
74
# File 'lib/nutrasuite/contexts.rb', line 72

def setups
  @setups
end

#teardownsObject (readonly)

Returns the value of attribute teardowns.



72
73
74
# File 'lib/nutrasuite/contexts.rb', line 72

def teardowns
  @teardowns
end

Class Method Details

.build_test_name(name = "") ⇒ Object



86
87
88
89
90
91
92
# File 'lib/nutrasuite/contexts.rb', line 86

def self.build_test_name(name="")
  full_name = "test "
  context_stack.each do |context|
    full_name << context.name << " "
  end
  full_name << name
end

.context_stackObject



103
104
105
# File 'lib/nutrasuite/contexts.rb', line 103

def self.context_stack
  @context_stack ||= []
end

.current_contextObject



107
108
109
# File 'lib/nutrasuite/contexts.rb', line 107

def self.current_context
  context_stack.last
end

.current_context?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/nutrasuite/contexts.rb', line 111

def self.current_context?
  !context_stack.empty?
end

.push(name, &block) ⇒ Object



94
95
96
97
98
99
100
101
# File 'lib/nutrasuite/contexts.rb', line 94

def self.push(name, &block)
  context = Context.new(name, &block)
  context_stack.push(context)

  context.build

  context_stack.pop
end

Instance Method Details

#buildObject



82
83
84
# File 'lib/nutrasuite/contexts.rb', line 82

def build
  @block.call
end