Skip to content

Commit

Permalink
moved from fakeweb to webmock, also added the first expectation test …
Browse files Browse the repository at this point in the history
…to message-items, more to come
  • Loading branch information
joshk committed Feb 4, 2011
1 parent e3b2dd9 commit ed8cd83
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
6 changes: 3 additions & 3 deletions linkedin.gemspec
Expand Up @@ -77,22 +77,22 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<nokogiri>, ["~> 1.4.4"])
s.add_development_dependency(%q<rspec>, ["~> 2.4.0"])
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
s.add_development_dependency(%q<fakeweb>, ["~> 1.3.0"])
s.add_development_dependency(%q<webmock>, ["~> 1.6.0"])
else
s.add_dependency(%q<oauth>, ["~> 0.4.0"])
s.add_dependency(%q<crack>, ["~> 0.1.4"])
s.add_dependency(%q<nokogiri>, ["~> 1.4.4"])
s.add_dependency(%q<rspec>, ["~> 2.4.0"])
s.add_dependency(%q<rake>, ["~> 0.8.7"])
s.add_dependency(%q<fakeweb>, ["~> 1.3.0"])
s.add_dependency(%q<webmock>, ["~> 1.6.0"])
end
else
s.add_dependency(%q<oauth>, ["~> 0.4.0"])
s.add_dependency(%q<crack>, ["~> 0.1.4"])
s.add_dependency(%q<nokogiri>, ["~> 1.4.4"])
s.add_dependency(%q<rspec>, ["~> 2.4.0"])
s.add_dependency(%q<rake>, ["~> 0.8.7"])
s.add_dependency(%q<fakeweb>, ["~> 1.3.0"])
s.add_dependency(%q<webmock>, ["~> 1.6.0"])
end
end

2 changes: 2 additions & 0 deletions spec/cases/client_spec.rb
Expand Up @@ -190,6 +190,8 @@
body = "You're certainly the best person for the job!"

client.send_message(subject, body, recipients).should == "201"

expect_post("/v1/people/~/mailbox", "mailbox_items.xml")
end

end
Expand Down
44 changes: 28 additions & 16 deletions spec/spec_helper.rb
@@ -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

0 comments on commit ed8cd83

Please sign in to comment.