Class: Spectre::Specification
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#full_desc ⇒ Object
readonly
Returns the value of attribute full_desc.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Natural sort comparison for spec names respecting numeric parts.
-
#initialize(parent, name, desc, tags, data, file, block) ⇒ Specification
constructor
A new instance of Specification.
-
#run(engine, befores, afters, bag) ⇒ Object
Execute this specification with its before/after blocks.
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, , data, file, block @parent = parent @root = parent.root @name = name @desc = desc @tags = @data = data @file = file @block = block @full_desc = "#{@parent.full_desc} #{@desc}" end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
1175 1176 1177 |
# File 'lib/spectre.rb', line 1175 def block @block end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
1175 1176 1177 |
# File 'lib/spectre.rb', line 1175 def data @data end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
1175 1176 1177 |
# File 'lib/spectre.rb', line 1175 def desc @desc end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
1175 1176 1177 |
# File 'lib/spectre.rb', line 1175 def file @file end |
#full_desc ⇒ Object (readonly)
Returns the value of attribute full_desc.
1175 1176 1177 |
# File 'lib/spectre.rb', line 1175 def full_desc @full_desc end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
1175 1176 1177 |
# File 'lib/spectre.rb', line 1175 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1175 1176 1177 |
# File 'lib/spectre.rb', line 1175 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
1175 1176 1177 |
# File 'lib/spectre.rb', line 1175 def parent @parent end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
1175 1176 1177 |
# File 'lib/spectre.rb', line 1175 def root @root end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
1175 1176 1177 |
# File 'lib/spectre.rb', line 1175 def @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 |