Skip to content
Browse files

Fix VCR::Request#method so that it delegates to Object#method when gi…

…ven arguments.
  • Loading branch information...
1 parent fccbf7e commit 8b2139ac93479c5181af5735bc97a3540d259df8 @myronmarston committed Feb 7, 2011
Showing with 24 additions and 0 deletions.
  1. +6 −0 lib/vcr/structs/request.rb
  2. +18 −0 spec/vcr/structs/request_spec.rb
View
6 lib/vcr/structs/request.rb
@@ -3,6 +3,7 @@ class Request < Struct.new(:method, :uri, :body, :headers)
include Normalizers::Header
include Normalizers::URI
include Normalizers::Body
+ include Module.new { alias __method__ method }
def self.from_net_http_request(net_http, request)
new(
@@ -13,6 +14,11 @@ def self.from_net_http_request(net_http, request)
)
end
+ def method(*args)
+ return super if args.empty?
+ __method__(*args)
+ end
+
def matcher(match_attributes)
RequestMatcher.new(self, match_attributes)
end
View
18 spec/vcr/structs/request_spec.rb
@@ -13,6 +13,24 @@
end
end
+ describe '#method' do
+ subject { VCR::Request.new(:get) }
+
+ context 'when given no arguments' do
+ it 'returns the HTTP method' do
+ subject.method.should == :get
+ end
+ end
+
+ context 'when given an argument' do
+ it 'returns the method object for the named method' do
+ m = subject.method(:class)
+ m.should be_a(Method)
+ m.call.should == described_class
+ end
+ end
+ end
+
describe '.from_net_http_request' do
let(:net_http) { YAML.load(File.read("#{VCR::SPEC_ROOT}/fixtures/#{YAML_SERIALIZATION_VERSION}/example_net_http.yml")) }
let(:request) { YAML.load(File.read("#{VCR::SPEC_ROOT}/fixtures/#{YAML_SERIALIZATION_VERSION}/example_net_http_request.yml")) }

0 comments on commit 8b2139a

Please sign in to comment.
Something went wrong with that request. Please try again.