Class: NginxTestHelper::HttpMatchers::BeHttpStatus

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

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ BeHttpStatus

Returns a new instance of BeHttpStatus.



4
5
6
7
# File 'lib/nginx_test_helper/http_matchers.rb', line 4

def initialize(expected)
  @expected = expected
  @should_has_content = nil
end

Instance Method Details

#descriptionObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/nginx_test_helper/http_matchers.rb', line 45

def description
  about_content = ""
  returned_values = " but returned with status '#{@target.response_header.status}'"
  if @body.nil? && @length.nil? && @should_has_content.nil?
    returned_values += " and content_length equals to #{@target.response_header.content_length.to_i}"
  elsif @body.nil? && @length.nil?
    about_content += " and #{@should_has_content ? "with body" : "without body"}"
    returned_values += " and #{@should_has_content ? "without body" : "with body"}"
  elsif @body.nil?
    about_content += " and content length #{@length}"
    returned_values += " and #{@target.response_header.content_length} of length"
  else
    about_content += " and body '#{@target.response}'"
    returned_values += " and #{@body} as content"
  end
  "be returned with status '#{@expected}'#{about_content}#{returned_values}"
end

#failure_messageObject Also known as: failure_message_for_should



35
36
37
# File 'lib/nginx_test_helper/http_matchers.rb', line 35

def failure_message
  "expected that the '#{request.method}' to '#{request.uri}' to #{description}"
end

#failure_message_when_negatedObject Also known as: failure_message_for_should_not



40
41
42
# File 'lib/nginx_test_helper/http_matchers.rb', line 40

def failure_message_when_negated
  "expected that the '#{request.method}' to '#{request.uri}' not to #{description}"
end

#matches?(target) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
# File 'lib/nginx_test_helper/http_matchers.rb', line 9

def matches?(target)
  @target = target
  ret = @target.response_header.status.eql?(@expected)
  ret = @should_has_content ? has_content? : !has_content? unless (@should_has_content.nil? || !ret)
  ret = @target.response_header.content_length == @length unless (@length.nil? || !ret)
  ret = @target.response == @body unless (@body.nil? || !ret)
  ret
end

#with_body(body = nil) ⇒ Object



24
25
26
27
28
# File 'lib/nginx_test_helper/http_matchers.rb', line 24

def with_body(body=nil)
  @body = body
  @should_has_content = true
  self
end

#with_body_length(length) ⇒ Object



30
31
32
33
# File 'lib/nginx_test_helper/http_matchers.rb', line 30

def with_body_length(length)
  @length = length
  self
end

#without_bodyObject



19
20
21
22
# File 'lib/nginx_test_helper/http_matchers.rb', line 19

def without_body
  @should_has_content = false
  self
end