Skip to content

Commit

Permalink
Merge pull request #194 from nixpulvis/ruby-2.0-tests
Browse files Browse the repository at this point in the history
Ruby 2.0 tests
  • Loading branch information
greatuserongithub committed Apr 10, 2013
2 parents 5e6ea14 + a0a07c5 commit 926326e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ rvm:
- 1.8.7
- ree
- 1.9.3
- 2.0.0
notifications:
email: false
bundler_args: --without development
16 changes: 15 additions & 1 deletion features/steps/httparty_response_steps.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
5 changes: 5 additions & 0 deletions lib/httparty/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion spec/httparty/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')
Expand Down
6 changes: 3 additions & 3 deletions spec/httparty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 926326e

Please sign in to comment.