Class: Crspec::Example
- Inherits:
-
Object
- Object
- Crspec::Example
- Defined in:
- lib/crspec/example.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#example_group ⇒ Object
readonly
Returns the value of attribute example_group.
-
#execution_time ⇒ Object
readonly
Returns the value of attribute execution_time.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(description, metadata, example_group, block) ⇒ Example
constructor
A new instance of Example.
Constructor Details
#initialize(description, metadata, example_group, block) ⇒ Example
Returns a new instance of Example.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/crspec/example.rb', line 9 def initialize(description, , example_group, block) @id = SecureRandom.uuid @description = description @metadata = .freeze @example_group = example_group @block = block @status = :pending @error = nil @execution_time = 0 end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
7 8 9 |
# File 'lib/crspec/example.rb', line 7 def block @block end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/crspec/example.rb', line 7 def description @description end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
7 8 9 |
# File 'lib/crspec/example.rb', line 7 def error @error end |
#example_group ⇒ Object (readonly)
Returns the value of attribute example_group.
7 8 9 |
# File 'lib/crspec/example.rb', line 7 def example_group @example_group end |
#execution_time ⇒ Object (readonly)
Returns the value of attribute execution_time.
7 8 9 |
# File 'lib/crspec/example.rb', line 7 def execution_time @execution_time end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/crspec/example.rb', line 7 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/crspec/example.rb', line 7 def @metadata end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/crspec/example.rb', line 7 def status @status end |
Instance Method Details
#execute! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/crspec/example.rb', line 20 def execute! start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) instance = @example_group.create_instance(self) begin run_hooks(instance, :before) instance.instance_exec(&@block) if @block @status = :passed rescue StandardError, ExpectationNotMetError => e @status = :failed @error = e ensure begin run_hooks(instance, :after) rescue StandardError => e if @status == :passed @status = :failed @error = e end end @execution_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time end end |