Class: Example

Inherits:
Object
  • Object
show all
Defined in:
lib/example.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example) ⇒ Example

Returns a new instance of Example.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/example.rb', line 9

def initialize(example)
  @description = example.description
  @full_description = example.full_description
  @execution_result = example.execution_result
  @run_time = (@execution_result.run_time).round(5)
  @duration = @execution_result.run_time.to_s(:rounded, precision: 5)
  @status = @execution_result.status.to_s
  @metadata = example.
  @file_path = @metadata[:file_path]
  @exception = Oopsy.new(example.exception, @file_path)
  filename = File.basename(@metadata[:file_path])
  line_number = @metadata[:line_number]
  @screenshot = "#{filename}-#{line_number}.png"
  @spec = nil
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/example.rb', line 6

def description
  @description
end

#durationObject (readonly)

Returns the value of attribute duration.



6
7
8
# File 'lib/example.rb', line 6

def duration
  @duration
end

#exceptionObject (readonly)

Returns the value of attribute exception.



6
7
8
# File 'lib/example.rb', line 6

def exception
  @exception
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



6
7
8
# File 'lib/example.rb', line 6

def file_path
  @file_path
end

#full_descriptionObject (readonly)

Returns the value of attribute full_description.



6
7
8
# File 'lib/example.rb', line 6

def full_description
  @full_description
end

#metadataObject (readonly)

Returns the value of attribute metadata.



6
7
8
# File 'lib/example.rb', line 6

def 
  @metadata
end

#run_timeObject (readonly)

Returns the value of attribute run_time.



6
7
8
# File 'lib/example.rb', line 6

def run_time
  @run_time
end

#screenshotObject (readonly)

Returns the value of attribute screenshot.



6
7
8
# File 'lib/example.rb', line 6

def screenshot
  @screenshot
end

#specObject (readonly)

Returns the value of attribute spec.



6
7
8
# File 'lib/example.rb', line 6

def spec
  @spec
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/example.rb', line 6

def status
  @status
end

Instance Method Details

#has_exception?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/example.rb', line 25

def has_exception?
  !@exception.klass.nil?
end

#has_spec?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/example.rb', line 29

def has_spec?
  !@spec.nil?
end

#klass(prefix = 'label-') ⇒ Object



37
38
39
40
# File 'lib/example.rb', line 37

def klass(prefix='label-')
  class_map = {passed: "#{prefix}success", failed: "#{prefix}danger", pending: "#{prefix}warning"}
  class_map[@status.to_sym]
end

#set_spec(spec) ⇒ Object



33
34
35
# File 'lib/example.rb', line 33

def set_spec(spec)
  @spec = spec
end