Skip to content

Commit 4de567a

Browse files
committed
add basic tests for issue_tracker
1 parent cbcbc98 commit 4de567a

File tree

4 files changed

+191
-0
lines changed

4 files changed

+191
-0
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ spec/reports
1515
test/tmp
1616
test/version_tmp
1717
tmp
18+
*.swp
19+
.rspec
20+
vendor/bundle

Diff for: .rspec

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--format documentation

Diff for: spec/issue_tracker_spec.rb

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
require 'spec_helper'
2+
3+
describe ErrbitGithubPlugin::IssueTracker do
4+
describe '.label' do
5+
it 'return LABEL' do
6+
expect(described_class.label).to eq described_class::LABEL
7+
end
8+
end
9+
10+
describe '.note' do
11+
it 'return NOTE' do
12+
expect(described_class.note).to eq described_class::NOTE
13+
end
14+
end
15+
16+
describe '.fields' do
17+
it 'return FIELDS' do
18+
expect(described_class.fields).to eq described_class::FIELDS
19+
end
20+
end
21+
22+
describe '.icons' do
23+
24+
it 'puts create icon onto the icons' do
25+
expect(described_class.icons[:create][0]).to eq 'image/png'
26+
expect(
27+
described_class.icons[:create][1]
28+
).to eq ErrbitGithubPlugin.read_static_file('github_create.png')
29+
end
30+
31+
it 'puts goto icon onto the icons' do
32+
expect(described_class.icons[:goto][0]).to eq 'image/png'
33+
expect(
34+
described_class.icons[:goto][1]
35+
).to eq ErrbitGithubPlugin.read_static_file('github_goto.png')
36+
end
37+
38+
it 'puts inactive icon onto the icons' do
39+
expect(described_class.icons[:inactive][0]).to eq 'image/png'
40+
expect(
41+
described_class.icons[:inactive][1]
42+
).to eq ErrbitGithubPlugin.read_static_file('github_inactive.png')
43+
end
44+
end
45+
46+
let(:tracker) { described_class.new(options) }
47+
48+
describe '#configured?' do
49+
context 'with errors' do
50+
let(:options) { { invalid_key: '' } }
51+
it 'return false' do
52+
expect(tracker.configured?).to eq false
53+
end
54+
end
55+
context 'without errors' do
56+
let(:options) do
57+
{ username: 'foo', password: 'bar', github_repo: 'user/repos' }
58+
end
59+
it 'return true' do
60+
expect(tracker.configured?).to eq true
61+
end
62+
end
63+
end
64+
65+
describe '#url' do
66+
let(:options) { { github_repo: 'repo' } }
67+
it 'returns issues url' do
68+
expect(tracker.url).to eq 'https://github.com/repo/issues'
69+
end
70+
end
71+
72+
describe '#errors' do
73+
subject { tracker.errors }
74+
context 'without username' do
75+
let(:options) { { username: '', password: 'bar', github_repo: 'repo' } }
76+
it { is_expected.not_to be_empty }
77+
end
78+
context 'without password' do
79+
let(:options) do
80+
{ username: '', password: 'bar', github_repo: 'repo' }
81+
end
82+
it { is_expected.not_to be_empty }
83+
end
84+
context 'without github_repo' do
85+
let(:options) do
86+
{ username: 'foo', password: 'bar', github_repo: '' }
87+
end
88+
it { is_expected.not_to be_empty }
89+
end
90+
context 'with completed options' do
91+
let(:options) do
92+
{ username: 'foo', password: 'bar', github_repo: 'repo' }
93+
end
94+
it { is_expected.to be_empty }
95+
end
96+
end
97+
98+
describe '#repo' do
99+
let(:options) { { github_repo: 'baz' } }
100+
it 'returns github repo' do
101+
expect(tracker.repo).to eq 'baz'
102+
end
103+
end
104+
105+
describe '#create_issue' do
106+
subject { tracker.create_issue('title', 'body', user: user) }
107+
let(:options) do
108+
{ username: 'foo', password: 'bar', github_repo: 'user/repos' }
109+
end
110+
let(:fake_github_client) do
111+
double('Fake GitHub Client').tap do |github_client|
112+
github_client.stub(:create_issue).and_return(fake_issue)
113+
end
114+
end
115+
let(:fake_issue) do
116+
double('Fake Issue').tap do |issue|
117+
issue.stub(:html_url).and_return('http://github.com/user/repos/issues/878')
118+
end
119+
end
120+
121+
context 'signed in with token' do
122+
let(:user) do
123+
{
124+
'github_login' => 'bob',
125+
'github_oauth_token' => 'valid_token'
126+
}
127+
end
128+
it 'return issue url' do
129+
Octokit::Client.stub(:new).with(
130+
login: user['github_login'], access_token: user['github_oauth_token']
131+
).and_return(fake_github_client)
132+
expect(subject).to eq fake_issue.html_url
133+
end
134+
end
135+
136+
context 'signed in with password' do
137+
let(:user) { {} }
138+
it 'return issue url' do
139+
(Octokit::Client).stub(:new).with(
140+
login: options['username'], password: options['password']
141+
).and_return(fake_github_client)
142+
expect(subject).to eq fake_issue.html_url
143+
end
144+
end
145+
146+
context 'when unauthentication error' do
147+
let(:user) do
148+
{ 'github_login' => 'alice', 'github_oauth_token' => 'invalid_token' }
149+
end
150+
it 'raise AuthenticationError' do
151+
(Octokit::Client).stub(:new).with(
152+
login: user['github_login'], access_token: user['github_oauth_token']
153+
).and_raise(Octokit::Unauthorized)
154+
expect { subject }.to raise_error
155+
end
156+
end
157+
end
158+
end

Diff for: spec/spec_helper.rb

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
if ENV['COVERAGE']
2+
require 'simplecov'
3+
if ENV['CI']
4+
require 'coveralls'
5+
Coveralls.wear!
6+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7+
SimpleCov::Formatter::HTMLFormatter,
8+
Coveralls::SimpleCov::Formatter
9+
]
10+
end
11+
12+
SimpleCov.start
13+
end
14+
15+
require 'errbit_plugin'
16+
require 'errbit_github_plugin'
17+
require 'active_support/all'
18+
19+
RSpec.configure do |config|
20+
config.run_all_when_everything_filtered = true
21+
config.filter_run :focus
22+
23+
# Run specs in random order to surface order dependencies. If you find an
24+
# order dependency and want to debug it, you can fix the order by providing
25+
# the seed, which is printed after each run.
26+
# --seed 1234
27+
config.order = 'random'
28+
end

0 commit comments

Comments
 (0)