Class: Camping::FunctionalTest

Inherits:
Test
  • Object
show all
Defined in:
lib/junebug/ext/mosquito.rb

Instance Method Summary collapse

Methods inherited from Test

#assert_difference, #assert_no_difference, #deny

Instance Method Details



188
189
190
# File 'lib/junebug/ext/mosquito.rb', line 188

def assert_cookie(name, pat, message=nil)
    assert_match pat, @cookies[name], message
end

#assert_match_body(regex, message = nil) ⇒ Object



175
176
177
# File 'lib/junebug/ext/mosquito.rb', line 175

def assert_match_body(regex, message=nil)
  assert_match regex, @response.body, message
end

#assert_no_match_body(regex, message = nil) ⇒ Object



178
179
180
# File 'lib/junebug/ext/mosquito.rb', line 178

def assert_no_match_body(regex, message=nil)
  assert_no_match regex, @response.body, message
end

#assert_redirected_to(url, message = nil) ⇒ Object



182
183
184
185
186
# File 'lib/junebug/ext/mosquito.rb', line 182

def assert_redirected_to(url, message=nil)
  assert_equal  url, 
                @response.headers['Location'].path.gsub(%r!/#{@class_name_abbr.downcase}!, ''), 
                message
end

#assert_response(status_code) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/junebug/ext/mosquito.rb', line 162

def assert_response(status_code)
  case status_code
  when :success
    assert_equal 200, @response.status
  when :redirect
    assert_equal 302, @response.status
  when :error
    assert @response.status >= 500
  else
    assert_equal status_code, @response.status
  end
end

#get(url = '/') ⇒ Object



132
133
134
# File 'lib/junebug/ext/mosquito.rb', line 132

def get(url='/')
  send_request url, {}, 'GET'
end

#post(url, post_vars = {}) ⇒ Object



136
137
138
# File 'lib/junebug/ext/mosquito.rb', line 136

def post(url, post_vars={})
  send_request url, post_vars, 'POST'
end

#send_request(url, post_vars, method) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/junebug/ext/mosquito.rb', line 140

def send_request(url, post_vars, method)
  @request['REQUEST_METHOD'] = method
  @request['SCRIPT_NAME'] = '/' + @class_name_abbr.downcase
  @request['PATH_INFO'] = '/' + url
  @request['REQUEST_URI'] = [@request.SCRIPT_NAME, @request.PATH_INFO].join('')
  
  @request['HTTP_COOKIE'] = @cookies.map {|k,v| "#{k}=#{v}" }.join('; ') if @cookies
  
  @response = eval("#{@class_name_abbr}.run StringIO.new('#{qs_build(post_vars)}'), @request")
  
  @cookies = @response.headers['Set-Cookie'].inject(@cookies||{}) do |res,header|
    data = header.split(';').first
    name, value = data.split('=')
    res[name] = value
    res
  end

  if @response.headers['X-Sendfile']
    @response.body = File.read(@response.headers['X-Sendfile'])
  end      
end

#setupObject



127
128
129
130
# File 'lib/junebug/ext/mosquito.rb', line 127

def setup
  @class_name_abbr = self.class.name.gsub(/Test$/, '')
  @request = MockRequest.new
end

#test_dummyObject



192
# File 'lib/junebug/ext/mosquito.rb', line 192

def test_dummy; end