From 47fb8b993855c67cc88dfe63b417ed47cf8f2d87 Mon Sep 17 00:00:00 2001 From: erwanlr Date: Tue, 9 Apr 2013 18:27:36 +0200 Subject: [PATCH] Browser::Actions specs fixes --- lib/common/browser.rb | 7 ------- lib/common/browser/actions.rb | 8 +------- spec/lib/common/browser_spec.rb | 12 ++++++------ spec/shared_examples/wp_item_existable.rb | 4 ++-- spec/shared_examples/wp_target/wp_registrable.rb | 2 +- 5 files changed, 10 insertions(+), 23 deletions(-) diff --git a/lib/common/browser.rb b/lib/common/browser.rb index 767aa492..c3ac9e35 100644 --- a/lib/common/browser.rb +++ b/lib/common/browser.rb @@ -170,13 +170,6 @@ class Browser params end - # return the response - def run_request(request) - @hydra.queue request - @hydra.run - request.response - end - private # return Array diff --git a/lib/common/browser/actions.rb b/lib/common/browser/actions.rb index bb3ddde2..230fb428 100644 --- a/lib/common/browser/actions.rb +++ b/lib/common/browser/actions.rb @@ -8,7 +8,6 @@ class Browser # # @return [ Typhoeus::Response ] def get(url, params = {}) - #Typhoeus.get(url, Browser.instance.merge_request_params(params)) process(url, params.merge(method: :get)) end @@ -17,7 +16,6 @@ class Browser # # @return [ Typhoeus::Response ] def post(url, params = {}) - #Typhoeus.post(url, Browser.instance.merge_request_params(params)) process(url, params.merge(method: :post)) end @@ -38,11 +36,7 @@ class Browser # # @return [ Typhoeus::Response ] def process(url, params) - browser = Browser.instance - - browser.run_request( - browser.forge_request(url, params) - ) + Typhoeus::Request.new(url, Browser.instance.merge_request_params(params)).run end end diff --git a/spec/lib/common/browser_spec.rb b/spec/lib/common/browser_spec.rb index e06e649f..64f7008e 100644 --- a/spec/lib/common/browser_spec.rb +++ b/spec/lib/common/browser_spec.rb @@ -267,7 +267,7 @@ describe Browser do cache_ttl: 250, headers: { 'User-Agent' => 'SomeUA' }, 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!' }). to_return(status: 200, body: 'Welcome Master') - response = @browser.post( + response = Browser.post( url, body: 'login=master&password=itsme!' #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). to_return(status: 200, body: 'Hello World !') - response = @browser.get(url) + response = Browser.get(url) response.should be_a Typhoeus::Response response.body.should == 'Hello World !' @@ -389,8 +389,8 @@ describe Browser do stub_request(:get, url). to_return(status: 200, body: 'Hello World !') - response1 = @browser.get(url) - response2 = @browser.get(url) + response1 = Browser.get(url) + response2 = Browser.get(url) response1.body.should == response2.body #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 url = SPEC_FIXTURES_DIR + '/utf8.html' 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 end end diff --git a/spec/shared_examples/wp_item_existable.rb b/spec/shared_examples/wp_item_existable.rb index 63b3d3e8..dd3c1517 100644 --- a/spec/shared_examples/wp_item_existable.rb +++ b/spec/shared_examples/wp_item_existable.rb @@ -7,7 +7,7 @@ shared_examples 'WpItem::Existable' do let(:response) { Typhoeus::Response.new } 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.exists?({}, response).should be_true @@ -16,7 +16,7 @@ shared_examples 'WpItem::Existable' do context 'when the response is not supplied' do it 'creates a request' do - Browser.instance.should_receive(:get) + Browser.should_receive(:get) subject.stub(:exists_from_response?).and_return(false) subject.exists?.should be_false diff --git a/spec/shared_examples/wp_target/wp_registrable.rb b/spec/shared_examples/wp_target/wp_registrable.rb index 67a2a8b2..58c2d2fa 100644 --- a/spec/shared_examples/wp_target/wp_registrable.rb +++ b/spec/shared_examples/wp_target/wp_registrable.rb @@ -27,7 +27,7 @@ shared_examples 'WpTarget::WpRegistrable' do describe '#registration_enabled?' do after do 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 end