Class: Fluoride::Analyzer::GroupContext

Inherits:
Object
  • Object
show all
Defined in:
lib/fluoride-analyzer/group-context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, status, requests, path, query_params) ⇒ GroupContext

Returns a new instance of GroupContext.



5
6
7
# File 'lib/fluoride-analyzer/group-context.rb', line 5

def initialize(method, status, requests, path, query_params)
  @method, @status_code, @requests, @path, @query_params = method, status, requests, path, query_params
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



8
9
10
# File 'lib/fluoride-analyzer/group-context.rb', line 8

def method
  @method
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



8
9
10
# File 'lib/fluoride-analyzer/group-context.rb', line 8

def status_code
  @status_code
end

Instance Method Details

#example_pathObject



33
34
35
# File 'lib/fluoride-analyzer/group-context.rb', line 33

def example_path
  request['path']
end

#example_sourceObject



29
30
31
# File 'lib/fluoride-analyzer/group-context.rb', line 29

def example_source
  request['sources'].keys.first
end

#redirect_pathObject



50
51
52
# File 'lib/fluoride-analyzer/group-context.rb', line 50

def redirect_path
  request['redirect_location'].sub(%r[^https?://#{request['host']}], '')
end

#request_countObject



23
24
25
26
27
# File 'lib/fluoride-analyzer/group-context.rb', line 23

def request_count
  @requests.inject(0) do |sum, request|
    sum + request['sources'].keys.length
  end
end

#request_spec_descriptionObject



37
38
39
# File 'lib/fluoride-analyzer/group-context.rb', line 37

def request_spec_description
  "#@method #{spec_request_path}"
end

#should_whatObject



41
42
43
44
45
46
47
48
# File 'lib/fluoride-analyzer/group-context.rb', line 41

def should_what
  case @status_code.to_i
  when 300..399
    "redirect"
  else
    "succeed"
  end
end

#spec_request_pathObject



76
77
78
# File 'lib/fluoride-analyzer/group-context.rb', line 76

def spec_request_path
  "#{@path}#{@query_params}"
end

#status_descriptionObject



14
15
16
17
18
19
20
21
# File 'lib/fluoride-analyzer/group-context.rb', line 14

def status_description
  case @status_code.to_i
  when 300..399
    "Redirect"
  else
    "OK"
  end
end

#test_methodObject



10
11
12
# File 'lib/fluoride-analyzer/group-context.rb', line 10

def test_method
  @method.downcase
end

#test_request(indent) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fluoride-analyzer/group-context.rb', line 63

def test_request(indent)
  indent = " " * indent
  test_request = "#{test_method} \"#{spec_request_path}\""
  if request.has_key? 'post_params'
    params = request['post_params'].pretty_inspect.split("\n")
    params = ([params[0]] + params[1..-1].map do |line|
      indent + line
    end).join("\n")
    test_request += ", #{params}"
  end
  test_request
end

#test_resultObject



54
55
56
57
58
59
60
61
# File 'lib/fluoride-analyzer/group-context.rb', line 54

def test_result
  case @status_code.to_i
  when 300..399
    ["response.should redirect_to(\"#{redirect_path}\")"]
  else
    ["response.should be_success", "response.status.should == 200"]
  end
end