From 6270393027bced56a5fa7f878fbcbdccb31d4d4b Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 17 Aug 2011 14:16:27 -0400 Subject: [PATCH] starting spec work --- Gemfile | 2 +- lib/penchant.rb | 2 +- lib/penchant/gemfile.rb | 23 +++++++++++++++++++ spec/lib/penchant/gemfile_spec.rb | 38 +++++++++++++++++++++++++++++++ spec/spec_helper.rb | 6 +++++ 5 files changed, 69 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 98c4a37..aebb6ed 100644 --- a/Gemfile +++ b/Gemfile @@ -7,4 +7,4 @@ gem 'guard' gem 'guard-rspec' gem 'mocha' gem 'fakefs' - +gem 'rspec', '~> 2.6.0' diff --git a/lib/penchant.rb b/lib/penchant.rb index aa2748b..0dfcd5d 100644 --- a/lib/penchant.rb +++ b/lib/penchant.rb @@ -1,3 +1,3 @@ module Penchant - # Your code goes here... + autoload :Gemfile, 'penchant/gemfile' end diff --git a/lib/penchant/gemfile.rb b/lib/penchant/gemfile.rb index e69de29..e7ba2e9 100644 --- a/lib/penchant/gemfile.rb +++ b/lib/penchant/gemfile.rb @@ -0,0 +1,23 @@ +module Penchant + class Gemfile + attr_reader :path + + def initialize(path) + @path = path + end + + def has_gemfile? + has_file_in_path?('Gemfile') + end + + def has_gemfile_erb? + has_file_in_path?('Gemfile.erb') + end + + private + def has_file_in_path?(file) + File.file?(File.join(@path, file)) + end + end +end + diff --git a/spec/lib/penchant/gemfile_spec.rb b/spec/lib/penchant/gemfile_spec.rb index cfb9521..67bff59 100644 --- a/spec/lib/penchant/gemfile_spec.rb +++ b/spec/lib/penchant/gemfile_spec.rb @@ -1,6 +1,44 @@ require 'spec_helper' describe Penchant::Gemfile do + include FakeFS::SpecHelpers + let(:dir) { File.expand_path(Dir.pwd) } + let(:gemfile) { described_class.new(dir) } + + let(:gemfile_path) { File.join(dir, 'Gemfile') } + let(:gemfile_erb_path) { File.join(dir, 'Gemfile.erb') } + + def write_file(path, content = nil) + File.open(path, 'wb') do |fh| + content = yield if block_given? + fh.print content + end + end + + subject { gemfile } + + context 'with no gemfile' do + it { should_not have_gemfile } + it { should_not have_gemfile_erb } + end + + context 'with gemfile' do + before do + write_file(gemfile_path) { "whatever" } + end + + it { should have_gemfile } + it { should_not have_gemfile_erb } + end + + context 'with gemfile.erb' do + before do + write_file(gemfile_erb_path) { "whatever" } + end + + it { should_not have_gemfile } + it { should have_gemfile_erb } + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e69de29..c9de50a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -0,0 +1,6 @@ +require 'fakefs/spec_helpers' +require 'penchant' + +RSpec.configure do |c| + c.mock_with :mocha +end