|
4 | 4 |
|
5 | 5 | RSpec.describe ErrbitGithubPlugin::IssueTracker do |
6 | 6 | describe ".label" do |
7 | | - it "return LABEL" do |
8 | | - expect(described_class.label).to eq described_class::LABEL |
9 | | - end |
| 7 | + it { expect(described_class.label).to eq("github") } |
10 | 8 | end |
11 | 9 |
|
12 | 10 | describe ".note" do |
13 | | - it "return NOTE" do |
14 | | - expect(described_class.note).to eq described_class::NOTE |
15 | | - end |
| 11 | + it { expect(described_class.note).to start_with("Please configure your GitHub") } |
16 | 12 | end |
17 | 13 |
|
18 | 14 | describe ".fields" do |
19 | | - it "return FIELDS" do |
20 | | - expect(described_class.fields).to eq described_class::FIELDS |
| 15 | + it do |
| 16 | + expect(described_class.fields).to eq( |
| 17 | + { |
| 18 | + username: { |
| 19 | + placeholder: "Your username on GitHub" |
| 20 | + }, |
| 21 | + password: { |
| 22 | + placeholder: "Password for your account" |
| 23 | + } |
| 24 | + } |
| 25 | + ) |
21 | 26 | end |
22 | 27 | end |
23 | 28 |
|
|
55 | 60 | end |
56 | 61 | context "without errors" do |
57 | 62 | let(:options) do |
58 | | - {username: "foo", password: "bar", github_repo: "user/repos"} |
| 63 | + {username: "foo", password: "bar", github_repo: "user/repository"} |
59 | 64 | end |
60 | 65 | it "return true" do |
61 | 66 | expect(tracker.configured?).to eq true |
|
105 | 110 |
|
106 | 111 | describe "#create_issue" do |
107 | 112 | subject { tracker.create_issue("title", "body", user: user) } |
| 113 | + |
108 | 114 | let(:options) do |
109 | 115 | {username: "foo", password: "bar", github_repo: "user/repos"} |
110 | 116 | end |
| 117 | + |
111 | 118 | let(:fake_github_client) do |
112 | 119 | double("Fake GitHub Client").tap do |github_client| |
113 | 120 | expect(github_client).to receive(:create_issue).and_return(fake_issue) |
114 | 121 | end |
115 | 122 | end |
| 123 | + |
116 | 124 | let(:fake_issue) do |
117 | 125 | double("Fake Issue").tap do |issue| |
118 | 126 | expect(issue).to receive(:html_url).and_return("http://github.com/user/repos/issues/878").twice |
|
126 | 134 | "github_oauth_token" => "valid_token" |
127 | 135 | } |
128 | 136 | end |
| 137 | + |
129 | 138 | it "return issue url" do |
130 | 139 | expect(Octokit::Client).to receive(:new).with( |
131 | 140 | login: user["github_login"], access_token: user["github_oauth_token"] |
132 | 141 | ).and_return(fake_github_client) |
| 142 | + |
133 | 143 | expect(subject).to eq fake_issue.html_url |
134 | 144 | end |
135 | 145 | end |
136 | 146 |
|
137 | 147 | context "signed in with password" do |
138 | 148 | let(:user) { {} } |
| 149 | + |
139 | 150 | it "return issue url" do |
140 | 151 | expect(Octokit::Client).to receive(:new).with( |
141 | 152 | login: options["username"], password: options["password"] |
142 | 153 | ).and_return(fake_github_client) |
| 154 | + |
143 | 155 | expect(subject).to eq fake_issue.html_url |
144 | 156 | end |
145 | 157 | end |
|
148 | 160 | let(:user) do |
149 | 161 | {"github_login" => "alice", "github_oauth_token" => "invalid_token"} |
150 | 162 | end |
| 163 | + |
151 | 164 | it "raise AuthenticationError" do |
152 | 165 | expect(Octokit::Client).to receive(:new).with( |
153 | 166 | login: user["github_login"], access_token: user["github_oauth_token"] |
154 | 167 | ).and_raise(Octokit::Unauthorized) |
| 168 | + |
155 | 169 | expect { subject }.to raise_error(ErrbitGithubPlugin::AuthenticationError) |
156 | 170 | end |
157 | 171 | end |
|
0 commit comments