Skip to content

Commit abe1ffb

Browse files
author
Arthur Nogueira Neves
committed
Merge pull request #6 from tjnet/3_add_basic_test
add basic tests
2 parents cbcbc98 + 60aa796 commit abe1ffb

File tree

4 files changed

+190
-0
lines changed

4 files changed

+190
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
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

.rspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--color
2+
--format documentation
3+
--require spec_helper

spec/issue_tracker_spec.rb

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

spec/spec_helper.rb

Lines changed: 28 additions & 0 deletions
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)