Skip to content

Commit

Permalink
Add specs to project
Browse files Browse the repository at this point in the history
  • Loading branch information
kfaustino committed Jan 24, 2011
1 parent 2bca36c commit a667f7a
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Gemfile.lock
pkg/*
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--colour
--format documentation
--fail-fast
5 changes: 5 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
require 'bundler'
Bundler::GemHelper.install_tasks

require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
end
Empty file modified bin/templater
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion lib/rails_templater.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'active_support'
require 'active_support/core_ext/string'

module RailsTemplater
extend self
Expand Down
3 changes: 1 addition & 2 deletions lib/rails_templater/templater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ class Templater
attr_accessor :post_bundler_strategies
attr_reader :template_options

def initialize(generator)
@generator = generator
def initialize
@post_bundler_strategies = []
@template_options = {}
@template_framework_path = File.join(File.dirname(__FILE__), '..', 'template_framework')
Expand Down
2 changes: 1 addition & 1 deletion lib/template_framework/core_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Generators
module Actions

def templater
@templater ||= RailsTemplater::Templater.new(self)
@templater ||= RailsTemplater::Templater.new
end

def execute_post_bundler_strategies
Expand Down
2 changes: 2 additions & 0 deletions rails_templater.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ Gem::Specification.new do |s|
s.require_path = 'lib'

s.add_dependency("thor", ["~> 0.14.6"])

s.add_development_dependency("rspec", ["~> 2.4"])
end
1 change: 1 addition & 0 deletions spec/fixtures/sample_snippet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Foo Bar
Empty file.
47 changes: 47 additions & 0 deletions spec/rails_templater/templater_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'spec_helper'

describe RailsTemplater::Templater do

let(:group) { 'sample' }

it "generates a recipe path based on a name" do
subject.recipe("mongoid").should == File.expand_path('recipes/mongoid.rb', TEMPLATE_FRAMEWORK_PATH)
end

it "generates a snippet path" do
subject.snippet_path("cucumber").should == File.expand_path('snippets/cucumber', TEMPLATE_FRAMEWORK_PATH)
end

it "generates a template path" do
subject.template_path("haml").should == File.expand_path('templates/haml', TEMPLATE_FRAMEWORK_PATH)
end

describe "#load_snippet" do

let(:snippet_name) { 'sample_snippet' }

before(:each) do
subject.stub(:snippet_path) { FIXTURE_PATH }
end

it "loads a snippet" do
subject.load_snippet(snippet_name, group).should == load_fixture(snippet_name)
end

end

describe "#load_template" do

let(:template_name) { 'sample_template.rb' }

before(:each) do
subject.stub(:template_path) { FIXTURE_PATH }
end

it "loads a template" do
subject.load_template(template_name, group).should == load_fixture(template_name)
end

end

end
9 changes: 9 additions & 0 deletions spec/rails_templater_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

describe RailsTemplater do

subject { RailsTemplater }

its(:template_runner) { should == File.expand_path('template_runner.rb', TEMPLATE_FRAMEWORK_PATH)}

end
20 changes: 20 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
begin
require 'bundler'
Bundler.setup(:default, :development)
rescue LoadError => e
# Fall back on doing an unlocked resolve at runtime.
STDERR.puts e.message
STDERR.puts "Try running `bundle install`."
exit!
end

require 'rails_templater'
require 'rspec'

# # Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir[File.join(File.dirname(__FILE__),'/support/**/*.rb')].each {|f| require f}

RSpec.configure do |config|
config.mock_with :rspec
end
5 changes: 5 additions & 0 deletions spec/support/fixtures.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FIXTURE_PATH = File.join(File.dirname(__FILE__), '..', 'fixtures')

def load_fixture(name)
File.read File.expand_path(name, FIXTURE_PATH)
end
1 change: 1 addition & 0 deletions spec/support/paths.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TEMPLATE_FRAMEWORK_PATH = File.join(File.dirname(__FILE__), '..', '..','lib', 'template_framework')

0 comments on commit a667f7a

Please sign in to comment.