add tests for fetching token
This commit is contained in:
parent
c67cbb31f2
commit
7b356bf01a
|
@ -8,6 +8,7 @@ module GitHubChangelogGenerator
|
|||
# fetcher = GitHubChangelogGenerator::Fetcher.new options
|
||||
class Fetcher
|
||||
PER_PAGE_NUMBER = 30
|
||||
CHANGELOG_GITHUB_TOKEN = "CHANGELOG_GITHUB_TOKEN"
|
||||
GH_RATE_LIMIT_EXCEEDED_MSG = "Warning: GitHub API rate limit (5000 per hour) exceeded, change log may be " \
|
||||
"missing some issues. You can limit the number of issues fetched using the `--max-issues NUM` argument."
|
||||
|
||||
|
@ -40,7 +41,7 @@ module GitHubChangelogGenerator
|
|||
#
|
||||
# @return [String]
|
||||
def fetch_github_token
|
||||
env_var = @options[:token] ? @options[:token] : (ENV.fetch "CHANGELOG_GITHUB_TOKEN", nil)
|
||||
env_var = @options[:token] ? @options[:token] : (ENV.fetch CHANGELOG_GITHUB_TOKEN, nil)
|
||||
|
||||
unless env_var
|
||||
@logger.warn "Warning: No token provided (-t option) and variable $CHANGELOG_GITHUB_TOKEN was not found.".yellow
|
||||
|
|
19
spec/unit/fetcher_spec.rb
Normal file
19
spec/unit/fetcher_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
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
|
||||
before { stub_const("ENV", ENV.to_hash.merge(token => "0123456789abcdef")) }
|
||||
subject { @fetcher.fetch_github_token }
|
||||
it { is_expected.to eq("0123456789abcdef") }
|
||||
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
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user