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.



1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
# File 'lib/spectre.rb', line 1177

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

#blockObject (readonly)

Returns the value of attribute block.



1175
1176
1177
# File 'lib/spectre.rb', line 1175

def block
  @block
end

#dataObject (readonly)

Returns the value of attribute data.



1175
1176
1177
# File 'lib/spectre.rb', line 1175

def data
  @data
end

#descObject (readonly)

Returns the value of attribute desc.



1175
1176
1177
# File 'lib/spectre.rb', line 1175

def desc
  @desc
end

#fileObject (readonly)

Returns the value of attribute file.



1175
1176
1177
# File 'lib/spectre.rb', line 1175

def file
  @file
end

#full_descObject (readonly)

Returns the value of attribute full_desc.



1175
1176
1177
# File 'lib/spectre.rb', line 1175

def full_desc
  @full_desc
end

#idObject (readonly)

Returns the value of attribute id.



1175
1176
1177
# File 'lib/spectre.rb', line 1175

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



1175
1176
1177
# File 'lib/spectre.rb', line 1175

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



1175
1176
1177
# File 'lib/spectre.rb', line 1175

def parent
  @parent
end

#rootObject (readonly)

Returns the value of attribute root.



1175
1176
1177
# File 'lib/spectre.rb', line 1175

def root
  @root
end

#tagsObject (readonly)

Returns the value of attribute tags.



1175
1176
1177
# File 'lib/spectre.rb', line 1175

def tags
  @tags
end

Instance Method Details

#<=>(other) ⇒ Object

Natural sort comparison for spec names respecting numeric parts.



1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
# File 'lib/spectre.rb', line 1192

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

Execute this specification with its before/after blocks



1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
# File 'lib/spectre.rb', line 1208

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