Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
Add remaining unit tests for configure
Browse files Browse the repository at this point in the history
  • Loading branch information
mfinelli committed Nov 5, 2015
1 parent 872924a commit dbab84f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/fixtures/configuration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
:name: Mario Finelli
:email: mario@example.com
:pkgdir: "/tmp/aur-packages"
45 changes: 45 additions & 0 deletions spec/gembuild_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,50 @@
expect(Gembuild.configure).to eql({name: 'Mario Finelli', email: 'mario@example.com', pkgdir: '/tmp/packages'})
end
end

context 'with no existing configuration' do
it 'should ask the user name' do
allow(File).to receive(:file?).and_return(false)
allow(Gembuild).to receive(:fetch_git_global_email)
allow(Gembuild).to receive(:fetch_pkgdir)
expect(Gembuild).to receive(:fetch_git_global_name)
Gembuild.configure
end

it 'should ask the user email' do
allow(File).to receive(:file?).and_return(false)
allow(Gembuild).to receive(:fetch_git_global_name)
allow(Gembuild).to receive(:fetch_pkgdir)
expect(Gembuild).to receive(:fetch_git_global_email)
Gembuild.configure
end

it 'should ask the user where to store directories' do
allow(File).to receive(:file?).and_return(false)
allow(Gembuild).to receive(:fetch_git_global_name)
allow(Gembuild).to receive(:fetch_git_global_email)
expect(Gembuild).to receive(:fetch_pkgdir)
Gembuild.configure
end

it 'should write a new configuration file' do
allow(File).to receive(:file?).and_return(false)
allow(Gembuild).to receive(:fetch_git_global_name).and_return('Mario Finelli')
allow(Gembuild).to receive(:fetch_git_global_email).and_return('mario@example.com')
allow(Gembuild).to receive(:fetch_pkgdir).and_return('/tmp/aur-packages')
expect(File).to receive(:write).with(Gembuild.conf_file, File.read(File.join(File.dirname(__FILE__), 'fixtures', 'configuration.yml')))
Gembuild.configure
end

it 'should return the correct configuration' do
allow(File).to receive(:file?).and_return(false)
allow(Gembuild).to receive(:fetch_git_global_name).and_return('Mario Finelli')
allow(Gembuild).to receive(:fetch_git_global_email).and_return('mario@example.com')
allow(Gembuild).to receive(:fetch_pkgdir).and_return('/tmp/aur-packages')
allow(File).to receive(:write)
allow(YAML).to receive(:load_file).and_return(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'configuration.yml')))
expect(Gembuild.configure).to eql(YAML.load_file(File.join(File.dirname(__FILE__), 'fixtures', 'configuration.yml')))
end
end
end
end

0 comments on commit dbab84f

Please sign in to comment.