Class: Manacle::Example

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example, last_response) ⇒ Example

Returns a new instance of Example.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/manacle/formatter.rb', line 10

def initialize(example, last_response)
  @description = example.description
  @full_description = build_description(example)
  @execution_result = example.execution_result
  #    @run_time = RSpec::Core::Formatters::Helpers.format_duration(@execution_result.run_time)
  @run_time = execution_result.run_time
  @status = @execution_result.status.to_s
   = example.
  @exception = example.exception
  @file_path = [:file_path]
  @last_response = last_response if ['passed', 'failed'].include?(@status)
  # @last_response = last_response
  @case = [:case]
  @params = [:params]
  @params ||= build_params(example)
end

Instance Attribute Details

#caseObject (readonly)

Returns the value of attribute case.



8
9
10
# File 'lib/manacle/formatter.rb', line 8

def case
  @case
end

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/manacle/formatter.rb', line 8

def description
  @description
end

#exceptionObject (readonly)

Returns the value of attribute exception.



8
9
10
# File 'lib/manacle/formatter.rb', line 8

def exception
  @exception
end

#execution_resultObject (readonly)

Returns the value of attribute execution_result.



8
9
10
# File 'lib/manacle/formatter.rb', line 8

def execution_result
  @execution_result
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



8
9
10
# File 'lib/manacle/formatter.rb', line 8

def file_path
  @file_path
end

#full_descriptionObject (readonly)

Returns the value of attribute full_description.



8
9
10
# File 'lib/manacle/formatter.rb', line 8

def full_description
  @full_description
end

#last_responseObject (readonly)

Returns the value of attribute last_response.



8
9
10
# File 'lib/manacle/formatter.rb', line 8

def last_response
  @last_response
end

#metadataObject (readonly)

Returns the value of attribute metadata.



8
9
10
# File 'lib/manacle/formatter.rb', line 8

def 
  
end

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/manacle/formatter.rb', line 8

def params
  @params
end

#run_timeObject (readonly)

Returns the value of attribute run_time.



8
9
10
# File 'lib/manacle/formatter.rb', line 8

def run_time
  @run_time
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/manacle/formatter.rb', line 8

def status
  @status
end

Instance Method Details

#build_description(example) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/manacle/formatter.rb', line 45

def build_description(example)
  full_description = [example.description, example.example_group.description]
  parent = example.example_group.parent
  while parent.is_a?(Class)
    full_description << parent.try(:description)
    parent = parent.parent
  end
  full_description.reverse.join('<br/>')
end

#build_params(example) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/manacle/formatter.rb', line 27

def build_params(example)
  return [] if last_response.nil?
  xml = Nokogiri::XML(last_response.request.options[:body])

  ns = {ns: 'http://www.quantiguous.com/services'}
  params = []

  example.example_group.described_class.param_defaults.each do |pv|
    p = pv.keys.first; v = pv.values.first
    if v.nil?
       params << xml.at_xpath("//ns:#{p}", ns).name.to_sym unless xml.at_xpath("//ns:#{p}", ns).nil?
    else
       params << xml.at_xpath("//ns:#{p}", ns).name.to_sym unless xml.at_xpath("//ns:#{p}", ns).try(:text) == v
    end
  end
  params
end

#param_value(param) ⇒ Object



55
56
57
58
# File 'lib/manacle/formatter.rb', line 55

def param_value(param)
  @reqDoc ||= Nokogiri::XML(@last_response.request.options[:body])
  @reqDoc.at_xpath('//ns:' + param.to_s, 'ns' => 'http://www.quantiguous.com/services').try(:text)
end