Some Browser::Options work

This commit is contained in:
erwanlr
2013-04-09 21:40:19 +02:00
parent 47fb8b9938
commit b9524499bf
8 changed files with 203 additions and 135 deletions

View File

@@ -3,6 +3,8 @@
require 'spec_helper'
describe Browser do
it_behaves_like 'Browser::Actions'
CONFIG_FILE_WITHOUT_PROXY = SPEC_FIXTURES_CONF_DIR + '/browser/browser.conf.json'
CONFIG_FILE_WITH_PROXY = SPEC_FIXTURES_CONF_DIR + '/browser/browser.conf_proxy.json'
CONFIG_FILE_WITH_PROXY_AND_AUTH = SPEC_FIXTURES_CONF_DIR + '/browser/browser.conf_proxy_auth.json'
@@ -326,61 +328,6 @@ describe Browser do
end
describe '#post' do
it 'should return a Typhoeus::Response wth body = "Welcome Master" if login=master&password=itsme!' do
url = 'http://example.com/'
stub_request(:post, url).with(body: { login: 'master', password: 'itsme!' }).
to_return(status: 200, body: 'Welcome Master')
response = Browser.post(
url,
body: 'login=master&password=itsme!'
#body: { login: 'master', password: 'hello' } # It's should be this line, but it fails
)
response.should be_a Typhoeus::Response
response.body.should == 'Welcome Master'
end
end
describe '#get' do
it "should return a Typhoeus::Response with body = 'Hello World !'" do
url = 'http://example.com/'
stub_request(:get, url).
to_return(status: 200, body: 'Hello World !')
response = Browser.get(url)
response.should be_a Typhoeus::Response
response.body.should == 'Hello World !'
end
end
describe '#get_and_follow_location' do
# Typhoeus does not follow the location (maybe it's fixed in > 0.4.2)
# Or, something else is wrong
#context 'whitout max_redirects params' do
# context 'when multiples redirection' do
# it 'returns the last redirection response' do
# url = 'http://target.com'
# first_redirection = 'www.first-redirection.com'
# last_redirection = 'last-redirection.com'
# stub_request(:get, url).to_return(status: 301, headers: { location: first_redirection })
# stub_request(:get, first_redirection).to_return(status: 301, headers: { location: last_redirection })
# stub_request(:get, last_redirection).to_return(status: 200, body: 'Hello World!')
# response = @browser.get_and_follow_location(url)
# response.body.should === 'Hellow World!'
# end
# end
#end
end
describe 'testing caching' do
it 'should only do 1 request, and retrieve the other one from the cache' do

View File

@@ -0,0 +1,60 @@
# encoding: UTF-8
shared_examples 'Browser::Actions' do
describe '#post' do
it 'returns a Typhoeus::Response wth body = "Welcome Master" if login=master&password=itsme!' do
url = 'http://example.com/'
stub_request(:post, url).with(body: { login: 'master', password: 'itsme!' }).
to_return(status: 200, body: 'Welcome Master')
response = Browser.post(
url,
body: 'login=master&password=itsme!'
#body: { login: 'master', password: 'hello' } # It's should be this line, but it fails
)
response.should be_a Typhoeus::Response
response.body.should == 'Welcome Master'
end
end
describe '#get' do
it "returns a Typhoeus::Response with body = 'Hello World !'" do
url = 'http://example.com/'
stub_request(:get, url).
to_return(status: 200, body: 'Hello World !')
response = Browser.get(url)
response.should be_a Typhoeus::Response
response.body.should == 'Hello World !'
end
end
describe '#get_and_follow_location' do
# Typhoeus does not follow the location with rspec
# See https://github.com/typhoeus/typhoeus/issues/279
#context 'whitout max_redirects params' do
# context 'when multiples redirection' do
# it 'returns the last redirection response' do
# url = 'http://target.com'
# first_redirection = 'www.first-redirection.com'
# last_redirection = 'last-redirection.com'
# stub_request(:get, url).to_return(status: 301, headers: { location: first_redirection })
# stub_request(:get, first_redirection).to_return(status: 301, headers: { location: last_redirection })
# stub_request(:get, last_redirection).to_return(status: 200, body: 'Hello World!')
# response = Browser.get_and_follow_location(url)
# response.body.should === 'Hellow World!'
# end
# end
#end
end
end

View File

@@ -0,0 +1,5 @@
# encoding: UTF-8
shared_examples 'Browser::Options' do
end