Skip to content

Commit

Permalink
add rspec tests, mostly passing
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonmwest committed May 28, 2011
1 parent ee6f8af commit 84afc88
Show file tree
Hide file tree
Showing 14 changed files with 405 additions and 34 deletions.
11 changes: 7 additions & 4 deletions Gemfile
Expand Up @@ -7,10 +7,13 @@ source "http://rubygems.org"
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "rake", "0.8.7"
gem "shoulda", ">= 0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.6.0"
gem "rcov", ">= 0"
gem "shoulda", ">= 0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.6.0"
gem "rcov", ">= 0"
gem "rspec"
gem "faraday"
gem "faraday_middleware"
gem "simplecov"
gem "webmock"
end
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -18,7 +18,7 @@ Jeweler::Tasks.new do |gem|
gem.homepage = "http://github.com/brandonmwest/rainmaker"
gem.license = "MIT"
gem.summary = %Q{Wrapper for the rainmaker API}
gem.description = %Q{TODO: longer description of your gem}
gem.description = %Q{Wrapper for the rainmaker.cc API}
gem.email = "brawest@gmail.com"
gem.authors = ["Brandon M. West"]
# dependencies defined in Gemfile
Expand Down
4 changes: 4 additions & 0 deletions lib/ruby-rainmaker.rb
@@ -1,5 +1,9 @@
require "faraday"
require "faraday_middleware"
require 'ruby_rainmaker/error'
require 'ruby_rainmaker/configuration'
require 'ruby_rainmaker/api'
require 'ruby_rainmaker/client'

module RubyRainmaker
extend Configuration
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_rainmaker/api.rb
@@ -1,7 +1,7 @@
require 'ruby_rainmaker/connection'
require 'ruby_rainmaker/request'

module Twitter
module RubyRainmaker
# @private
class API
# @private
Expand Down
@@ -1,5 +1,4 @@
require 'faraday'
require 'ruby_rainmaker/version'

module RubyRainmaker
# Defines constants and methods related to configuration
Expand Down
3 changes: 1 addition & 2 deletions lib/ruby_rainmaker/connection.rb
Expand Up @@ -17,8 +17,7 @@ def connection(raw=false)
}

Faraday.new(options) do |builder|
builder.use Faraday::Request::MultipartWithFile
builder.use Faraday::Request::Multipart
builder.use Faraday::Request::Multipart
builder.use Faraday::Request::UrlEncoded
builder.use Faraday::Request::Gateway, gateway if gateway
builder.use Faraday::Response::RaiseHttp4xx
Expand Down
168 changes: 168 additions & 0 deletions spec/fixtures/person.json
@@ -0,0 +1,168 @@
{
"status": 200,
"contactInfo": {
"familyName": "Lorang",
"givenName": "Bart",
"fullName": "Bart Lorang",
"emailAddresses":
[
"lorangb@gmail.com"
]
},
"interests": {
"Football": true,
"Sports & Recreation": true,
"Business": true,
"Online News": true,
"Baseball": true,
"Tennis": true,
"News & Current Events": true,
"Basketball": true,
"Blogging": true,
"Social Networks": true,
"Online Journals": true,
"Golf": true,
"Technology": true
},
"organizations":
[
{
"name": "Forseti Holdings, LLC",
"title": "Chairman & CEO",
"startDate": "2010-01"
},
{
"name": "Rainmaker Technologies",
"title": "CEO",
"startDate": "2010-01"
},
{
"name": "Forseti Holdings LLC",
"title": "Chairman & CEO",
"isPrimary": true
},
{
"name": "CloudCenter LLC",
"title": "Chairman & CEO",
"isPrimary": false
},
{
"name": "DTS",
"isPrimary": false
}
],
"demographics": {
"influencerScore": "81-90",
"householdIncome": "250k+",
"age": "31",
"homeOwnerStatus": "Own",
"locationGeneral": "Denver, Colorado, United States",
"children": "No",
"gender": "Male",
"maritalStatus": "Single"
},
"socialProfiles":
[
{
"type": "facebook",
"url": "http://www.facebook.com/bart.lorang",
"id": "651620441",
"birthday": "08/16/1979",
"username": "bart.lorang"
},
{
"url": "http://twitter.com/lorangb",
"id": "5998422",
"type": "twitter",
"username": "lorangb"
},
{
"url": "http://www.linkedin.com/in/bartlorang",
"id": "bartlorang",
"type": "linkedin",
"username": "bartlorang"
},
{
"url": "http://about.me/lorangb",
"type": "about.me"
},
{
"url": "http://www.flickr.com/people/39267654@N00/",
"id": "39267654@N00",
"type": "flickr"
},
{
"url": "http://profiles.friendster.com/6986589",
"type": "friendster"
},
{
"url": "https://profiles.google.com/lorangb",
"id": "lorangb",
"type": "google profile",
"username": "lorangb"
},
{
"url": "http://www.myspace.com/137200880",
"type": "myspace"
},
{
"url": "http://picasaweb.google.com/lorangb",
"type": "picasa"
},
{
"url": "http://tungle.me/bartlorang",
"id": "bartlorang",
"type": "tungle.me",
"username": "bartlorang"
},
{
"url": "http://youtube.com/lorangb",
"type": "youtube"
},
{
"type": "friendster",
"url": "http://profiles.friendster.com/6986589"
}
]
"photos":
[
{
"url": "http://graph.facebook.com/651620441/picture?type=large",
"type": "facebook"
},
{
"url": "https://lh5.googleusercontent.com/-EkI-dQC-4iM/AAAAAAAAAAI/AAAAAAAAAAA/o2NExlQVurA/photo.jpg?sz=200",
"type": "google profile"
},
{
"url": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/41508_651620441_4210927_n.jpg",
"type": "facebook"
},
{
"url": "http://photos.friendster.com/photos/98/56/6986589/4262265956117t.jpg",
"type": "friendster"
},
{
"url": "http://c2.ac-images.myspacecdn.com/images01/128/l_d7f2149dcb61b290b25232bf4c7968b9.jpg",
"type": "myspace"
},
{
"url": "http://images.plaxo.com/fetch_image?path=249108119662_0_-413637613",
"type": "plaxo"

},
{
"url": "http://a1.twimg.com/profile_images/712689472/Me.png",
"type": "twitter"

},
{
"type": "gravatar",
"url": "https://secure.gravatar.com/avatar/956b7dca7c77a12c43ebe9ae09dfaba8"
},
{
"type": "linkedin",
"url": "http://media.linkedin.com/mpr/mpr/shrink_80_80/p/2/000/086/2c8/2444fae.jpg"
}
],
}
31 changes: 31 additions & 0 deletions spec/helper.rb
@@ -0,0 +1,31 @@
require 'webmock/rspec'
require 'simplecov'
require 'ruby-rainmaker'
require 'rspec'

