Module: Net::HTTPExt::Etest

Defined in:
lib/vex/base/net/http_ext.rb

Instance Method Summary collapse

Instance Method Details

#test_w_googleObject



195
196
197
198
199
200
201
202
203
204
205
# File 'lib/vex/base/net/http_ext.rb', line 195

def test_w_google
  return unless Socket.online?

  assert Net.exists?("http://www.google.de")
  assert Net.exist?("http://www.google.de")
  
  google = Net.get("http://www.google.de")
  assert google =~ /<title>Google/
  assert google.headers["Content-Type"] =~ /text\/html/
  assert google.headers.content_type =~ /text\/html/
end

#test_w_google_adjusted_headersObject



214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/vex/base/net/http_ext.rb', line 214

def test_w_google_adjusted_headers
  return unless Socket.online?

  Net.with_headers :x_abc => "Test ABC" do
    assert_equal("Test ABC", Net.headers[:x_abc])
    assert Net.exists?("http://www.google.de")
    Net.with_headers :x_abc => nil do
      assert_equal(nil, Net.headers[:x_abc])
    end
    assert_equal("Test ABC", Net.headers[:x_abc])
  end
end

#test_w_google_timeoutObject



207
208
209
210
211
212
# File 'lib/vex/base/net/http_ext.rb', line 207

def test_w_google_timeout
  return unless Socket.online?

  google = Net.get("http://www.google.de", :timeout => 0.01)
  assert_equal(nil, google)
end

#test_w_google_w_redirectionObject



177
178
179
180
181
182
183
184
# File 'lib/vex/base/net/http_ext.rb', line 177

def test_w_google_w_redirection
  return unless Socket.online?

  google = Net.get("http://www.google.com")
  assert google =~ /<title>Google/
  assert google.headers["Content-Type"] =~ /text\/html/
  assert google.headers.content_type =~ /text\/html/
end

#test_w_google_wo_redirectionObject



186
187
188
189
190
191
192
193
# File 'lib/vex/base/net/http_ext.rb', line 186

def test_w_google_wo_redirection
  return unless Socket.online?

  google = Net.get("http://www.google.com", :redirect => false)
  assert_equal(302 , google.code)
  assert google.headers["Content-Type"] =~ /text\/html/
  assert google.headers.content_type =~ /text\/html/
end