Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #394 from calonso/improve_em_http_request_cookies_…

…support

moved cookies tests to proper file
  • Loading branch information...
commit 2a587b20b03403cb76fd88c73ed2308a11155cd4 2 parents 03914e2 + 4fd9074
@bblimke authored
View
73 spec/acceptance/em_http_request/em_http_request_spec.rb
@@ -267,6 +267,79 @@ def client(uri, options = {})
signature.uri.should == Addressable::URI.parse(uri)
end
end
+
+ describe 'get_response_cookie' do
+
+ before(:each) do
+ stub_request(:get, "http://example.org/").
+ to_return(
+ :status => 200,
+ :body => "",
+ :headers => { 'Set-Cookie' => cookie_string }
+ )
+ end
+
+ describe 'success' do
+
+ context 'with only one cookie' do
+
+ let(:cookie_name) { 'name_of_the_cookie' }
+ let(:cookie_value) { 'value_of_the_cookie' }
+ let(:cookie_string) { "#{cookie_name}=#{cookie_value}" }
+
+ it 'successfully gets the cookie' do
+ EM.run {
+ http = EventMachine::HttpRequest.new('http://example.org').get
+
+ http.errback { fail(http.error) }
+ http.callback {
+ http.get_response_cookie(cookie_name).should == cookie_value
+ EM.stop
+ }
+ }
+ end
+ end
+
+ context 'with several cookies' do
+
+ let(:cookie_name) { 'name_of_the_cookie' }
+ let(:cookie_value) { 'value_of_the_cookie' }
+ let(:cookie_2_name) { 'name_of_the_2nd_cookie' }
+ let(:cookie_2_value) { 'value_of_the_2nd_cookie' }
+ let(:cookie_string) { %W(#{cookie_name}=#{cookie_value} #{cookie_2_name}=#{cookie_2_value}) }
+
+ it 'successfully gets both cookies' do
+ EM.run {
+ http = EventMachine::HttpRequest.new('http://example.org').get
+
+ http.errback { fail(http.error) }
+ http.callback {
+ http.get_response_cookie(cookie_name).should == cookie_value
+ http.get_response_cookie(cookie_2_name).should == cookie_2_value
+ EM.stop
+ }
+ }
+ end
+ end
+ end
+
+ describe 'failure' do
+
+ let(:cookie_string) { 'a=b' }
+
+ it 'returns nil when no cookie is found' do
+ EM.run {
+ http = EventMachine::HttpRequest.new('http://example.org').get
+
+ http.errback { fail(http.error) }
+ http.callback {
+ http.get_response_cookie('not_found_cookie').should == nil
+ EM.stop
+ }
+ }
+ end
+ end
+ end
end
end
View
77 spec/unit/http_lib_adapters/webmock_http_client_spec.rb
@@ -1,77 +0,0 @@
-require 'spec_helper'
-
-describe EventMachine::WebMockHttpClient do
-
- describe 'get_response_cookie' do
-
- before(:each) do
- stub_request(:get, "http://example.org/").
- to_return(
- :status => 200,
- :body => "",
- :headers => { 'Set-Cookie' => cookie_string }
- )
- end
-
- describe 'success' do
-
- context 'with only one cookie' do
-
- let(:cookie_name) { 'name_of_the_cookie' }
- let(:cookie_value) { 'value_of_the_cookie' }
- let(:cookie_string) { "#{cookie_name}=#{cookie_value}" }
-
- it 'successfully gets the cookie' do
- EM.run {
- http = EventMachine::HttpRequest.new('http://example.org').get
-
- http.errback { fail(http.error) }
- http.callback {
- http.get_response_cookie(cookie_name).should == cookie_value
- EM.stop
- }
- }
- end
- end
-
- context 'with several cookies' do
-
- let(:cookie_name) { 'name_of_the_cookie' }
- let(:cookie_value) { 'value_of_the_cookie' }
- let(:cookie_2_name) { 'name_of_the_2nd_cookie' }
- let(:cookie_2_value) { 'value_of_the_2nd_cookie' }
- let(:cookie_string) { %W(#{cookie_name}=#{cookie_value} #{cookie_2_name}=#{cookie_2_value}) }
-
- it 'successfully gets both cookies' do
- EM.run {
- http = EventMachine::HttpRequest.new('http://example.org').get
-
- http.errback { fail(http.error) }
- http.callback {
- http.get_response_cookie(cookie_name).should == cookie_value
- http.get_response_cookie(cookie_2_name).should == cookie_2_value
- EM.stop
- }
- }
- end
- end
- end
-
- describe 'failure' do
-
- let(:cookie_string) { 'a=b' }
-
- it 'returns nil when no cookie is found' do
- EM.run {
- http = EventMachine::HttpRequest.new('http://example.org').get
-
- http.errback { fail(http.error) }
- http.callback {
- http.get_response_cookie('not_found_cookie').should == nil
- EM.stop
- }
- }
- end
- end
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.