Class: Sweet::Format::RSpec::Example

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Example

Returns a new instance of Example.



33
34
35
36
37
38
39
40
41
# File 'lib/sweet/format/rspec/example.rb', line 33

def initialize(opts = {})
  @name = opts[:name]
  @status = opts[:status].to_sym if opts[:status]
  @file_path = sanitize_file_path(opts[:file_path])
  @line_number = opts[:line_number]
  @duration = opts[:duration]
  @message = opts[:message]
  @screenshot = opts[:screenshot]
end

Instance Attribute Details

#backtraceObject

Returns the value of attribute backtrace.



30
31
32
# File 'lib/sweet/format/rspec/example.rb', line 30

def backtrace
  @backtrace
end

#file_pathObject

Returns the value of attribute file_path.



30
31
32
# File 'lib/sweet/format/rspec/example.rb', line 30

def file_path
  @file_path
end

#line_numberObject

Returns the value of attribute line_number.



30
31
32
# File 'lib/sweet/format/rspec/example.rb', line 30

def line_number
  @line_number
end

#messageObject

Returns the value of attribute message.



30
31
32
# File 'lib/sweet/format/rspec/example.rb', line 30

def message
  @message
end

#nameObject

Returns the value of attribute name.



30
31
32
# File 'lib/sweet/format/rspec/example.rb', line 30

def name
  @name
end

#screenshotObject

Returns the value of attribute screenshot.



30
31
32
# File 'lib/sweet/format/rspec/example.rb', line 30

def screenshot
  @screenshot
end

#statusObject

Returns the value of attribute status.



30
31
32
# File 'lib/sweet/format/rspec/example.rb', line 30

def status
  @status
end

Class Method Details

.from_output(data) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sweet/format/rspec/example.rb', line 6

def from_output(data)
  data = JSON.parse(data, symbolize_names: true) if data.is_a? String

  case data[:status]
  when 'pending'
    message = data[:pending_message]
  when 'failed'
    e = data[:exception]
    message = "#{e[:class]}\n#{e[:message]}"
  end

  backtrace = data[:exception][:backtrace] if data[:exception]

  new name: data[:full_description],
      status: data[:status],
      file_path: data[:file_path],
      line_number: data[:line_number],
      duration: data[:run_time],
      message: message,
      backtrace: backtrace,
      screenshot: data[:screenshot]
end

Instance Method Details

#durationObject



43
44
45
# File 'lib/sweet/format/rspec/example.rb', line 43

def duration
  @duration * 1_000_000_000
end