Skip to content
Prev Previous commit
Next Next commit
refactor specs
  • Loading branch information
jasonkarns committed Oct 31, 2014
commit 98103a5485be4c3c1ae18a3326ab6a814b3ea71b
47 changes: 22 additions & 25 deletions spec/auth_token_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,41 @@
stub_const("Gist::URL_ENV_NAME", "STUBBED_GITHUB_URL")
end

context "without custom GITHUB_URL" do
let(:expected_filename) { File.expand_path "~/.gist" }
describe "#filename" do
let(:filename) { double() }

describe "#filename" do
it "is stored in $HOME" do
subject.filename.should eq expected_filename
context "with default GITHUB_URL" do
it "is ~/.gist" do
File.should_receive(:expand_path).with("~/.gist").and_return(filename)
subject.filename.should be filename
end
end

describe "#read" do
let(:token) { "auth_token" }

it "reads file contents" do
File.should_receive(:read).with(expected_filename).and_return(token)
subject.read.should eq token
context "with custom GITHUB_URL" do
before do
ENV[Gist::URL_ENV_NAME] = github_url
end
let(:github_url) { "gh.custom.org" }

it "chomps file contents" do
File.should_receive(:read).with(expected_filename).and_return(token + "\n")
subject.read.should eq token
it "is ~/.gist.{custom_github_url}" do
File.should_receive(:expand_path).with("~/.gist.#{github_url}").and_return(filename)
subject.filename.should be filename
end
end

end

context "with custom GITHUB_URL" do
let(:github_url) { "gh.custom.org" }
let(:expected_filename) { File.expand_path "~/.gist.#{github_url}" }
describe "#read" do
let(:token) { "auth_token" }

before do
ENV[Gist::URL_ENV_NAME] = github_url
it "reads file contents" do
File.should_receive(:read).and_return(token)
subject.read.should eq token
end

describe "#filename" do
it "is stored in $HOME" do
subject.filename.should eq expected_filename
end
it "chomps file contents" do
File.should_receive(:read).and_return(token + "\n")
subject.read.should eq token
end

end

end