Class: Fluoride::Analyzer::GroupContext
- Inherits:
-
Object
- Object
- Fluoride::Analyzer::GroupContext
- Defined in:
- lib/fluoride-analyzer/group-context.rb
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
Instance Method Summary collapse
- #example_path ⇒ Object
- #example_source ⇒ Object
-
#initialize(method, status, requests, path, query_params) ⇒ GroupContext
constructor
A new instance of GroupContext.
- #redirect_path ⇒ Object
- #request_count ⇒ Object
- #request_spec_description ⇒ Object
- #should_what ⇒ Object
- #spec_request_path ⇒ Object
- #status_description ⇒ Object
- #test_method ⇒ Object
- #test_request(indent) ⇒ Object
- #test_result ⇒ Object
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
#method ⇒ Object (readonly)
Returns the value of attribute method.
8 9 10 |
# File 'lib/fluoride-analyzer/group-context.rb', line 8 def method @method end |
#status_code ⇒ Object (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_path ⇒ Object
33 34 35 |
# File 'lib/fluoride-analyzer/group-context.rb', line 33 def example_path request['path'] end |
#example_source ⇒ Object
29 30 31 |
# File 'lib/fluoride-analyzer/group-context.rb', line 29 def example_source request['sources'].keys.first end |
#redirect_path ⇒ Object
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_count ⇒ Object
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_description ⇒ Object
37 38 39 |
# File 'lib/fluoride-analyzer/group-context.rb', line 37 def request_spec_description "#@method #{spec_request_path}" end |
#should_what ⇒ Object
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_path ⇒ Object
76 77 78 |
# File 'lib/fluoride-analyzer/group-context.rb', line 76 def spec_request_path "#{@path}#{@query_params}" end |
#status_description ⇒ Object
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_method ⇒ Object
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_result ⇒ Object
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 |