starting spec work

This commit is contained in:
John Bintz 2011-08-17 14:16:27 -04:00
parent b088152ea2
commit 6270393027
5 changed files with 69 additions and 2 deletions

View File

@ -7,4 +7,4 @@ gem 'guard'
gem 'guard-rspec'
gem 'mocha'
gem 'fakefs'
gem 'rspec', '~> 2.6.0'

View File

@ -1,3 +1,3 @@
module Penchant
# Your code goes here...
autoload :Gemfile, 'penchant/gemfile'
end

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,6 @@
require 'fakefs/spec_helpers'
require 'penchant'
RSpec.configure do |c|
c.mock_with :mocha
end