Class: Spectre::Specification

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, name, desc, tags, data, file, block) ⇒ Specification

Returns a new instance of Specification.



1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
# File 'lib/spectre.rb', line 1173

def initialize parent, name, desc, tags, data, file, block
  @parent = parent
  @root = parent.root
  @name = name
  @desc = desc
  @tags = tags
  @data = data
  @file = file
  @block = block
  @full_desc = "#{@parent.full_desc} #{@desc}"
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



1171
1172
1173
# File 'lib/spectre.rb', line 1171

def data
  @data
end

#descObject (readonly)

Returns the value of attribute desc.



1171
1172
1173
# File 'lib/spectre.rb', line 1171

def desc
  @desc
end

#fileObject (readonly)

Returns the value of attribute file.



1171
1172
1173
# File 'lib/spectre.rb', line 1171

def file
  @file
end

#full_descObject (readonly)

Returns the value of attribute full_desc.



1171
1172
1173
# File 'lib/spectre.rb', line 1171

def full_desc
  @full_desc
end

#idObject (readonly)

Returns the value of attribute id.



1171
1172
1173
# File 'lib/spectre.rb', line 1171

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



1171
1172
1173
# File 'lib/spectre.rb', line 1171

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



1171
1172
1173
# File 'lib/spectre.rb', line 1171

def parent
  @parent
end

#rootObject (readonly)

Returns the value of attribute root.



1171
1172
1173
# File 'lib/spectre.rb', line 1171

def root
  @root
end

#tagsObject (readonly)

Returns the value of attribute tags.



1171
1172
1173
# File 'lib/spectre.rb', line 1171

def tags
  @tags
end

Instance Method Details

#<=>(other) ⇒ Object



1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
# File 'lib/spectre.rb', line 1185

def <=>(other)
  # Split on dash: text part and numeric part
  self_parts = @name.split('-')
  other_parts = other.name.split('-')

  text_compare = self_parts[0] <=> other_parts[0]

  # If the text parts are already different, we can return here
  return text_compare unless text_compare.zero?

  self_parts[1].to_i <=> other_parts[1].to_i
end

#run(engine, befores, afters, bag) ⇒ Object

Creates a new RunContext and executes the spec, before and after blocks



1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
# File 'lib/spectre.rb', line 1202

def run engine, befores, afters, bag
  RunContext.new(engine, self, :spec, bag) do |run_context|
    engine.formatter.scope(@desc, self) do
      befores.each do |block|
        engine.formatter.scope('before', :before) do
          engine.logger.correlate do
            run_context.execute(@data, &block)
          end
        end
      end

      run_context.execute(@data, &@block) if run_context.status == :success
    ensure
      afters.each do |block|
        engine.formatter.scope('after', :after) do
          engine.logger.correlate do
            run_context.execute(@data, &block)
          end
        end
      end
    end
  end
end