From b3e0fd8fe6829854dc84306914f5685cfbc7e33a Mon Sep 17 00:00:00 2001 From: James Dennes Date: Mon, 9 Jun 2014 12:50:25 +0200 Subject: [PATCH] Add spec and fixtures for successful check --- lib/contribution-checker/checker.rb | 6 +- spec/contribution-checker/checker_spec.rb | 39 ++++++ spec/fixtures/commit.json | 89 ++++++++++++ spec/fixtures/default_compare.json | 157 ++++++++++++++++++++++ spec/fixtures/emails.json | 12 ++ spec/fixtures/repo.json | 93 +++++++++++++ spec/fixtures/user.json | 37 +++++ spec/helper.rb | 27 +++- 8 files changed, 456 insertions(+), 4 deletions(-) create mode 100644 spec/fixtures/commit.json create mode 100644 spec/fixtures/default_compare.json create mode 100644 spec/fixtures/emails.json create mode 100644 spec/fixtures/repo.json create mode 100644 spec/fixtures/user.json diff --git a/lib/contribution-checker/checker.rb b/lib/contribution-checker/checker.rb index 78641bb..24d4d6f 100644 --- a/lib/contribution-checker/checker.rb +++ b/lib/contribution-checker/checker.rb @@ -115,8 +115,8 @@ def commit_in_valid_branch? # The compare status should be "identical" or "behind" if the commit is in # the default branch - unless default_compare && - %w(identical behind).include?(default_compare[:status]) + if default_compare.nil? || + !(%w(identical behind).include?(default_compare[:status])) # If the commit is not in the default branch, check the gh-pages branch begin @@ -171,7 +171,7 @@ def user_has_starred_repo? # # @return [Boolean] def user_is_repo_org_member? - false if @repo[:owner] != "Organization" + return false if @repo[:owner] != "Organization" @client.organization_member? @repo[:owner][:login], @user[:login] end diff --git a/spec/contribution-checker/checker_spec.rb b/spec/contribution-checker/checker_spec.rb index 039cc70..7c1839c 100644 --- a/spec/contribution-checker/checker_spec.rb +++ b/spec/contribution-checker/checker_spec.rb @@ -47,6 +47,45 @@ end end + context "when a commit is successfully checked" do + let(:checker) { checker = ContributionChecker::Checker.new \ + :access_token => "token", + :commit_url => "https://github.com/jdennes/contribution-checker/commit/731e83d4abf1bd67ac6ab68d18387693482e47cf" + } + + before do + stub_get("/repos/jdennes/contribution-checker/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf"). + to_return(json_response("commit.json")) + stub_get("/repos/jdennes/contribution-checker"). + to_return(json_response("repo.json")) + stub_get("/user"). + to_return(json_response("user.json")) + stub_get("/repos/jdennes/contribution-checker/compare/master...731e83d4abf1bd67ac6ab68d18387693482e47cf"). + to_return(json_response("default_compare.json")) + stub_get("/user/emails"). + to_return(json_response("emails.json")) + stub_get("/user/starred/jdennes/contribution-checker"). + to_return(:return => 404) + end + + it "returns the check result" do + result = checker.check + expect(result).to be_a(Hash) + + expect(result[:contribution]).to eq(true) + + expect(result[:and_criteria][:commit_in_valid_branch]).to eq(true) + expect(result[:and_criteria][:commit_in_last_year]).to eq(true) + expect(result[:and_criteria][:repo_not_a_fork]).to eq(true) + expect(result[:and_criteria][:commit_email_linked_to_user]).to eq(true) + + expect(result[:or_criteria][:user_has_starred_repo]).to eq(false) + expect(result[:or_criteria][:user_can_push_to_repo]).to eq(true) + expect(result[:or_criteria][:user_is_repo_org_member]).to eq(false) + expect(result[:or_criteria][:user_has_fork_of_repo]).to eq(false) + end + end + end end diff --git a/spec/fixtures/commit.json b/spec/fixtures/commit.json new file mode 100644 index 0000000..70b2cd5 --- /dev/null +++ b/spec/fixtures/commit.json @@ -0,0 +1,89 @@ +{ + "sha": "731e83d4abf1bd67ac6ab68d18387693482e47cf", + "commit": { + "author": { + "name": "James Dennes", + "email": "example@example.com", + "date": "2014-06-08T10:25:34Z" + }, + "committer": { + "name": "James Dennes", + "email": "example@example.com", + "date": "2014-06-08T10:25:34Z" + }, + "message": "Version 0.0.2", + "tree": { + "sha": "30d937ac96b77183e8df7f319acc1e4387516981", + "url": "https://api.github.com/repos/jdennes/contribution-checker/git/trees/30d937ac96b77183e8df7f319acc1e4387516981" + }, + "url": "https://api.github.com/repos/jdennes/contribution-checker/git/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf", + "comment_count": 0 + }, + "url": "https://api.github.com/repos/jdennes/contribution-checker/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf", + "html_url": "https://github.com/jdennes/contribution-checker/commit/731e83d4abf1bd67ac6ab68d18387693482e47cf", + "comments_url": "https://api.github.com/repos/jdennes/contribution-checker/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf/comments", + "author": { + "login": "jdennes", + "id": 65057, + "avatar_url": "https://avatars.githubusercontent.com/u/65057?", + "gravatar_id": "55fd031da91ef9af6e6ed88b101416a1", + "url": "https://api.github.com/users/jdennes", + "html_url": "https://github.com/jdennes", + "followers_url": "https://api.github.com/users/jdennes/followers", + "following_url": "https://api.github.com/users/jdennes/following{/other_user}", + "gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}", + "starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/jdennes/subscriptions", + "organizations_url": "https://api.github.com/users/jdennes/orgs", + "repos_url": "https://api.github.com/users/jdennes/repos", + "events_url": "https://api.github.com/users/jdennes/events{/privacy}", + "received_events_url": "https://api.github.com/users/jdennes/received_events", + "type": "User", + "site_admin": true + }, + "committer": { + "login": "jdennes", + "id": 65057, + "avatar_url": "https://avatars.githubusercontent.com/u/65057?", + "gravatar_id": "55fd031da91ef9af6e6ed88b101416a1", + "url": "https://api.github.com/users/jdennes", + "html_url": "https://github.com/jdennes", + "followers_url": "https://api.github.com/users/jdennes/followers", + "following_url": "https://api.github.com/users/jdennes/following{/other_user}", + "gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}", + "starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/jdennes/subscriptions", + "organizations_url": "https://api.github.com/users/jdennes/orgs", + "repos_url": "https://api.github.com/users/jdennes/repos", + "events_url": "https://api.github.com/users/jdennes/events{/privacy}", + "received_events_url": "https://api.github.com/users/jdennes/received_events", + "type": "User", + "site_admin": true + }, + "parents": [ + { + "sha": "5514532ab61216d1d7d242fd624a2f215d225a31", + "url": "https://api.github.com/repos/jdennes/contribution-checker/commits/5514532ab61216d1d7d242fd624a2f215d225a31", + "html_url": "https://github.com/jdennes/contribution-checker/commit/5514532ab61216d1d7d242fd624a2f215d225a31" + } + ], + "stats": { + "total": 2, + "additions": 1, + "deletions": 1 + }, + "files": [ + { + "sha": "d8853e79dea5d3235cb470f4ea1de0ec2d17bcb5", + "filename": "lib/contribution-checker/version.rb", + "status": "modified", + "additions": 1, + "deletions": 1, + "changes": 2, + "blob_url": "https://github.com/jdennes/contribution-checker/blob/731e83d4abf1bd67ac6ab68d18387693482e47cf/lib/contribution-checker/version.rb", + "raw_url": "https://github.com/jdennes/contribution-checker/raw/731e83d4abf1bd67ac6ab68d18387693482e47cf/lib/contribution-checker/version.rb", + "contents_url": "https://api.github.com/repos/jdennes/contribution-checker/contents/lib/contribution-checker/version.rb?ref=731e83d4abf1bd67ac6ab68d18387693482e47cf", + "patch": "@@ -1,3 +1,3 @@\n module ContributionChecker\n- VERSION = \"0.0.1\"\n+ VERSION = \"0.0.2\"\n end" + } + ] +} diff --git a/spec/fixtures/default_compare.json b/spec/fixtures/default_compare.json new file mode 100644 index 0000000..34a3bfc --- /dev/null +++ b/spec/fixtures/default_compare.json @@ -0,0 +1,157 @@ +{ + "url": "https://api.github.com/repos/jdennes/contribution-checker/compare/master...731e83d4abf1bd67ac6ab68d18387693482e47cf", + "html_url": "https://github.com/jdennes/contribution-checker/compare/master...731e83d4abf1bd67ac6ab68d18387693482e47cf", + "permalink_url": "https://github.com/jdennes/contribution-checker/compare/jdennes:8007252...jdennes:731e83d", + "diff_url": "https://github.com/jdennes/contribution-checker/compare/master...731e83d4abf1bd67ac6ab68d18387693482e47cf.diff", + "patch_url": "https://github.com/jdennes/contribution-checker/compare/master...731e83d4abf1bd67ac6ab68d18387693482e47cf.patch", + "base_commit": { + "sha": "80072520cb4a9dc70dabbc61492d94c962abdc0b", + "commit": { + "author": { + "name": "James Dennes", + "email": "example@example.com", + "date": "2014-06-08T22:47:15Z" + }, + "committer": { + "name": "James Dennes", + "email": "example@example.com", + "date": "2014-06-08T22:47:15Z" + }, + "message": "Add ContributionChecker::InvalidAccessTokenError", + "tree": { + "sha": "bad7a5547a5b973d74492aba53adb1da02aecb9c", + "url": "https://api.github.com/repos/jdennes/contribution-checker/git/trees/bad7a5547a5b973d74492aba53adb1da02aecb9c" + }, + "url": "https://api.github.com/repos/jdennes/contribution-checker/git/commits/80072520cb4a9dc70dabbc61492d94c962abdc0b", + "comment_count": 0 + }, + "url": "https://api.github.com/repos/jdennes/contribution-checker/commits/80072520cb4a9dc70dabbc61492d94c962abdc0b", + "html_url": "https://github.com/jdennes/contribution-checker/commit/80072520cb4a9dc70dabbc61492d94c962abdc0b", + "comments_url": "https://api.github.com/repos/jdennes/contribution-checker/commits/80072520cb4a9dc70dabbc61492d94c962abdc0b/comments", + "author": { + "login": "jdennes", + "id": 65057, + "avatar_url": "https://avatars.githubusercontent.com/u/65057?", + "gravatar_id": "55fd031da91ef9af6e6ed88b101416a1", + "url": "https://api.github.com/users/jdennes", + "html_url": "https://github.com/jdennes", + "followers_url": "https://api.github.com/users/jdennes/followers", + "following_url": "https://api.github.com/users/jdennes/following{/other_user}", + "gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}", + "starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/jdennes/subscriptions", + "organizations_url": "https://api.github.com/users/jdennes/orgs", + "repos_url": "https://api.github.com/users/jdennes/repos", + "events_url": "https://api.github.com/users/jdennes/events{/privacy}", + "received_events_url": "https://api.github.com/users/jdennes/received_events", + "type": "User", + "site_admin": true + }, + "committer": { + "login": "jdennes", + "id": 65057, + "avatar_url": "https://avatars.githubusercontent.com/u/65057?", + "gravatar_id": "55fd031da91ef9af6e6ed88b101416a1", + "url": "https://api.github.com/users/jdennes", + "html_url": "https://github.com/jdennes", + "followers_url": "https://api.github.com/users/jdennes/followers", + "following_url": "https://api.github.com/users/jdennes/following{/other_user}", + "gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}", + "starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/jdennes/subscriptions", + "organizations_url": "https://api.github.com/users/jdennes/orgs", + "repos_url": "https://api.github.com/users/jdennes/repos", + "events_url": "https://api.github.com/users/jdennes/events{/privacy}", + "received_events_url": "https://api.github.com/users/jdennes/received_events", + "type": "User", + "site_admin": true + }, + "parents": [ + { + "sha": "1a048d7745c5ea48eff015063f49369d6c7c3913", + "url": "https://api.github.com/repos/jdennes/contribution-checker/commits/1a048d7745c5ea48eff015063f49369d6c7c3913", + "html_url": "https://github.com/jdennes/contribution-checker/commit/1a048d7745c5ea48eff015063f49369d6c7c3913" + } + ] + }, + "merge_base_commit": { + "sha": "731e83d4abf1bd67ac6ab68d18387693482e47cf", + "commit": { + "author": { + "name": "James Dennes", + "email": "example@example.com", + "date": "2014-06-08T10:25:34Z" + }, + "committer": { + "name": "James Dennes", + "email": "example@example.com", + "date": "2014-06-08T10:25:34Z" + }, + "message": "Version 0.0.2", + "tree": { + "sha": "30d937ac96b77183e8df7f319acc1e4387516981", + "url": "https://api.github.com/repos/jdennes/contribution-checker/git/trees/30d937ac96b77183e8df7f319acc1e4387516981" + }, + "url": "https://api.github.com/repos/jdennes/contribution-checker/git/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf", + "comment_count": 0 + }, + "url": "https://api.github.com/repos/jdennes/contribution-checker/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf", + "html_url": "https://github.com/jdennes/contribution-checker/commit/731e83d4abf1bd67ac6ab68d18387693482e47cf", + "comments_url": "https://api.github.com/repos/jdennes/contribution-checker/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf/comments", + "author": { + "login": "jdennes", + "id": 65057, + "avatar_url": "https://avatars.githubusercontent.com/u/65057?", + "gravatar_id": "55fd031da91ef9af6e6ed88b101416a1", + "url": "https://api.github.com/users/jdennes", + "html_url": "https://github.com/jdennes", + "followers_url": "https://api.github.com/users/jdennes/followers", + "following_url": "https://api.github.com/users/jdennes/following{/other_user}", + "gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}", + "starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/jdennes/subscriptions", + "organizations_url": "https://api.github.com/users/jdennes/orgs", + "repos_url": "https://api.github.com/users/jdennes/repos", + "events_url": "https://api.github.com/users/jdennes/events{/privacy}", + "received_events_url": "https://api.github.com/users/jdennes/received_events", + "type": "User", + "site_admin": true + }, + "committer": { + "login": "jdennes", + "id": 65057, + "avatar_url": "https://avatars.githubusercontent.com/u/65057?", + "gravatar_id": "55fd031da91ef9af6e6ed88b101416a1", + "url": "https://api.github.com/users/jdennes", + "html_url": "https://github.com/jdennes", + "followers_url": "https://api.github.com/users/jdennes/followers", + "following_url": "https://api.github.com/users/jdennes/following{/other_user}", + "gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}", + "starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/jdennes/subscriptions", + "organizations_url": "https://api.github.com/users/jdennes/orgs", + "repos_url": "https://api.github.com/users/jdennes/repos", + "events_url": "https://api.github.com/users/jdennes/events{/privacy}", + "received_events_url": "https://api.github.com/users/jdennes/received_events", + "type": "User", + "site_admin": true + }, + "parents": [ + { + "sha": "5514532ab61216d1d7d242fd624a2f215d225a31", + "url": "https://api.github.com/repos/jdennes/contribution-checker/commits/5514532ab61216d1d7d242fd624a2f215d225a31", + "html_url": "https://github.com/jdennes/contribution-checker/commit/5514532ab61216d1d7d242fd624a2f215d225a31" + } + ] + }, + "status": "behind", + "ahead_by": 0, + "behind_by": 10, + "total_commits": 0, + "commits": [ + + ], + "files": [ + + ] +} diff --git a/spec/fixtures/emails.json b/spec/fixtures/emails.json new file mode 100644 index 0000000..c054166 --- /dev/null +++ b/spec/fixtures/emails.json @@ -0,0 +1,12 @@ +[ + { + "email": "example@example.com", + "primary": false, + "verified": true + }, + { + "email": "another@example.com", + "primary": true, + "verified": true + } +] diff --git a/spec/fixtures/repo.json b/spec/fixtures/repo.json new file mode 100644 index 0000000..25117fe --- /dev/null +++ b/spec/fixtures/repo.json @@ -0,0 +1,93 @@ +{ + "id": 20517235, + "name": "contribution-checker", + "full_name": "jdennes/contribution-checker", + "owner": { + "login": "jdennes", + "id": 65057, + "avatar_url": "https://avatars.githubusercontent.com/u/65057?", + "gravatar_id": "55fd031da91ef9af6e6ed88b101416a1", + "url": "https://api.github.com/users/jdennes", + "html_url": "https://github.com/jdennes", + "followers_url": "https://api.github.com/users/jdennes/followers", + "following_url": "https://api.github.com/users/jdennes/following{/other_user}", + "gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}", + "starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/jdennes/subscriptions", + "organizations_url": "https://api.github.com/users/jdennes/orgs", + "repos_url": "https://api.github.com/users/jdennes/repos", + "events_url": "https://api.github.com/users/jdennes/events{/privacy}", + "received_events_url": "https://api.github.com/users/jdennes/received_events", + "type": "User", + "site_admin": false + }, + "private": false, + "html_url": "https://github.com/jdennes/contribution-checker", + "description": "Check whether one of your GitHub commits qualifies as a contribution.", + "fork": false, + "url": "https://api.github.com/repos/jdennes/contribution-checker", + "forks_url": "https://api.github.com/repos/jdennes/contribution-checker/forks", + "keys_url": "https://api.github.com/repos/jdennes/contribution-checker/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/jdennes/contribution-checker/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/jdennes/contribution-checker/teams", + "hooks_url": "https://api.github.com/repos/jdennes/contribution-checker/hooks", + "issue_events_url": "https://api.github.com/repos/jdennes/contribution-checker/issues/events{/number}", + "events_url": "https://api.github.com/repos/jdennes/contribution-checker/events", + "assignees_url": "https://api.github.com/repos/jdennes/contribution-checker/assignees{/user}", + "branches_url": "https://api.github.com/repos/jdennes/contribution-checker/branches{/branch}", + "tags_url": "https://api.github.com/repos/jdennes/contribution-checker/tags", + "blobs_url": "https://api.github.com/repos/jdennes/contribution-checker/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/jdennes/contribution-checker/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/jdennes/contribution-checker/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/jdennes/contribution-checker/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/jdennes/contribution-checker/statuses/{sha}", + "languages_url": "https://api.github.com/repos/jdennes/contribution-checker/languages", + "stargazers_url": "https://api.github.com/repos/jdennes/contribution-checker/stargazers", + "contributors_url": "https://api.github.com/repos/jdennes/contribution-checker/contributors", + "subscribers_url": "https://api.github.com/repos/jdennes/contribution-checker/subscribers", + "subscription_url": "https://api.github.com/repos/jdennes/contribution-checker/subscription", + "commits_url": "https://api.github.com/repos/jdennes/contribution-checker/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/jdennes/contribution-checker/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/jdennes/contribution-checker/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/jdennes/contribution-checker/issues/comments/{number}", + "contents_url": "https://api.github.com/repos/jdennes/contribution-checker/contents/{+path}", + "compare_url": "https://api.github.com/repos/jdennes/contribution-checker/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/jdennes/contribution-checker/merges", + "archive_url": "https://api.github.com/repos/jdennes/contribution-checker/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/jdennes/contribution-checker/downloads", + "issues_url": "https://api.github.com/repos/jdennes/contribution-checker/issues{/number}", + "pulls_url": "https://api.github.com/repos/jdennes/contribution-checker/pulls{/number}", + "milestones_url": "https://api.github.com/repos/jdennes/contribution-checker/milestones{/number}", + "notifications_url": "https://api.github.com/repos/jdennes/contribution-checker/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/jdennes/contribution-checker/labels{/name}", + "releases_url": "https://api.github.com/repos/jdennes/contribution-checker/releases{/id}", + "created_at": "2014-06-05T08:16:43Z", + "updated_at": "2014-06-08T22:47:25Z", + "pushed_at": "2014-06-08T22:47:22Z", + "git_url": "git://github.com/jdennes/contribution-checker.git", + "ssh_url": "git@github.com:jdennes/contribution-checker.git", + "clone_url": "https://github.com/jdennes/contribution-checker.git", + "svn_url": "https://github.com/jdennes/contribution-checker", + "homepage": "", + "size": 0, + "stargazers_count": 0, + "watchers_count": 0, + "language": "Ruby", + "has_issues": true, + "has_downloads": true, + "has_wiki": false, + "forks_count": 0, + "mirror_url": null, + "open_issues_count": 0, + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "master", + "permissions": { + "admin": true, + "push": true, + "pull": true + }, + "network_count": 0, + "subscribers_count": 2 +} diff --git a/spec/fixtures/user.json b/spec/fixtures/user.json new file mode 100644 index 0000000..1fae174 --- /dev/null +++ b/spec/fixtures/user.json @@ -0,0 +1,37 @@ +{ + "login": "jdennes", + "id": 65057, + "avatar_url": "https://avatars.githubusercontent.com/u/12345?", + "gravatar_id": "whatever", + "url": "https://api.github.com/users/jdennes", + "html_url": "https://github.com/jdennes", + "followers_url": "https://api.github.com/users/jdennes/followers", + "following_url": "https://api.github.com/users/jdennes/following{/other_user}", + "gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}", + "starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/jdennes/subscriptions", + "organizations_url": "https://api.github.com/users/jdennes/orgs", + "repos_url": "https://api.github.com/users/jdennes/repos", + "events_url": "https://api.github.com/users/jdennes/events{/privacy}", + "received_events_url": "https://api.github.com/users/jdennes/received_events", + "type": "User", + "site_admin": false, + "name": "James Dennes", + "company": "GitHub", + "blog": "http://jdenn.es", + "location": "Berlin, Germany", + "email": "", + "hireable": false, + "bio": "", + "public_repos": 5, + "public_gists": 5, + "followers": 5, + "following": 5, + "created_at": "2009-03-19T22:11:12Z", + "updated_at": "2014-06-08T23:11:57Z", + "private_gists": 5, + "total_private_repos": 5, + "owned_private_repos": 5, + "disk_usage": 100, + "collaborators": 0 +} diff --git a/spec/helper.rb b/spec/helper.rb index d80f0c0..3b160cd 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -1,5 +1,30 @@ require "rspec" -require 'webmock/rspec' +require "webmock/rspec" require "contribution-checker" WebMock.disable_net_connect! + +def github_url(url) + url =~ /^http/ ? url : "https://api.github.com#{url}" +end + +def stub_get(url) + stub_request(:get, github_url(url)) +end + +def fixture_path + File.expand_path("../fixtures", __FILE__) +end + +def fixture(file) + File.new(fixture_path + '/' + file) +end + +def json_response(file) + { + :body => fixture(file), + :headers => { + :content_type => 'application/json; charset=utf-8' + } + } +end