Permalink
Browse files

Deprecate HTTP::Request#method and define #__method__

Finishing up #49.
  • Loading branch information...
1 parent 60e0777 commit b2560383a40688f7da687a68bb1483a1803c6800 @sferik sferik committed Jan 4, 2014
Showing with 42 additions and 4 deletions.
  1. +3 −3 .rspec
  2. +1 −1 Rakefile
  3. +11 −0 lib/http/request.rb
  4. +15 −0 spec/http/request_spec.rb
  5. +12 −0 spec/spec_helper.rb
View
@@ -1,5 +1,5 @@
---color
---format documentation
--backtrace
---warnings
+--color
+--format=documentation
--order random
+--warnings
View
@@ -22,7 +22,7 @@ end
require 'yardstick/rake/verify'
Yardstick::Rake::Verify.new do |verify|
- verify.threshold = 55.4
+ verify.threshold = 55.2
end
task :default => [:spec, :rubocop, :verify_measurements]
View
@@ -30,6 +30,17 @@ class UnsupportedMethodError < ArgumentError; end
# Method is given as a lowercase symbol e.g. :get, :post
attr_reader :verb
+ # The following alias may be removed in three minor versions (0.8.0) or one
+ # major version (1.0.0)
+ alias_method :__method__, :method
+
+ # The following method may be removed in two minor versions (0.7.0) or one
+ # major version (1.0.0)
+ def method(*args)
+ warn "#{Kernel.caller.first}: [DEPRECATION] HTTP::Request#method is deprecated. Use #verb instead. For Object#method, use #__method__."
+ @verb
+ end
+
# "Request URI" as per RFC 2616
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html
attr_reader :uri
@@ -15,5 +15,20 @@
it 'provides a #headers accessor' do
expect(subject.headers).to eq('Accept' => 'text/html', 'Host' => 'example.com')
end
+
+ it 'provides a #verb accessor' do
+ expect(subject.verb).to eq(:get)
+ end
+
+ it 'provides a #method accessor that outputs a deprecation warning and returns the verb' do
+ warning = capture_warning do
+ expect(subject.method).to eq(subject.verb)
+ end
+ expect(warning).to match(/\[DEPRECATION\] HTTP::Request#method is deprecated\. Use #verb instead\. For Object#method, use #__method__\.$/)
+ end
+
+ it 'provides a #__method__ method that delegates to Object#method' do
+ expect(subject.__method__(:verb)).to be_a(Method)
+ end
end
end
View
@@ -20,3 +20,15 @@
c.syntax = :expect
end
end
+
+def capture_warning(&block)
+ begin
+ old_stderr = $stderr
+ $stderr = StringIO.new
+ block.call
+ result = $stderr.string
+ ensure
+ $stderr = old_stderr
+ end
+ result
+end

0 comments on commit b256038

Please sign in to comment.