start of spec work

This commit is contained in:
John Bintz 2011-08-18 12:50:14 -04:00
parent 6270393027
commit 8fac9351ce
3 changed files with 39 additions and 8 deletions

View File

@ -1,7 +1,7 @@
# A sample Guardfile # A sample Guardfile
# More info at https://github.com/guard/guard#readme # More info at https://github.com/guard/guard#readme
guard 'rspec', :version => 2 do guard 'rspec', :cli => '-c', :version => 2 do
watch(%r{^spec/.+_spec\.rb$}) watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" } watch('spec/spec_helper.rb') { "spec" }

View File

@ -6,17 +6,29 @@ module Penchant
@path = path @path = path
end end
def gemfile_path
file_in_path('Gemfile')
end
def has_gemfile? def has_gemfile?
has_file_in_path?('Gemfile') File.file?('Gemfile')
end
def gemfile_erb_path
file_in_path('Gemfile.erb')
end end
def has_gemfile_erb? def has_gemfile_erb?
has_file_in_path?('Gemfile.erb') File.file?(gemfile_erb_path)
end
def environment
File.readlines(gemfile_path).first.strip[%r{environment: (.*)}, 1]
end end
private private
def has_file_in_path?(file) def file_in_path(file)
File.file?(File.join(@path, file)) File.join(@path, file)
end end
end end
end end

View File

@ -24,14 +24,33 @@ describe Penchant::Gemfile do
end end
context 'with gemfile' do context 'with gemfile' do
let(:data) { "whatever" }
before do before do
write_file(gemfile_path) { "whatever" } write_file(gemfile_path) { data }
end end
describe 'existence' do
it { should have_gemfile } it { should have_gemfile }
it { should_not have_gemfile_erb } it { should_not have_gemfile_erb }
end end
describe '#environment' do
context 'not defined' do
its(:environment) { should be_nil }
end
context 'defined' do
let(:environment) { 'test' }
let(:data) { <<-GEMFILE }
# generated by penchant, environment: #{environment}
GEMFILE
its(:environment) { should == environment }
end
end
end
context 'with gemfile.erb' do context 'with gemfile.erb' do
before do before do
write_file(gemfile_erb_path) { "whatever" } write_file(gemfile_erb_path) { "whatever" }