2016-09-22 17:04:35 +00:00
|
|
|
# frozen_string_literal: true
|
2016-02-23 15:06:55 +00:00
|
|
|
VALID_TOKEN = "0123456789abcdef"
|
|
|
|
INVALID_TOKEN = "0000000000000000"
|
2015-05-18 13:55:49 +00:00
|
|
|
|
|
|
|
DEFAULT_OPTIONS = { user: "skywinder",
|
2016-02-23 15:06:55 +00:00
|
|
|
project: "changelog_test" }
|
2015-05-18 13:55:49 +00:00
|
|
|
|
|
|
|
def options_with_invalid_token
|
|
|
|
options = DEFAULT_OPTIONS
|
|
|
|
options[:token] = INVALID_TOKEN
|
|
|
|
options
|
|
|
|
end
|
|
|
|
|
2015-05-14 12:57:31 +00:00
|
|
|
describe GitHubChangelogGenerator::Fetcher do
|
|
|
|
before(:all) do
|
|
|
|
@fetcher = GitHubChangelogGenerator::Fetcher.new
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#fetch_github_token" do
|
|
|
|
token = GitHubChangelogGenerator::Fetcher::CHANGELOG_GITHUB_TOKEN
|
|
|
|
context "when token in ENV exist" do
|
2015-05-18 08:40:32 +00:00
|
|
|
before { stub_const("ENV", ENV.to_hash.merge(token => VALID_TOKEN)) }
|
2015-05-14 12:57:31 +00:00
|
|
|
subject { @fetcher.fetch_github_token }
|
2015-05-18 08:40:32 +00:00
|
|
|
it { is_expected.to eq(VALID_TOKEN) }
|
2015-05-14 12:57:31 +00:00
|
|
|
end
|
|
|
|
context "when token in ENV is nil" do
|
|
|
|
before { stub_const("ENV", ENV.to_hash.merge(token => nil)) }
|
|
|
|
subject { @fetcher.fetch_github_token }
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
2015-05-18 08:40:32 +00:00
|
|
|
context "when token in options and ENV is nil" do
|
|
|
|
before do
|
|
|
|
stub_const("ENV", ENV.to_hash.merge(token => nil))
|
|
|
|
@fetcher = GitHubChangelogGenerator::Fetcher.new(token: VALID_TOKEN)
|
|
|
|
end
|
|
|
|
subject { @fetcher.fetch_github_token }
|
|
|
|
it { is_expected.to eq(VALID_TOKEN) }
|
|
|
|
end
|
|
|
|
context "when token in options and ENV specified" do
|
|
|
|
before do
|
|
|
|
stub_const("ENV", ENV.to_hash.merge(token => "no_matter_what"))
|
|
|
|
@fetcher = GitHubChangelogGenerator::Fetcher.new(token: VALID_TOKEN)
|
|
|
|
end
|
|
|
|
subject { @fetcher.fetch_github_token }
|
|
|
|
it { is_expected.to eq(VALID_TOKEN) }
|
|
|
|
end
|
2015-05-14 12:57:31 +00:00
|
|
|
end
|
2015-05-18 13:55:49 +00:00
|
|
|
|
|
|
|
describe "#github_fetch_tags" do
|
|
|
|
context "when wrong token provided" do
|
|
|
|
before do
|
|
|
|
options = options_with_invalid_token
|
|
|
|
@fetcher = GitHubChangelogGenerator::Fetcher.new(options)
|
|
|
|
end
|
|
|
|
it "should raise Unauthorized error" do
|
2015-06-10 11:18:15 +00:00
|
|
|
expect { @fetcher.github_fetch_tags }.to raise_error Github::Error::Unauthorized
|
2015-05-18 13:55:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-05-14 12:57:31 +00:00
|
|
|
end
|