diff --git a/.travis.yml b/.travis.yml index 5d2b2c2c..f18f39d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ rvm: - 1.8.7 - ree - 1.9.3 + - 2.0.0 notifications: email: false bundler_args: --without development diff --git a/features/steps/httparty_response_steps.rb b/features/steps/httparty_response_steps.rb index bf535da2..abfacf51 100644 --- a/features/steps/httparty_response_steps.rb +++ b/features/steps/httparty_response_steps.rb @@ -1,3 +1,17 @@ +# Not needed anymore in ruby 2.0, but needed to resolve constants +# in nested namespaces. This is taken from rails :) +def constantize(camel_cased_word) + names = camel_cased_word.split('::') + names.shift if names.empty? || names.first.empty? + + constant = Object + names.each do |name| + constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name) + end + constant +end + + Then /it should return an? (\w+)$/ do |class_string| @response_from_httparty.should be_an_instance_of(class_string.class) end @@ -22,5 +36,5 @@ Then /it should raise (?:an|a) ([\w:]+) exception/ do |exception| @exception_from_httparty.should_not be_nil - @exception_from_httparty.class.name.should eql(exception) + @exception_from_httparty.should be_a constantize(exception) end diff --git a/lib/httparty/response.rb b/lib/httparty/response.rb index 3193b998..abc05aea 100644 --- a/lib/httparty/response.rb +++ b/lib/httparty/response.rb @@ -40,6 +40,11 @@ def inspect end end + # Support old multiple_choice? method from pre 2.0.0 era. + if ::RUBY_VERSION >= "2.0.0" + alias_method :multiple_choice?, :multiple_choices? + end + def respond_to?(name) return true if [:request, :response, :parsed_response, :body, :headers].include?(name) parsed_response.respond_to?(name) || response.respond_to?(name) diff --git a/spec/httparty/response_spec.rb b/spec/httparty/response_spec.rb index 35380d52..19b65f38 100644 --- a/spec/httparty/response_spec.rb +++ b/spec/httparty/response_spec.rb @@ -195,7 +195,14 @@ def response_mock(klass) :unsupported_media_type? => Net::HTTPUnsupportedMediaType, :use_proxy? => Net::HTTPUseProxy, :version_not_supported? => Net::HTTPVersionNotSupported - }.each do |method, klass| + } + + # Ruby 2.0, new name for this response. + if RUBY_VERSION >= "2.0.0" + SPECIFIC_CODES[:multiple_choices?] = Net::HTTPMultipleChoices + end + + SPECIFIC_CODES.each do |method, klass| it "responds to #{method}" do net_response = response_mock(klass) response = HTTParty::Response.new(@request_object, net_response, '') diff --git a/spec/httparty_spec.rb b/spec/httparty_spec.rb index f0d54c59..bc095f3b 100644 --- a/spec/httparty_spec.rb +++ b/spec/httparty_spec.rb @@ -599,11 +599,11 @@ def self.name end it 'should dup the proc on the child class' do - imaginary_option = lambda { "This is a new lambda" } + imaginary_option = lambda { 2 * 3.14 } @parent.default_options[:imaginary_option] = imaginary_option - @parent.default_options[:imaginary_option].should be_equal imaginary_option + @parent.default_options[:imaginary_option].call.should == imaginary_option.call @child1.default_options[:imaginary_option] - @child1.default_options[:imaginary_option].should == imaginary_option + @child1.default_options[:imaginary_option].call.should == imaginary_option.call @child1.default_options[:imaginary_option].should_not be_equal imaginary_option end