SimpleCov.start do
add_group 'RubyRainmaker', 'lib/ruby_rainmaker'
add_group 'Faraday Middleware', 'lib/faraday'
add_group 'Specs', 'spec'
end


RSpec.configure do |config|
config.include WebMock::API
end

def a_get(path)
a_request(:get, RubyRainmaker.endpoint + path)
end

def stub_get(path)
stub_request(:get, RubyRainmaker.endpoint + path)
end

def fixture_path
File.expand_path("../fixtures", __FILE__)
end

def fixture(file)
File.new(fixture_path + '/' + file)
end
65 changes: 65 additions & 0 deletions spec/ruby_rainmaker/api_spec.rb
@@ -0,0 +1,65 @@
require 'helper'

describe RubyRainmaker::API do
before do
@keys = RubyRainmaker::Configuration::VALID_OPTIONS_KEYS
end

context "with module configuration" do
before do
RubyRainmaker.configure do |config|
@keys.each do |key|
config.send("#{key}=", key)
end
end
end

after do
RubyRainmaker.reset
end

it "should inherit module configuration" do
api = RubyRainmaker::API.new
@keys.each do |key|
api.send(key).should == key
end
end

context "with class configuration" do

before do
@configuration = {
:consumer_key => 'CK',
:adapter => :typhoeus,
:endpoint => 'http://tumblr.com/',
:gateway => 'apigee-1111.apigee.com',
:format => :xml,
:proxy => 'http://erik:sekret@proxy.example.com:8080',
:user_agent => 'Custom User Agent',
}
end

context "during initialization"

it "should override module configuration" do
api = RubyRainmaker::API.new(@configuration)
@keys.each do |key|
api.send(key).should == @configuration[key]
end
end

context "after initilization" do

it "should override module configuration after initialization" do
api = RubyRainmaker::API.new
@configuration.each do |key, value|
api.send("#{key}=", value)
end
@keys.each do |key|
api.send(key).should == @configuration[key]
end
end
end
end
end
end
12 changes: 12 additions & 0 deletions spec/ruby_rainmaker/client/person_spec.rb
@@ -0,0 +1,12 @@
require 'helper'

describe RubyRainmaker::Client do
RubyRainmaker::Configuration::VALID_FORMATS.each do |format|
context ".new(:format => '#{format}')" do
before do
@client = RubyRainmaker::Client.new(:format => format, :consumer_key => 'CK')
end

end
end
end
10 changes: 10 additions & 0 deletions spec/ruby_rainmaker/client_spec.rb
@@ -0,0 +1,10 @@
require 'helper'

describe RubyRainmaker::Client do
it "should connect using the endpoint configuration" do
client = RubyRainmaker::Client.new
endpoint = URI.parse(client.api_endpoint)
connection = client.send(:connection).build_url(nil).to_s
connection.should == endpoint.to_s
end
end

0 comments on commit 84afc88

Please sign in to comment.