Skip to content

Commit

Permalink
Added fakeweb to make rake run timely and tests not dependent on actu…
Browse files Browse the repository at this point in the history
…al api returns
  • Loading branch information
Julian Coutu authored and Julian Coutu committed Dec 14, 2010
1 parent 7509e37 commit 9dd6f12
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/gitnetworkitis/repository.rb
Expand Up @@ -7,7 +7,6 @@ class Repository < Base
def find_all_watched(options={})
resp = self.class.get("/repos/watched/#{self.username}")
json_result = JSON.parse(resp.body.to_s)

result = Array.new
json_result["repositories"].each do |repo|
result.push parse_attributes(repo)
Expand All @@ -30,7 +29,8 @@ def find_all_owned(options={})

def find(options={})
resp = self.class.get("/repos/show/turingstudio/loupe")
parse_attributes(resp["repository"])
json_result = JSON.parse(resp.body.to_s)
parse_attributes(json_result["repository"])
end

private
Expand Down
11 changes: 8 additions & 3 deletions spec/repository_spec.rb
Expand Up @@ -2,18 +2,23 @@

describe "Gitnetworkitis::Repository" do

before :each do
fake_responses
end


it "should list a users watched repositories" do
c = GitNetworkitis::Repository.new("jcoutu", "0ea98987469a2ef1daee5d1e30b42fd8")
repos = c.find_all_watched()
repos.should_not be_empty
repos.length.should == 14
repos.length.should == 15
end

it "should list a users repositories" do
c = GitNetworkitis::Repository.new("jcoutu", "0ea98987469a2ef1daee5d1e30b42fd8")
repos = c.find_all_owned()
#TODO: fix this test
repos.should be_empty
repos.should_not be_empty
repos.length.should == 1
end

