github-changelog-generator/spec/unit/fetcher_spec.rb

37 lines
1.3 KiB
Ruby
Raw Normal View History

2015-05-14 12:57:31 +00:00
describe GitHubChangelogGenerator::Fetcher do
2015-05-18 08:40:32 +00:00
VALID_TOKEN = "0123456789abcdef"
2015-05-14 12:57:31 +00:00
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
end