spec/git-layer_spec.rb in git-layer-0.1.0 vs spec/git-layer_spec.rb in git-layer-0.2.0

- old
+ new

@@ -1,23 +1,198 @@ require File.expand_path(File.dirname(__FILE__) + '/helper') require 'webmock/rspec' +USER_RESPONSE = '{"login":"user_login", "repos_url": "http://api/github.com/user_name/repos", "name": "user_name","email": "test.email@example.com","html_url": "http://www.github.com/user_name"}' +EXAMPLE_USER_RESPONSE = '{"login": "tcclevela", "id": 4340941, "avatar_url": "https://0.gravatar.com/avatar/35120b8227f24c04d7ac2095876db64e?d=https%3A%2F%2Fidenticons.github.com%2Fed559600885df5d58a479d1398f6b765.png", "gravatar_id": "35120b8227f24c04d7ac2095876db64e", "url": "https://api.github.com/users/tcclevela", "html_url": "https://github.com/tcclevela", "followers_url": "https://api.github.com/users/tcclevela/followers", "following_url": "https://api.github.com/users/tcclevela/following{/other_user}", "gists_url": "https://api.github.com/users/tcclevela/gists{/gist_id}", "starred_url": "https://api.github.com/users/tcclevela/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tcclevela/subscriptions", "organizations_url": "https://api.github.com/users/tcclevela/orgs", "repos_url": "https://api.github.com/users/tcclevela/repos", "events_url": "https://api.github.com/users/tcclevela/events{/privacy}", "received_events_url": "https://api.github.com/users/tcclevela/received_events", "type": "User", "site_admin": false, "name": "Teddy Cleveland", "company": "General Assembly", "blog": "http://www.theodorecleveland.com", "location": "Boston", "email": "tcclevela@gmail.com", "hireable": true, "bio": null, "public_repos": 81, "followers": 30, "following": 28, "created_at": "2013-05-04T16:46:49Z", "updated_at": "2013-10-18T18:01:23Z", "public_gists": 5}' +EXAMPLE_REPO_RESPONSE = '[{ "id": 11029752, "name": "address_book", "full_name": "tcclevela/address_book", "owner": { "login": "tcclevela", "id": 4340941, "avatar_url": "https://0.gravatar.com/avatar/35120b8227f24c04d7ac2095876db64e?d=https%3A%2F%2Fidenticons.github.com%2Fed559600885df5d58a479d1398f6b765.png", "gravatar_id": "35120b8227f24c04d7ac2095876db64e", "url": "https://api.github.com/users/tcclevela", "html_url": "https://github.com/tcclevela", "followers_url": "https://api.github.com/users/tcclevela/followers", "following_url": "https://api.github.com/users/tcclevela/following{/other_user}", "gists_url": "https://api.github.com/users/tcclevela/gists{/gist_id}", "starred_url": "https://api.github.com/users/tcclevela/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tcclevela/subscriptions", "organizations_url": "https://api.github.com/users/tcclevela/orgs", "repos_url": "https://api.github.com/users/tcclevela/repos", "events_url": "https://api.github.com/users/tcclevela/events{/privacy}", "received_events_url": "https://api.github.com/users/tcclevela/received_events", "type": "User", "site_admin": false }, "private": false, "html_url": "https://github.com/tcclevela/address_book", "description": "", "fork": true, "url": "https://api.github.com/repos/tcclevela/address_book", "forks_url": "https://api.github.com/repos/tcclevela/address_book/forks", "keys_url": "https://api.github.com/repos/tcclevela/address_book/keys{/key_id}", "collaborators_url": "https://api.github.com/repos/tcclevela/address_book/collaborators{/collaborator}", "teams_url": "https://api.github.com/repos/tcclevela/address_book/teams", "hooks_url": "https://api.github.com/repos/tcclevela/address_book/hooks", "issue_events_url": "https://api.github.com/repos/tcclevela/address_book/issues/events{/number}", "events_url": "https://api.github.com/repos/tcclevela/address_book/events", "assignees_url": "https://api.github.com/repos/tcclevela/address_book/assignees{/user}", "branches_url": "https://api.github.com/repos/tcclevela/address_book/branches{/branch}", "tags_url": "https://api.github.com/repos/tcclevela/address_book/tags", "blobs_url": "https://api.github.com/repos/tcclevela/address_book/git/blobs{/sha}", "git_tags_url": "https://api.github.com/repos/tcclevela/address_book/git/tags{/sha}", "git_refs_url": "https://api.github.com/repos/tcclevela/address_book/git/refs{/sha}", "trees_url": "https://api.github.com/repos/tcclevela/address_book/git/trees{/sha}", "statuses_url": "https://api.github.com/repos/tcclevela/address_book/statuses/{sha}", "languages_url": "https://api.github.com/repos/tcclevela/address_book/languages", "stargazers_url": "https://api.github.com/repos/tcclevela/address_book/stargazers", "contributors_url": "https://api.github.com/repos/tcclevela/address_book/contributors", "subscribers_url": "https://api.github.com/repos/tcclevela/address_book/subscribers", "subscription_url": "https://api.github.com/repos/tcclevela/address_book/subscription", "commits_url": "https://api.github.com/repos/tcclevela/address_book/commits{/sha}", "git_commits_url": "https://api.github.com/repos/tcclevela/address_book/git/commits{/sha}", "comments_url": "https://api.github.com/repos/tcclevela/address_book/comments{/number}", "issue_comment_url": "https://api.github.com/repos/tcclevela/address_book/issues/comments/{number}", "contents_url": "https://api.github.com/repos/tcclevela/address_book/contents/{+path}", "compare_url": "https://api.github.com/repos/tcclevela/address_book/compare/{base}...{head}", "merges_url": "https://api.github.com/repos/tcclevela/address_book/merges", "archive_url": "https://api.github.com/repos/tcclevela/address_book/{archive_format}{/ref}", "downloads_url": "https://api.github.com/repos/tcclevela/address_book/downloads", "issues_url": "https://api.github.com/repos/tcclevela/address_book/issues{/number}", "pulls_url": "https://api.github.com/repos/tcclevela/address_book/pulls{/number}", "milestones_url": "https://api.github.com/repos/tcclevela/address_book/milestones{/number}", "notifications_url": "https://api.github.com/repos/tcclevela/address_book/notifications{?since,all,participating}", "labels_url": "https://api.github.com/repos/tcclevela/address_book/labels{/name}", "created_at": "2013-06-28T15:15:19Z", "updated_at": "2013-06-28T17:18:39Z", "pushed_at": "2013-06-28T17:18:38Z", "git_url": "git://github.com/tcclevela/address_book.git", "ssh_url": "git@github.com:tcclevela/address_book.git", "clone_url": "https://github.com/tcclevela/address_book.git", "svn_url": "https://github.com/tcclevela/address_book", "homepage": null, "size": 132, "watchers_count": 0, "language": "Ruby", "has_issues": false, "has_downloads": true, "has_wiki": true, "forks_count": 0, "mirror_url": null, "open_issues_count": 0, "forks": 0, "open_issues": 0, "watchers": 0, "master_branch": "master", "default_branch": "master" }, { "id": 12090792, "name": "ajax_flags", "full_name": "tcclevela/ajax_flags", "owner": { "login": "tcclevela", "id": 4340941, "avatar_url": "https://0.gravatar.com/avatar/35120b8227f24c04d7ac2095876db64e?d=https%3A%2F%2Fidenticons.github.com%2Fed559600885df5d58a479d1398f6b765.png", "gravatar_id": "35120b8227f24c04d7ac2095876db64e", "url": "https://api.github.com/users/tcclevela", "html_url": "https://github.com/tcclevela", "followers_url": "https://api.github.com/users/tcclevela/followers", "following_url": "https://api.github.com/users/tcclevela/following{/other_user}", "gists_url": "https://api.github.com/users/tcclevela/gists{/gist_id}", "starred_url": "https://api.github.com/users/tcclevela/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tcclevela/subscriptions", "organizations_url": "https://api.github.com/users/tcclevela/orgs", "repos_url": "https://api.github.com/users/tcclevela/repos", "events_url": "https://api.github.com/users/tcclevela/events{/privacy}", "received_events_url": "https://api.github.com/users/tcclevela/received_events", "type": "User", "site_admin": false }, "private": false, "html_url": "https://github.com/tcclevela/ajax_flags", "description": "", "fork": true, "url": "https://api.github.com/repos/tcclevela/ajax_flags", "forks_url": "https://api.github.com/repos/tcclevela/ajax_flags/forks", "keys_url": "https://api.github.com/repos/tcclevela/ajax_flags/keys{/key_id}", "collaborators_url": "https://api.github.com/repos/tcclevela/ajax_flags/collaborators{/collaborator}", "teams_url": "https://api.github.com/repos/tcclevela/ajax_flags/teams", "hooks_url": "https://api.github.com/repos/tcclevela/ajax_flags/hooks", "issue_events_url": "https://api.github.com/repos/tcclevela/ajax_flags/issues/events{/number}", "events_url": "https://api.github.com/repos/tcclevela/ajax_flags/events", "assignees_url": "https://api.github.com/repos/tcclevela/ajax_flags/assignees{/user}", "branches_url": "https://api.github.com/repos/tcclevela/ajax_flags/branches{/branch}", "tags_url": "https://api.github.com/repos/tcclevela/ajax_flags/tags", "blobs_url": "https://api.github.com/repos/tcclevela/ajax_flags/git/blobs{/sha}", "git_tags_url": "https://api.github.com/repos/tcclevela/ajax_flags/git/tags{/sha}", "git_refs_url": "https://api.github.com/repos/tcclevela/ajax_flags/git/refs{/sha}", "trees_url": "https://api.github.com/repos/tcclevela/ajax_flags/git/trees{/sha}", "statuses_url": "https://api.github.com/repos/tcclevela/ajax_flags/statuses/{sha}", "languages_url": "https://api.github.com/repos/tcclevela/ajax_flags/languages", "stargazers_url": "https://api.github.com/repos/tcclevela/ajax_flags/stargazers", "contributors_url": "https://api.github.com/repos/tcclevela/ajax_flags/contributors", "subscribers_url": "https://api.github.com/repos/tcclevela/ajax_flags/subscribers", "subscription_url": "https://api.github.com/repos/tcclevela/ajax_flags/subscription", "commits_url": "https://api.github.com/repos/tcclevela/ajax_flags/commits{/sha}", "git_commits_url": "https://api.github.com/repos/tcclevela/ajax_flags/git/commits{/sha}", "comments_url": "https://api.github.com/repos/tcclevela/ajax_flags/comments{/number}", "issue_comment_url": "https://api.github.com/repos/tcclevela/ajax_flags/issues/comments/{number}", "contents_url": "https://api.github.com/repos/tcclevela/ajax_flags/contents/{+path}", "compare_url": "https://api.github.com/repos/tcclevela/ajax_flags/compare/{base}...{head}", "merges_url": "https://api.github.com/repos/tcclevela/ajax_flags/merges", "archive_url": "https://api.github.com/repos/tcclevela/ajax_flags/{archive_format}{/ref}", "downloads_url": "https://api.github.com/repos/tcclevela/ajax_flags/downloads", "issues_url": "https://api.github.com/repos/tcclevela/ajax_flags/issues{/number}", "pulls_url": "https://api.github.com/repos/tcclevela/ajax_flags/pulls{/number}", "milestones_url": "https://api.github.com/repos/tcclevela/ajax_flags/milestones{/number}", "notifications_url": "https://api.github.com/repos/tcclevela/ajax_flags/notifications{?since,all,participating}", "labels_url": "https://api.github.com/repos/tcclevela/ajax_flags/labels{/name}", "created_at": "2013-08-13T19:35:44Z", "updated_at": "2013-08-15T19:39:53Z", "pushed_at": "2013-08-14T01:13:52Z", "git_url": "git://github.com/tcclevela/ajax_flags.git", "ssh_url": "git@github.com:tcclevela/ajax_flags.git", "clone_url": "https://github.com/tcclevela/ajax_flags.git", "svn_url": "https://github.com/tcclevela/ajax_flags", "homepage": null, "size": 479, "watchers_count": 0, "language": "JavaScript", "has_issues": false, "has_downloads": true, "has_wiki": true, "forks_count": 0, "mirror_url": null, "open_issues_count": 0, "forks": 0, "open_issues": 0, "watchers": 0, "master_branch": "master", "default_branch": "master" }]' +EXAMPLE_REPO_INFO = '{ "id": 11029752, "name": "address_book", "full_name": "tcclevela/address_book", "owner": { "login": "tcclevela", "id": 4340941, "avatar_url": "https://0.gravatar.com/avatar/35120b8227f24c04d7ac2095876db64e?d=https%3A%2F%2Fidenticons.github.com%2Fed559600885df5d58a479d1398f6b765.png", "gravatar_id": "35120b8227f24c04d7ac2095876db64e", "url": "https://api.github.com/users/tcclevela", "html_url": "https://github.com/tcclevela", "followers_url": "https://api.github.com/users/tcclevela/followers", "following_url": "https://api.github.com/users/tcclevela/following{/other_user}", "gists_url": "https://api.github.com/users/tcclevela/gists{/gist_id}", "starred_url": "https://api.github.com/users/tcclevela/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tcclevela/subscriptions", "organizations_url": "https://api.github.com/users/tcclevela/orgs", "repos_url": "https://api.github.com/users/tcclevela/repos", "events_url": "https://api.github.com/users/tcclevela/events{/privacy}", "received_events_url": "https://api.github.com/users/tcclevela/received_events", "type": "User", "site_admin": false }, "private": false, "html_url": "https://github.com/tcclevela/address_book", "description": "", "fork": true, "url": "https://api.github.com/repos/tcclevela/address_book", "forks_url": "https://api.github.com/repos/tcclevela/address_book/forks", "keys_url": "https://api.github.com/repos/tcclevela/address_book/keys{/key_id}", "collaborators_url": "https://api.github.com/repos/tcclevela/address_book/collaborators{/collaborator}", "teams_url": "https://api.github.com/repos/tcclevela/address_book/teams", "hooks_url": "https://api.github.com/repos/tcclevela/address_book/hooks", "issue_events_url": "https://api.github.com/repos/tcclevela/address_book/issues/events{/number}", "events_url": "https://api.github.com/repos/tcclevela/address_book/events", "assignees_url": "https://api.github.com/repos/tcclevela/address_book/assignees{/user}", "branches_url": "https://api.github.com/repos/tcclevela/address_book/branches{/branch}", "tags_url": "https://api.github.com/repos/tcclevela/address_book/tags", "blobs_url": "https://api.github.com/repos/tcclevela/address_book/git/blobs{/sha}", "git_tags_url": "https://api.github.com/repos/tcclevela/address_book/git/tags{/sha}", "git_refs_url": "https://api.github.com/repos/tcclevela/address_book/git/refs{/sha}", "trees_url": "https://api.github.com/repos/tcclevela/address_book/git/trees{/sha}", "statuses_url": "https://api.github.com/repos/tcclevela/address_book/statuses/{sha}", "languages_url": "https://api.github.com/repos/tcclevela/address_book/languages", "stargazers_url": "https://api.github.com/repos/tcclevela/address_book/stargazers", "contributors_url": "https://api.github.com/repos/tcclevela/address_book/contributors", "subscribers_url": "https://api.github.com/repos/tcclevela/address_book/subscribers", "subscription_url": "https://api.github.com/repos/tcclevela/address_book/subscription", "commits_url": "https://api.github.com/repos/tcclevela/address_book/commits{/sha}", "git_commits_url": "https://api.github.com/repos/tcclevela/address_book/git/commits{/sha}", "comments_url": "https://api.github.com/repos/tcclevela/address_book/comments{/number}", "issue_comment_url": "https://api.github.com/repos/tcclevela/address_book/issues/comments/{number}", "contents_url": "https://api.github.com/repos/tcclevela/address_book/contents/{+path}", "compare_url": "https://api.github.com/repos/tcclevela/address_book/compare/{base}...{head}", "merges_url": "https://api.github.com/repos/tcclevela/address_book/merges", "archive_url": "https://api.github.com/repos/tcclevela/address_book/{archive_format}{/ref}", "downloads_url": "https://api.github.com/repos/tcclevela/address_book/downloads", "issues_url": "https://api.github.com/repos/tcclevela/address_book/issues{/number}", "pulls_url": "https://api.github.com/repos/tcclevela/address_book/pulls{/number}", "milestones_url": "https://api.github.com/repos/tcclevela/address_book/milestones{/number}", "notifications_url": "https://api.github.com/repos/tcclevela/address_book/notifications{?since,all,participating}", "labels_url": "https://api.github.com/repos/tcclevela/address_book/labels{/name}", "created_at": "2013-06-28T15:15:19Z", "updated_at": "2013-06-28T17:18:39Z", "pushed_at": "2013-06-28T17:18:38Z", "git_url": "git://github.com/tcclevela/address_book.git", "ssh_url": "git@github.com:tcclevela/address_book.git", "clone_url": "https://github.com/tcclevela/address_book.git", "svn_url": "https://github.com/tcclevela/address_book", "homepage": null, "size": 132, "watchers_count": 0, "language": "Ruby", "has_issues": false, "has_downloads": true, "has_wiki": true, "forks_count": 0, "mirror_url": null, "open_issues_count": 0, "forks": 0, "open_issues": 0, "watchers": 0, "master_branch": "master", "default_branch": "master" }' +EXAMPLE_REPO_INFO_B = '{ "id": 11029752, "name": "address_book", "full_name": "tcclevela/address_book", "owner": { "login": "tcclevela", "id": 4340941, "avatar_url": "https://0.gravatar.com/avatar/35120b8227f24c04d7ac2095876db64e?d=https%3A%2F%2Fidenticons.github.com%2Fed559600885df5d58a479d1398f6b765.png", "gravatar_id": "35120b8227f24c04d7ac2095876db64e", "url": "https://api.github.com/users/tcclevela", "html_url": "https://github.com/tcclevela", "followers_url": "https://api.github.com/users/tcclevela/followers", "following_url": "https://api.github.com/users/tcclevela/following{/other_user}", "gists_url": "https://api.github.com/users/tcclevela/gists{/gist_id}", "starred_url": "https://api.github.com/users/tcclevela/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tcclevela/subscriptions", "organizations_url": "https://api.github.com/users/tcclevela/orgs", "repos_url": "https://api.github.com/users/tcclevela/repos", "events_url": "https://api.github.com/users/tcclevela/events{/privacy}", "received_events_url": "https://api.github.com/users/tcclevela/received_events", "type": "User", "site_admin": false }, "private": false, "html_url": "https://github.com/tcclevela/address_book", "description": "", "fork": false, "url": "https://api.github.com/repos/tcclevela/address_book", "forks_url": "https://api.github.com/repos/tcclevela/address_book/forks", "keys_url": "https://api.github.com/repos/tcclevela/address_book/keys{/key_id}", "collaborators_url": "https://api.github.com/repos/tcclevela/address_book/collaborators{/collaborator}", "teams_url": "https://api.github.com/repos/tcclevela/address_book/teams", "hooks_url": "https://api.github.com/repos/tcclevela/address_book/hooks", "issue_events_url": "https://api.github.com/repos/tcclevela/address_book/issues/events{/number}", "events_url": "https://api.github.com/repos/tcclevela/address_book/events", "assignees_url": "https://api.github.com/repos/tcclevela/address_book/assignees{/user}", "branches_url": "https://api.github.com/repos/tcclevela/address_book/branches{/branch}", "tags_url": "https://api.github.com/repos/tcclevela/address_book/tags", "blobs_url": "https://api.github.com/repos/tcclevela/address_book/git/blobs{/sha}", "git_tags_url": "https://api.github.com/repos/tcclevela/address_book/git/tags{/sha}", "git_refs_url": "https://api.github.com/repos/tcclevela/address_book/git/refs{/sha}", "trees_url": "https://api.github.com/repos/tcclevela/address_book/git/trees{/sha}", "statuses_url": "https://api.github.com/repos/tcclevela/address_book/statuses/{sha}", "languages_url": "https://api.github.com/repos/tcclevela/address_book/languages", "stargazers_url": "https://api.github.com/repos/tcclevela/address_book/stargazers", "contributors_url": "https://api.github.com/repos/tcclevela/address_book/contributors", "subscribers_url": "https://api.github.com/repos/tcclevela/address_book/subscribers", "subscription_url": "https://api.github.com/repos/tcclevela/address_book/subscription", "commits_url": "https://api.github.com/repos/tcclevela/address_book/commits{/sha}", "git_commits_url": "https://api.github.com/repos/tcclevela/address_book/git/commits{/sha}", "comments_url": "https://api.github.com/repos/tcclevela/address_book/comments{/number}", "issue_comment_url": "https://api.github.com/repos/tcclevela/address_book/issues/comments/{number}", "contents_url": "https://api.github.com/repos/tcclevela/address_book/contents/{+path}", "compare_url": "https://api.github.com/repos/tcclevela/address_book/compare/{base}...{head}", "merges_url": "https://api.github.com/repos/tcclevela/address_book/merges", "archive_url": "https://api.github.com/repos/tcclevela/address_book/{archive_format}{/ref}", "downloads_url": "https://api.github.com/repos/tcclevela/address_book/downloads", "issues_url": "https://api.github.com/repos/tcclevela/address_book/issues{/number}", "pulls_url": "https://api.github.com/repos/tcclevela/address_book/pulls{/number}", "milestones_url": "https://api.github.com/repos/tcclevela/address_book/milestones{/number}", "notifications_url": "https://api.github.com/repos/tcclevela/address_book/notifications{?since,all,participating}", "labels_url": "https://api.github.com/repos/tcclevela/address_book/labels{/name}", "created_at": "2013-06-28T15:15:19Z", "updated_at": "2013-06-28T17:18:39Z", "pushed_at": "2013-06-28T17:18:38Z", "git_url": "git://github.com/tcclevela/address_book.git", "ssh_url": "git@github.com:tcclevela/address_book.git", "clone_url": "https://github.com/tcclevela/address_book.git", "svn_url": "https://github.com/tcclevela/address_book", "homepage": null, "size": 132, "watchers_count": 0, "language": "Ruby", "has_issues": false, "has_downloads": true, "has_wiki": true, "forks_count": 0, "mirror_url": null, "open_issues_count": 0, "forks": 0, "open_issues": 0, "watchers": 0, "master_branch": "master", "default_branch": "master" }' +EXAMPLE_COMMITS_RESPONSE = ' {"commits": "list"}' +EXAMPLE_LANGUAGES_RESPONSE = ' {"Ruby": 204929, "JavaScript": 104030, "C++": 1235}' describe "Github" do - it 'should return raise error if initialized without token' do - expect do - Github.new() - end.to raise_error(ArgumentError) + + describe "initialize" do + it 'should return raise error if initialized without token' do + expect do + Github.new() + end.to raise_error(ArgumentError) + end + + it 'should return the authentication token after initialization' do + github = Github.new(access_token: 'token') + github.access_token.should eq('token') + end end - context 'after initialization with token' do + context 'Github::Client' do subject{Github.new(access_token: 'token')} - it 'should return the authentication token after initialization' do - subject.access_token.should eq('token') + + describe "#user method on Github object" do + it "should return the current user\'s information if no username is passed" do + stub_request(:get, "https://api.github.com/user?access_token=token") + .to_return(body: USER_RESPONSE, status: 200) + user = subject.user + user["name"].should eq('user_name') + user["email"].should eq('test.email@example.com') + user["html_url"].should eq('http://www.github.com/user_name') + end end - it "should load the current user\'s information" do - stub_request(:get, "https://api.github.com/user?access_token=token") - .to_return(body: {user: {username: 'uname'}}, status: 200) - subject.user.should eq(user: {username: 'uname'}) + + describe "#name" do + it "should return the current user's name if no username is passed" do + stub_request(:get, "https://api.github.com/user?access_token=token") + .to_return(body: USER_RESPONSE, status: 200) + subject.name.should eq('user_name') + end + + it "should return the searched user's name if username is passed" do + stub_request(:get, "https://api.github.com/users/tcclevela?access_token=token") + .to_return(body: EXAMPLE_USER_RESPONSE, status: 200) + subject.name(login: 'tcclevela').should eq('Teddy Cleveland') + end end + describe "#login" do + it "should return the current user's login if no username is passed" do + stub_request(:get, "https://api.github.com/user?access_token=token") + .to_return(body: USER_RESPONSE, status: 200) + subject.login.should eq('user_login') + end + it "should return the current user's login if username is passed" do + subject.login(login: 'tcclevela').should eq('tcclevela') + end + end + + describe "#email" do + it "should return the current user's email if no username is passed" do + stub_request(:get, "https://api.github.com/user?access_token=token") + .to_return(body: USER_RESPONSE, status: 200) + subject.email.should eq('test.email@example.com') + end + + it "should return the searched user's email if username is passed" do + stub_request(:get, "https://api.github.com/users/tcclevela?access_token=token") + .to_return(body: EXAMPLE_USER_RESPONSE, status: 200) + subject.email(login: 'tcclevela').should eq('tcclevela@gmail.com') + end + end + + describe "#html_url" do + it "should return the html url of the current user if no login is passed" do + stub_request(:get, "https://api.github.com/user?access_token=token") + .to_return(body: USER_RESPONSE, status: 200) + subject.html_url.should eq("http://www.github.com/user_name") + end + it "should return the url of the specified user if login is passed" do + stub_request(:get, "https://api.github.com/users/tcclevela?access_token=token") + .to_return(body: EXAMPLE_USER_RESPONSE, status: 200) + subject.html_url(login: 'tcclevela').should eq("https://github.com/tcclevela") + end + end + + describe "#repos_url" do + it "should return the repos url of the current user if no login is passed" do + stub_request(:get, "https://api.github.com/user?access_token=token") + .to_return(body: USER_RESPONSE, status: 200) + subject.repos_url.should eq("http://api/github.com/user_name/repos") + end + + it "should return the repos url of the specified user if login is passed" do + stub_request(:get, "https://api.github.com/users/tcclevela?access_token=token") + .to_return(body: EXAMPLE_USER_RESPONSE, status: 200) + subject.repos_url(login: 'tcclevela').should eq("https://api.github.com/users/tcclevela/repos") + end + end + describe "#repos" do + it "should return an array" do + stub_request(:get, "https://api.github.com/users/tcclevela?access_token=token") + .to_return(body: EXAMPLE_USER_RESPONSE, status: 200) + stub_request(:get, "https://api.github.com/users/tcclevela/repos?access_token=token") + .to_return(body: EXAMPLE_REPO_RESPONSE, status: 200) + subject.repos(login: 'tcclevela').class.should eq(Github::ReposResponseWrapper) + end + + it 'should return an array of Github::Repo objects' do + stub_request(:get, "https://api.github.com/users/tcclevela?access_token=token") + .to_return(body: EXAMPLE_USER_RESPONSE, status: 200) + stub_request(:get, "https://api.github.com/users/tcclevela/repos?access_token=token") + .to_return(body: EXAMPLE_REPO_RESPONSE, status: 200) + subject.repos(login: 'tcclevela').response.first.class.should eq(Github::Repo) + end + + it "should return the repos of the current user if no login is passed" do + stub_request(:get, "https://api.github.com/user?access_token=token") + .to_return(body: USER_RESPONSE, status: 200) + stub_request(:get, "http://api/github.com/user_name/repos?access_token=token") + .to_return(body: EXAMPLE_REPO_RESPONSE, status: 200) + subject.repos.response.first.class.should eq(Github::Repo) + end + end + end + + context "Repo submodule" do + subject{Github::Repo.new(JSON.parse(EXAMPLE_REPO_INFO), 'token')} + + describe "#language" do + it "should return the primary language that the repository is written in" do + subject.language.should eq("Ruby") + end + end + + describe "#name" do + it "should return the name of the repository" do + subject.name.should eq("address_book") + end + end + + describe "#owner_login" do + it "should return the login of the repo owner" do + subject.owner_login.should eq("tcclevela") + end + end + + describe "#forked?" do + it "should return true if repository is forked" do + subject.forked?.should eq(true) + end + + it "should return false if respository was created by owner" do + unforked = Github::Repo.new(JSON.parse(EXAMPLE_REPO_INFO_B), 'token'); + unforked.forked?.should eq(false) + end + end + + describe "url" do + it "should return the html_url of the repository" do + subject.url.should eq("https://github.com/tcclevela/address_book") + end + end + + describe "#commits_url" do + it "should hit the API and retrieve the commits for the repository" do + subject.commits_url.should eq("https://api.github.com/repos/tcclevela/address_book/commits") + end + end + + describe "#access_token" do + it "should return the access token with which the Github::Repo was initialized" do + subject.access_token.should eq('token') + end + end + + describe "#commits" do + it "should return commits by hitting the commits url passing token as authentication" do + stub_request(:get, "https://api.github.com/repos/tcclevela/address_book/commits?access_token=token") + .to_return(body: EXAMPLE_COMMITS_RESPONSE, status: 200 ) + subject.commits.should eq(JSON.parse(EXAMPLE_COMMITS_RESPONSE)) + end + end + + describe "#languages" do + it "should returna hash containging language-byte pairs" do + stub_request(:get, "https://api.github.com/repos/tcclevela/address_book/languages?access_token=token") + .to_return(body: EXAMPLE_LANGUAGES_RESPONSE, status: 200) + subject.languages.should eq(JSON.parse(EXAMPLE_LANGUAGES_RESPONSE)) + end + end end end