Class: Crspec::Example
- Inherits:
-
Object
- Object
- Crspec::Example
- Defined in:
- lib/crspec/example.rb
Defined Under Namespace
Classes: ExampleInvocation
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.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#focused ⇒ Object
Returns the value of attribute focused.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #execute! ⇒ Object
- #focused? ⇒ Boolean
-
#initialize(description, metadata, example_group, block, pending: false, location: nil) ⇒ Example
constructor
A new instance of Example.
- #pending? ⇒ Boolean
- #persistence_key ⇒ Object
Constructor Details
#initialize(description, metadata, example_group, block, pending: false, location: nil) ⇒ Example
Returns a new instance of Example.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/crspec/example.rb', line 10 def initialize(description, , example_group, block, pending: false, location: nil) @id = SecureRandom.uuid @description = description @metadata = .freeze @example_group = example_group @block = block @status = :pending @pending = pending || block.nil? || [:skip] || [:pending] ? true : false @focused = [:focus] ? true : false @error = nil @execution_time = 0 location ||= block&.source_location @file_path, @line_number = location if location 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 |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
7 8 9 |
# File 'lib/crspec/example.rb', line 7 def file_path @file_path end |
#focused ⇒ Object
Returns the value of attribute focused.
8 9 10 |
# File 'lib/crspec/example.rb', line 8 def focused @focused end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/crspec/example.rb', line 7 def id @id end |
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
7 8 9 |
# File 'lib/crspec/example.rb', line 7 def line_number @line_number 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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/crspec/example.rb', line 58 def execute! return if @pending start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) instance = @example_group.create_instance(self) begin around_hooks = @example_group.ancestor_hooks(:around, self) run_around_hooks(instance, around_hooks) do @example_group.run_eager_lets(instance) run_hooks(instance, :before) instance.instance_exec(&@block) if @block @status = :passed end 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 |
#focused? ⇒ Boolean
25 26 27 |
# File 'lib/crspec/example.rb', line 25 def focused? @focused end |
#pending? ⇒ Boolean
29 30 31 |
# File 'lib/crspec/example.rb', line 29 def pending? @pending end |
#persistence_key ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/crspec/example.rb', line 33 def persistence_key @persistence_key ||= begin parts = [] group = @example_group while group parts.unshift(group.description.to_s) group = group.parent end parts << @description.to_s parts.join(" > ") end end |