diff --git a/lib/gitnetworkitis/repository.rb b/lib/gitnetworkitis/repository.rb index 346de87..9526c1c 100644 --- a/lib/gitnetworkitis/repository.rb +++ b/lib/gitnetworkitis/repository.rb @@ -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) @@ -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 diff --git a/spec/repository_spec.rb b/spec/repository_spec.rb index 8d4cb93..2dfc37f 100644 --- a/spec/repository_spec.rb +++ b/spec/repository_spec.rb @@ -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 diff --git a/spec/responses/repos_show_jcoutu.json b/spec/responses/repos_show_jcoutu.json new file mode 100644 index 0000000..25f2e06 --- /dev/null +++ b/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}]} \ No newline at end of file diff --git a/spec/responses/repos_watched_jcoutu.json b/spec/responses/repos_watched_jcoutu.json new file mode 100644 index 0000000..69ea99f --- /dev/null +++ b/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}]} \ No newline at end of file diff --git a/spec/responses/reps_show_turingstudio_loupe.json b/spec/responses/reps_show_turingstudio_loupe.json new file mode 100644 index 0000000..b4b7b4b --- /dev/null +++ b/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}} \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 17c5a5a..d049395 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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