From 50ba2695fbf64753e9ba8be6cff05ab4e162c8b4 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 18 May 2015 11:40:32 +0300 Subject: [PATCH] add test for token in options --- spec/unit/fetcher_spec.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/spec/unit/fetcher_spec.rb b/spec/unit/fetcher_spec.rb index 6c08d25..709563f 100644 --- a/spec/unit/fetcher_spec.rb +++ b/spec/unit/fetcher_spec.rb @@ -1,4 +1,5 @@ describe GitHubChangelogGenerator::Fetcher do + VALID_TOKEN = "0123456789abcdef" before(:all) do @fetcher = GitHubChangelogGenerator::Fetcher.new end @@ -6,14 +7,30 @@ describe GitHubChangelogGenerator::Fetcher do 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")) } + before { stub_const("ENV", ENV.to_hash.merge(token => VALID_TOKEN)) } subject { @fetcher.fetch_github_token } - it { is_expected.to eq("0123456789abcdef") } + it { is_expected.to eq(VALID_TOKEN) } 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 + 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 end end