Module: Intermodal::RSpec::Rack::ClassMethods

Defined in:
lib/intermodal/rspec/requests/rack.rb

Instance Method Summary collapse

Instance Method Details

#expects_content_type(mime_type, charset = nil) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/intermodal/rspec/requests/rack.rb', line 115

def expects_content_type(mime_type, charset = nil)
  if mime_type
    it "should respond with content type of #{mime_type}" do
      content_type.should match(%r{^#{mime_type}})
    end
    if charset
      it "should respond encoded in #{charset}" do
        content_type.should match(%r{charset=#{charset}})
      end
    end
  else
    it "should not respond with content type" do
      content_type.should be_nil
    end
  end

end

#expects_empty_bodyObject



133
134
135
136
137
138
# File 'lib/intermodal/rspec/requests/rack.rb', line 133

def expects_empty_body
  it "should respond with a Rack-compliant empty body" do
    response[2].should be_empty
    response[2].should be_respond_to(:each)
  end
end

#expects_status(response_status) ⇒ Object



109
110
111
112
113
# File 'lib/intermodal/rspec/requests/rack.rb', line 109

def expects_status(response_status)
  it "should respond with status #{response_status} #{Intermodal::RSpec::HTTP::STATUS_CODES[response_status.to_s]}" do
    status.should eql(response_status)
  end
end

#rack_request(method, _url, _format = nil, &_payload) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/intermodal/rspec/requests/rack.rb', line 95

def rack_request(method, _url, _format = nil, &_payload)
  _format = _format # Scope for closure
  _payload = proc do nil end unless _payload

  let(:format) { _format } if _format
  let(:request) { rack_compliant_request(method,
                                         request_url_prefix + request_url,
                                         http_headers,
                                         request_raw_payload,
                                         (request_raw_payload ? request_payload_mime_type : nil) ) }
  let(:request_url) { _url }
  let(:request_payload, &_payload)
end

#request(method, _url, payload = nil, &blk) ⇒ Object



88
89
90
91
92
93
# File 'lib/intermodal/rspec/requests/rack.rb', line 88

def request(method, _url, payload = nil, &blk)
  describe "#{method.to_s.upcase} #{_url}" do
    rack_request(method, _url, &payload)
    instance_eval(&blk)
  end
end