Skip to content

Commit

Permalink
Fix VCR::Request#method so that it delegates to Object#method when gi…
Browse files Browse the repository at this point in the history
…ven arguments.
  • Loading branch information
myronmarston committed Feb 8, 2011
1 parent fccbf7e commit 8b2139a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/vcr/structs/request.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Request < Struct.new(:method, :uri, :body, :headers)
include Normalizers::Header include Normalizers::Header
include Normalizers::URI include Normalizers::URI
include Normalizers::Body include Normalizers::Body
include Module.new { alias __method__ method }


def self.from_net_http_request(net_http, request) def self.from_net_http_request(net_http, request)
new( new(
Expand All @@ -13,6 +14,11 @@ def self.from_net_http_request(net_http, request)
) )
end end


def method(*args)
return super if args.empty?
__method__(*args)
end

def matcher(match_attributes) def matcher(match_attributes)
RequestMatcher.new(self, match_attributes) RequestMatcher.new(self, match_attributes)
end end
Expand Down
18 changes: 18 additions & 0 deletions spec/vcr/structs/request_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@
end end
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 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(: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")) } let(:request) { YAML.load(File.read("#{VCR::SPEC_ROOT}/fixtures/#{YAML_SERIALIZATION_VERSION}/example_net_http_request.yml")) }
Expand Down

0 comments on commit 8b2139a

Please sign in to comment.