forked from hexgnu/linkedin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved from fakeweb to webmock, also added the first expectation test …
…to message-items, more to come
- Loading branch information
Showing
3 changed files
with
33 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,47 @@ | ||
require 'fakeweb' | ||
require 'linkedin' | ||
require 'webmock/rspec' | ||
|
||
require 'linkedin' | ||
|
||
FakeWeb.allow_net_connect = false | ||
|
||
def fixture_path | ||
File.expand_path("../fixtures", __FILE__) | ||
end | ||
|
||
def fixture_file(filename) | ||
return '' if filename == '' | ||
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename) | ||
File.read(file_path) | ||
def fixture(file) | ||
File.new(fixture_path + '/' + file) | ||
end | ||
|
||
|
||
def linkedin_url(url) | ||
url =~ /^http/ ? url : "https://api.linkedin.com#{url}" | ||
end | ||
|
||
|
||
def stub_get(url, filename, status=nil) | ||
options = {:body => fixture_file(filename)} | ||
options.merge!({:status => status}) unless status.nil? | ||
options = { :body => fixture(filename) } | ||
options.merge!({ :status => status }) unless status.nil? | ||
|
||
stub_request(:get, linkedin_url(url)).to_return(options) | ||
end | ||
|
||
def stub_post(url, result) | ||
result_hash = { :status => 201 } | ||
result_hash[:body] = fixture(result) if result | ||
|
||
FakeWeb.register_uri(:get, linkedin_url(url), options) | ||
stub_request(:post, linkedin_url(url)).to_return(result_hash) | ||
end | ||
|
||
def stub_post(url, filename) | ||
FakeWeb.register_uri(:post, linkedin_url(url), :body => fixture_file(filename)) | ||
def expect_post(url, body, result = nil) | ||
a_request(:post, linkedin_url(url)).with({ | ||
:body => fixture(body).read, | ||
:headers => { :content_type => 'application/xml' } | ||
}).should have_been_made.once | ||
end | ||
|
||
def stub_put(url, filename) | ||
FakeWeb.register_uri(:put, linkedin_url(url), :body => fixture_file(filename)) | ||
def stub_put(url, returns_xml) | ||
stub_request(:put, linkedin_url(url)).to_return(:body => fixture(returns_xml)) | ||
end | ||
|
||
def stub_delete(url, filename) | ||
FakeWeb.register_uri(:delete, linkedin_url(url), :body => fixture_file(filename)) | ||
def stub_delete(url, returns_xml) | ||
stub_request(:delete, linkedin_url(url)).to_return(:body => fixture(returns_xml)) | ||
end |