it "should allow a user to search for a repo based on owner and repo name" do
Expand Down
1 change: 1 addition & 0 deletions spec/responses/repos_show_jcoutu.json
@@ -0,0 +1 @@
{"repositories":[{"description":"","watchers":3,"has_wiki":true,"url":"https://github.com/jcoutu/gitnetworkitis","open_issues":0,"pushed_at":"2010/12/13 19:18:04 -0800","homepage":"","forks":0,"fork":false,"has_issues":true,"created_at":"2010/12/13 19:16:28 -0800","private":true,"name":"gitnetworkitis","owner":"jcoutu","has_downloads":true}]}
1 change: 1 addition & 0 deletions spec/responses/repos_watched_jcoutu.json
@@ -0,0 +1 @@
{"repositories":[{"description":"Ruby gem for accessing the Campaign Monitor API. Forked to add support for custom fields.","pushed_at":"2010/05/19 16:27:53 -0700","url":"https://github.com/turingstudio/campaign-monitor-ruby","watchers":10,"has_downloads":true,"homepage":"","forks":0,"fork":true,"created_at":"2009/01/12 14:14:37 -0800","organization":"turingstudio","private":false,"has_wiki":true,"name":"campaign-monitor-ruby","owner":"turingstudio","open_issues":0,"has_issues":true},{"description":"","pushed_at":"2010/08/24 13:39:11 -0700","url":"https://github.com/turingstudio/website-citizensoftware","watchers":15,"has_downloads":true,"homepage":"","forks":1,"fork":false,"created_at":"2009/12/17 13:59:26 -0800","organization":"turingstudio","private":true,"has_wiki":true,"name":"website-citizensoftware","owner":"turingstudio","open_issues":0,"has_issues":true},{"description":"","pushed_at":"2010/08/15 20:21:52 -0700","url":"https://github.com/turingstudio/constant-contact","watchers":11,"has_downloads":true,"homepage":"","forks":1,"fork":false,"created_at":"2010/03/23 11:36:05 -0700","organization":"turingstudio","private":true,"has_wiki":true,"name":"constant-contact","owner":"turingstudio","open_issues":0,"has_issues":true},{"description":"A Ruby interface to GitHub API v2","pushed_at":"2010/04/12 15:22:50 -0700","url":"https://github.com/holman/octopi","watchers":2,"has_downloads":true,"homepage":"http://hasmany.info/2009/4/18/ruby-interface-to-github-api","forks":1,"fork":true,"created_at":"2010/04/11 13:24:21 -0700","private":false,"has_wiki":true,"name":"octopi","owner":"holman","open_issues":0,"has_issues":false},{"description":"","pushed_at":"2010/07/15 15:29:59 -0700","url":"https://github.com/turingstudio/brownpapertickets","watchers":7,"has_downloads":true,"homepage":"","forks":0,"fork":false,"created_at":"2010/07/13 11:57:19 -0700","organization":"turingstudio","private":true,"has_wiki":true,"name":"brownpapertickets","owner":"turingstudio","open_issues":0,"has_issues":true},{"description":"","pushed_at":"2010/08/30 13:15:12 -0700","url":"https://github.com/turingstudio/license-audit","watchers":5,"has_downloads":true,"homepage":"","forks":0,"fork":false,"created_at":"2010/08/23 08:45:52 -0700","organization":"turingstudio","private":true,"has_wiki":true,"name":"license-audit","owner":"turingstudio","open_issues":0,"has_issues":true},{"description":"","pushed_at":"2010/09/03 08:57:15 -0700","url":"https://github.com/turingstudio/turing-rails-templates","watchers":5,"has_downloads":true,"homepage":"","forks":1,"fork":false,"created_at":"2010/08/30 10:40:33 -0700","organization":"turingstudio","private":false,"has_wiki":true,"name":"turing-rails-templates","owner":"turingstudio","open_issues":0,"has_issues":true},{"description":"","pushed_at":"2010/10/28 10:17:42 -0700","url":"https://github.com/turingstudio/website-body-evolution-technologies","watchers":12,"has_downloads":true,"homepage":"","forks":0,"fork":false,"created_at":"2010/09/02 14:52:09 -0700","organization":"turingstudio","private":true,"has_wiki":true,"name":"website-body-evolution-technologies","owner":"turingstudio","open_issues":0,"has_issues":true},{"description":"","pushed_at":"2010/12/10 16:30:45 -0800","url":"https://github.com/turingstudio/loupe","watchers":12,"has_downloads":true,"homepage":"","forks":0,"fork":false,"created_at":"2010/09/30 11:43:01 -0700","organization":"turingstudio","private":true,"has_wiki":true,"name":"loupe","owner":"turingstudio","open_issues":0,"has_issues":true},{"description":"easily and transparently use subdomains as parameters in a Rails 3 application","pushed_at":"2010/11/19 11:02:13 -0800","url":"https://github.com/stephenjudkins/subdomainitis","watchers":5,"has_downloads":true,"homepage":"","forks":1,"fork":false,"created_at":"2010/10/21 18:44:12 -0700","private":false,"has_wiki":true,"name":"subdomainitis","owner":"stephenjudkins","open_issues":0,"has_issues":true},{"description":"","pushed_at":"2010/12/01 07:15:19 -0800","url":"https://github.com/turingstudio/zen","watchers":10,"has_downloads":true,"homepage":"","forks":0,"fork":false,"created_at":"2010/11/04 14:24:35 -0700","organization":"turingstudio","private":true,"has_wiki":true,"name":"zen","owner":"turingstudio","open_issues":0,"has_issues":true},{"description":"","pushed_at":"2010/12/01 07:15:11 -0800","url":"https://github.com/turingstudio/zen-server","watchers":10,"has_downloads":true,"homepage":"","forks":0,"fork":false,"created_at":"2010/11/04 14:30:28 -0700","organization":"turingstudio","private":true,"has_wiki":true,"name":"zen-server","owner":"turingstudio","open_issues":0,"has_issues":true},{"description":"","pushed_at":"2010/11/24 02:15:17 -0800","url":"https://github.com/turingstudio/zen-tools","watchers":10,"has_downloads":true,"homepage":"","forks":0,"fork":false,"created_at":"2010/11/04 14:31:30 -0700","organization":"turingstudio","private":true,"has_wiki":true,"name":"zen-tools","owner":"turingstudio","open_issues":0,"has_issues":true},{"description":"","pushed_at":"2010/12/14 00:47:16 -0800","url":"https://github.com/turingstudio/zen-browser","watchers":9,"has_downloads":true,"homepage":"","forks":1,"fork":false,"created_at":"2010/11/17 17:16:00 -0800","organization":"turingstudio","private":true,"has_wiki":true,"name":"zen-browser","owner":"turingstudio","open_issues":0,"has_issues":true},{"description":"","pushed_at":"2010/12/13 19:18:04 -0800","url":"https://github.com/jcoutu/gitnetworkitis","watchers":3,"has_downloads":true,"homepage":"","forks":0,"fork":false,"created_at":"2010/12/13 19:16:28 -0800","private":true,"has_wiki":true,"name":"gitnetworkitis","owner":"jcoutu","open_issues":0,"has_issues":true}]}
1 change: 1 addition & 0 deletions spec/responses/reps_show_turingstudio_loupe.json
@@ -0,0 +1 @@
{"repository":{"description":"","has_wiki":true,"forks":0,"open_issues":0,"pushed_at":"2010/12/10 16:30:45 -0800","url":"https://github.com/turingstudio/loupe","watchers":12,"homepage":"","has_issues":true,"fork":false,"created_at":"2010/09/30 11:43:01 -0700","organization":"turingstudio","private":true,"name":"loupe","owner":"turingstudio","has_downloads":true}}
16 changes: 15 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -2,11 +2,25 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'gitnetworkitis'
require 'fakeweb'

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

RSpec.configure do |config|


end

def response_file(*path)
File.join(File.dirname(__FILE__), "responses", path)
end

def fake_responses
#FakeWeb.allow_net_connect = false
FakeWeb.clean_registry
auth = "jcoutu%2Ftoken:0ea98987469a2ef1daee5d1e30b42fd8@"
FakeWeb.register_uri(:get, "https://#{auth}github.com/api/v2/json/repos/watched/jcoutu", :body => response_file('repos_watched_jcoutu.json'))
FakeWeb.register_uri(:get, "https://#{auth}github.com/api/v2/json/repos/show/jcoutu", :body => response_file('repos_show_jcoutu.json'))
FakeWeb.register_uri(:get, "https://#{auth}github.com/api/v2/json/repos/show/turingstudio/loupe", :body => response_file('reps_show_turingstudio_loupe.json'))
end

0 comments on commit 9dd6f12

Please sign in to comment.