Browser::Actions specs fixes

This commit is contained in:
erwanlr
2013-04-09 18:27:36 +02:00
parent 3525fb87e2
commit 47fb8b9938
5 changed files with 10 additions and 23 deletions

View File

@@ -170,13 +170,6 @@ class Browser
params params
end end
# return the response
def run_request(request)
@hydra.queue request
@hydra.run
request.response
end
private private
# return Array # return Array

View File

@@ -8,7 +8,6 @@ class Browser
# #
# @return [ Typhoeus::Response ] # @return [ Typhoeus::Response ]
def get(url, params = {}) def get(url, params = {})
#Typhoeus.get(url, Browser.instance.merge_request_params(params))
process(url, params.merge(method: :get)) process(url, params.merge(method: :get))
end end
@@ -17,7 +16,6 @@ class Browser
# #
# @return [ Typhoeus::Response ] # @return [ Typhoeus::Response ]
def post(url, params = {}) def post(url, params = {})
#Typhoeus.post(url, Browser.instance.merge_request_params(params))
process(url, params.merge(method: :post)) process(url, params.merge(method: :post))
end end
@@ -38,11 +36,7 @@ class Browser
# #
# @return [ Typhoeus::Response ] # @return [ Typhoeus::Response ]
def process(url, params) def process(url, params)
browser = Browser.instance Typhoeus::Request.new(url, Browser.instance.merge_request_params(params)).run
browser.run_request(
browser.forge_request(url, params)
)
end end
end end

View File

@@ -267,7 +267,7 @@ describe Browser do
cache_ttl: 250, cache_ttl: 250,
headers: { 'User-Agent' => 'SomeUA' }, headers: { 'User-Agent' => 'SomeUA' },
ssl_verifypeer: false, ssl_verifyhost: 0, ssl_verifypeer: false, ssl_verifyhost: 0,
cookie_jar: cookie_jar, cookie_file: cookie_jar cookiejar: cookie_jar, cookiefile: cookie_jar
} }
} }
@@ -333,7 +333,7 @@ describe Browser do
stub_request(:post, url).with(body: { login: 'master', password: 'itsme!' }). stub_request(:post, url).with(body: { login: 'master', password: 'itsme!' }).
to_return(status: 200, body: 'Welcome Master') to_return(status: 200, body: 'Welcome Master')
response = @browser.post( response = Browser.post(
url, url,
body: 'login=master&password=itsme!' body: 'login=master&password=itsme!'
#body: { login: 'master', password: 'hello' } # It's should be this line, but it fails #body: { login: 'master', password: 'hello' } # It's should be this line, but it fails
@@ -351,7 +351,7 @@ describe Browser do
stub_request(:get, url). stub_request(:get, url).
to_return(status: 200, body: 'Hello World !') to_return(status: 200, body: 'Hello World !')
response = @browser.get(url) response = Browser.get(url)
response.should be_a Typhoeus::Response response.should be_a Typhoeus::Response
response.body.should == 'Hello World !' response.body.should == 'Hello World !'
@@ -389,8 +389,8 @@ describe Browser do
stub_request(:get, url). stub_request(:get, url).
to_return(status: 200, body: 'Hello World !') to_return(status: 200, body: 'Hello World !')
response1 = @browser.get(url) response1 = Browser.get(url)
response2 = @browser.get(url) response2 = Browser.get(url)
response1.body.should == response2.body response1.body.should == response2.body
#WebMock.should have_requested(:get, url).times(1) # This one fail, dunno why :s (but it works without mock) #WebMock.should have_requested(:get, url).times(1) # This one fail, dunno why :s (but it works without mock)
@@ -401,7 +401,7 @@ describe Browser do
it 'should not throw an encoding exception' do it 'should not throw an encoding exception' do
url = SPEC_FIXTURES_DIR + '/utf8.html' url = SPEC_FIXTURES_DIR + '/utf8.html'
stub_request(:get, url).to_return(status: 200, body: File.read(url)) stub_request(:get, url).to_return(status: 200, body: File.read(url))
response1 = @browser.get(url) response1 = Browser.get(url)
expect { response1.body }.to_not raise_error expect { response1.body }.to_not raise_error
end end
end end

View File

@@ -7,7 +7,7 @@ shared_examples 'WpItem::Existable' do
let(:response) { Typhoeus::Response.new } let(:response) { Typhoeus::Response.new }
it 'does not create a request' do it 'does not create a request' do
Browser.instance.should_not_receive(:get) Browser.should_not_receive(:get)
subject.stub(:exists_from_response?).and_return(true) subject.stub(:exists_from_response?).and_return(true)
subject.exists?({}, response).should be_true subject.exists?({}, response).should be_true
@@ -16,7 +16,7 @@ shared_examples 'WpItem::Existable' do
context 'when the response is not supplied' do context 'when the response is not supplied' do
it 'creates a request' do it 'creates a request' do
Browser.instance.should_receive(:get) Browser.should_receive(:get)
subject.stub(:exists_from_response?).and_return(false) subject.stub(:exists_from_response?).and_return(false)
subject.exists?.should be_false subject.exists?.should be_false

View File

@@ -27,7 +27,7 @@ shared_examples 'WpTarget::WpRegistrable' do
describe '#registration_enabled?' do describe '#registration_enabled?' do
after do after do
wp_target.stub(:multisite?).and_return(multisite) wp_target.stub(:multisite?).and_return(multisite)
stub_request(:get, wp_target.registration_url.to_s).to_return(@stub) stub_request(:get, wp_target.registration_url).to_return(@stub)
wp_target.registration_enabled?.should === @expected wp_target.registration_enabled?.should === @expected
end end