Skip to content

Commit

Permalink
Remove request stubbing
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Sadauskas committed May 29, 2008
1 parent 469a945 commit 31082b5
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 54 deletions.
21 changes: 0 additions & 21 deletions lib/resourceful/http_accessor.rb
Expand Up @@ -72,29 +72,8 @@ def user_agent_string
# by the specified URI. A resource object will be created if necessary.
def resource(uri)
resource = Resource.new(self, uri)
return resource unless canned_responses[uri]

# we have some stubbing todo
s_resource = StubbedResourceProxy.new(resource, canned_responses[uri])
return s_resource
end
alias [] resource

# Sets up a canned response for a particular HTTP request. Once
# this stub is configured all matching HTTP requests will return
# the canned response rather than actual HTTP request. This is
# intended primarily for testing purposes.
def stub_request(method, uri, response_mime_type, response_body)
raise ArgumentError, "Only GETs can be stubbed" unless method == :get

(canned_responses[uri] ||= []) << {:mime_type => response_mime_type, :body => response_body}
end

protected

def canned_responses
@canned_responses ||= {}
end

end
end
2 changes: 1 addition & 1 deletion lib/resourceful/version.rb
@@ -1 +1 @@
RESOURCEFUL_VERSION = '0.1'
RESOURCEFUL_VERSION = '0.2'
32 changes: 0 additions & 32 deletions spec/resourceful/http_accessor_spec.rb
Expand Up @@ -117,36 +117,4 @@
@accessor.resource('http://www.example/previously-unused-uri')
end

describe 'request stubbing' do

it 'should allow http request to be stubbed for testing/debugging purposes' do
@accessor.stub_request(:get, 'http://www.example/temptation-waits', 'text/plain', "This is a stubbed response")
end

it 'should return request stubbing resource proxy' do
@accessor.stub_request(:get, 'http://www.example/temptation-waits', 'text/plain', "This is a stubbed response")

@accessor.resource('http://www.example/temptation-waits').should be_kind_of(Resourceful::StubbedResourceProxy)
end

it 'response to stubbed request should have canned body' do
@accessor.stub_request(:get, 'http://www.example/temptation-waits', 'text/plain', "This is a stubbed response")

@accessor.resource('http://www.example/temptation-waits').get.body.should == "This is a stubbed response"
end

it 'response to stubbed request should have canned content_type' do
@accessor.stub_request(:get, 'http://www.example/temptation-waits', 'text/plain', "This is a stubbed response")

@accessor.resource('http://www.example/temptation-waits').get['content-type'].should == "text/plain"
end

it 'should not allow stubbing of not get requests' do
lambda{
@accessor.stub_request(:post, 'http://www.example/temptation-waits', 'text/plain', "This is a stubbed response")
}.should raise_error(ArgumentError)

end
end

end

0 comments on commit 31082b5

Please sign in to comment.