Module: Sus::It
- Defined in:
- lib/sus/it.rb
Overview
Represents an individual test case.
Class Method Summary collapse
-
.build(parent, description = nil, unique: true, &block) ⇒ Object
Build a new test case class.
Instance Method Summary collapse
-
#call(assertions) ⇒ Object
Execute this test case.
-
#handle_skip(instance, assertions) ⇒ Object
Handle skip logic for the test case.
- #leaf? ⇒ Boolean
-
#print(output) ⇒ Object
Print a representation of this test case.
- #to_s ⇒ Object
Class Method Details
.build(parent, description = nil, unique: true, &block) ⇒ Object
Build a new test case class.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sus/it.rb', line 17 def self.build(parent, description = nil, unique: true, &block) base = Class.new(parent) base.extend(It) base.description = description base.identity = Identity.nested(parent.identity, base.description, unique: unique) base.set_temporary_name("#{self}[#{description}]") if block_given? base.define_method(:call, &block) end return base end |
Instance Method Details
#call(assertions) ⇒ Object
Execute this test case.
51 52 53 54 55 56 57 58 59 |
# File 'lib/sus/it.rb', line 51 def call(assertions) assertions.nested(self, identity: self.identity, isolated: true, measure: true) do |assertions| instance = self.new(assertions) instance.around do handle_skip(instance, assertions) end end end |
#handle_skip(instance, assertions) ⇒ Object
Handle skip logic for the test case.
65 66 67 68 69 |
# File 'lib/sus/it.rb', line 65 def handle_skip(instance, assertions) catch(:skip) do return instance.call end end |
#leaf? ⇒ Boolean
32 33 34 |
# File 'lib/sus/it.rb', line 32 def leaf? true end |
#print(output) ⇒ Object
Print a representation of this test case.
38 39 40 41 42 |
# File 'lib/sus/it.rb', line 38 def print(output) self.superclass.print(output) output.write(" it ", :it, self.description, :reset, " ", :identity, self.identity.to_s, :reset) end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/sus/it.rb', line 45 def to_s "it #{description}" end |