rails_wizard 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +95 -0
- data/bin/rails_wizard +7 -0
- data/lib/rails_wizard.rb +10 -0
- data/lib/rails_wizard/command.rb +78 -0
- data/lib/rails_wizard/config.rb +86 -0
- data/lib/rails_wizard/recipe.rb +106 -0
- data/lib/rails_wizard/recipes.rb +38 -0
- data/lib/rails_wizard/template.rb +57 -0
- data/recipes/activerecord.rb +37 -0
- data/recipes/capybara.rb +34 -0
- data/recipes/cucumber.rb +16 -0
- data/recipes/devise.rb +23 -0
- data/recipes/git.rb +15 -0
- data/recipes/haml.rb +11 -0
- data/recipes/heroku.rb +58 -0
- data/recipes/hoptoad.rb +31 -0
- data/recipes/jammit.rb +43 -0
- data/recipes/jquery.rb +23 -0
- data/recipes/less.rb +12 -0
- data/recipes/mongo_mapper.rb +18 -0
- data/recipes/mongohq.rb +59 -0
- data/recipes/mongoid.rb +18 -0
- data/recipes/mootools.rb +23 -0
- data/recipes/omniauth.rb +15 -0
- data/recipes/prototype.rb +11 -0
- data/recipes/redis.rb +11 -0
- data/recipes/rightjs.rb +17 -0
- data/recipes/rspec.rb +21 -0
- data/recipes/sass.rb +13 -0
- data/recipes/sequel.rb +13 -0
- data/recipes/slim.rb +11 -0
- data/recipes/test_unit.rb +11 -0
- data/spec/rails_wizard/config_spec.rb +99 -0
- data/spec/rails_wizard/recipe_spec.rb +103 -0
- data/spec/rails_wizard/recipes/sanity_spec.rb +30 -0
- data/spec/rails_wizard/recipes_spec.rb +24 -0
- data/spec/rails_wizard/template_spec.rb +48 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/rails_directory.rb +17 -0
- data/spec/support/template_runner.rb +28 -0
- data/templates/helpers.erb +44 -0
- data/templates/layout.erb +42 -0
- data/templates/recipe.erb +9 -0
- data/version.rb +3 -0
- metadata +139 -0
data/recipes/omniauth.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
gem 'omniauth', '~> 0.2.0'
|
2
|
+
|
3
|
+
after_bundler do
|
4
|
+
file 'app/controllers/sessions_controller.rb', "class SessionsController < ApplicationController\n def callback\n auth # Do what you want with the auth hash!\n end\n\n def auth; request.env['omniauth.auth'] end\nend"
|
5
|
+
route "match '/auth/:provider/callback', :to => 'sessions#callback'"
|
6
|
+
end
|
7
|
+
|
8
|
+
__END__
|
9
|
+
|
10
|
+
name: OmniAuth
|
11
|
+
description: "A basic setup of OmniAuth with a SessionsController to handle the request and callback phases."
|
12
|
+
author: mbleigh
|
13
|
+
|
14
|
+
exclusive: authentication
|
15
|
+
category: authentication
|
data/recipes/redis.rb
ADDED
data/recipes/rightjs.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
gem 'right-rails'
|
2
|
+
|
3
|
+
after_bundler do
|
4
|
+
generate 'right_rails'
|
5
|
+
end
|
6
|
+
|
7
|
+
__END__
|
8
|
+
|
9
|
+
name: RightJS
|
10
|
+
description: "Use RightJS in place of Prototype for this application."
|
11
|
+
author: mbleigh
|
12
|
+
|
13
|
+
exclusive: javascript_framework
|
14
|
+
category: assets
|
15
|
+
tags: [javascript, framework]
|
16
|
+
|
17
|
+
args: ["-J"]
|
data/recipes/rspec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
gem 'rspec-rails', '>= 2.0.1', :group => [:development, :test]
|
2
|
+
|
3
|
+
inject_into_file "config/initializers/generators.rb", :after => "Rails.application.config.generators do |g|\n" do
|
4
|
+
" g.test_framework = :rspec\n"
|
5
|
+
end
|
6
|
+
|
7
|
+
after_bundler do
|
8
|
+
generate 'rspec:install'
|
9
|
+
end
|
10
|
+
|
11
|
+
__END__
|
12
|
+
|
13
|
+
name: RSpec
|
14
|
+
description: "Use RSpec for unit testing for this Rails app."
|
15
|
+
author: mbleigh
|
16
|
+
|
17
|
+
exclusive: unit_testing
|
18
|
+
category: testing
|
19
|
+
|
20
|
+
args: ["-T"]
|
21
|
+
|
data/recipes/sass.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
unless recipes.include? 'haml'
|
2
|
+
gem 'haml', '>= 3.0.0'
|
3
|
+
end
|
4
|
+
|
5
|
+
__END__
|
6
|
+
|
7
|
+
name: SASS
|
8
|
+
description: "Utilize SASS (through the HAML gem) for really awesome stylesheets!"
|
9
|
+
author: mbleigh
|
10
|
+
|
11
|
+
exclusive: css_replacement
|
12
|
+
category: assets
|
13
|
+
tags: [css]
|
data/recipes/sequel.rb
ADDED
data/recipes/slim.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsWizard::Config do
|
4
|
+
describe '#initialize' do
|
5
|
+
subject{ RailsWizard::Config.new(YAML.load(@schema)) }
|
6
|
+
it 'should add a question key for each key of the schema' do
|
7
|
+
@schema = <<-YAML
|
8
|
+
- test:
|
9
|
+
type: string
|
10
|
+
YAML
|
11
|
+
subject.questions.should be_key('test')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should instantiate the correct question type for each question' do
|
15
|
+
@schema = <<-YAML
|
16
|
+
- string:
|
17
|
+
type: string
|
18
|
+
- boolean:
|
19
|
+
type: boolean
|
20
|
+
- multiple_choice:
|
21
|
+
type: multiple_choice
|
22
|
+
YAML
|
23
|
+
subject.questions['string'].should be_kind_of(RailsWizard::Config::Prompt)
|
24
|
+
subject.questions['boolean'].should be_kind_of(RailsWizard::Config::TrueFalse)
|
25
|
+
subject.questions['multiple_choice'].should be_kind_of(RailsWizard::Config::MultipleChoice)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should error on invalid question type' do
|
29
|
+
@schema = <<-YAML
|
30
|
+
- invalid
|
31
|
+
type: invalid
|
32
|
+
YAML
|
33
|
+
lambda{ subject }.should raise_error(ArgumentError)
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#compile' do
|
37
|
+
let(:lines) { subject.compile.split("\n") }
|
38
|
+
before do
|
39
|
+
@schema = <<-YAML
|
40
|
+
- string:
|
41
|
+
type: string
|
42
|
+
prompt: Give me a string?
|
43
|
+
if: is_true
|
44
|
+
- boolean:
|
45
|
+
type: boolean
|
46
|
+
prompt: Yes or no?
|
47
|
+
unless: is_false
|
48
|
+
if_recipe: awesome
|
49
|
+
- multiple_choice:
|
50
|
+
type: multiple_choice
|
51
|
+
choices: [[ABC, abc], [DEF, def]]
|
52
|
+
unless_recipe: awesome
|
53
|
+
YAML
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should include all questions' do
|
57
|
+
lines.size.should == 4
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should handle "if"' do
|
61
|
+
lines[1].should be_include("config['is_true']")
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should handle "unless"' do
|
65
|
+
lines[2].should be_include("!config['is_false']")
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should handle "if_recipe"' do
|
69
|
+
lines[2].should be_include("recipe?('awesome')")
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should handle "unelss_recipe"' do
|
73
|
+
lines[3].should be_include("!recipe?('awesome')")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe RailsWizard::Config::Prompt do
|
78
|
+
subject{ RailsWizard::Config::Prompt }
|
79
|
+
it 'should compile to a prompt' do
|
80
|
+
subject.new({'prompt' => "What's your favorite color?"}).question.should == 'ask_wizard("What\'s your favorite color?")'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe RailsWizard::Config::TrueFalse do
|
85
|
+
subject{ RailsWizard::Config::TrueFalse }
|
86
|
+
it 'should compile to a yes? question' do
|
87
|
+
subject.new({'prompt' => 'Yes yes?'}).question.should == 'yes_wizard?("Yes yes?")'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe RailsWizard::Config::MultipleChoice do
|
92
|
+
subject{ RailsWizard::Config::MultipleChoice }
|
93
|
+
it 'should compile into a multiple_choice' do
|
94
|
+
subject.new({'prompt' => 'What kind of fruit?', 'choices' => [['Apples', 'apples'], ['Bananas', 'bananas']]}).question.should ==
|
95
|
+
'multiple_choice("What kind of fruit?", [["Apples", "apples"], ["Bananas", "bananas"]])'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsWizard::Recipe do
|
4
|
+
context "with a generated recipe" do
|
5
|
+
subject{ RailsWizard::Recipe.generate('recipe_example', "# this is a test", :category => 'example', :name => "RailsWizard Example") }
|
6
|
+
|
7
|
+
context 'string setter methods' do
|
8
|
+
(RailsWizard::Recipe::ATTRIBUTES - ['config']).each do |setter|
|
9
|
+
it "should be able to set #{setter} with an argument" do
|
10
|
+
subject.send(setter + '=', "test")
|
11
|
+
subject.send(setter).should == 'test'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should be able to get the value from the instance' do
|
15
|
+
subject.send(setter + '=', 'test')
|
16
|
+
subject.new.send(setter).should == subject.send(setter)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.attributes' do
|
22
|
+
it 'should be accessible from the instance' do
|
23
|
+
subject.new.attributes.should == subject.attributes
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.generate' do
|
28
|
+
it 'should work with a string and hash as arguments' do
|
29
|
+
recipe = RailsWizard::Recipe.generate('some_key', '# some code', :name => "Example")
|
30
|
+
recipe.superclass.should == RailsWizard::Recipe
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should work with an IO object' do
|
34
|
+
file = StringIO.new <<-RUBY
|
35
|
+
# this is an example
|
36
|
+
|
37
|
+
__END__
|
38
|
+
|
39
|
+
category: example
|
40
|
+
name: This is an Example
|
41
|
+
description: You know it's an exmaple.
|
42
|
+
RUBY
|
43
|
+
recipe = RailsWizard::Recipe.generate('just_a_test', file)
|
44
|
+
recipe.template.should == '# this is an example'
|
45
|
+
recipe.category.should == 'example'
|
46
|
+
recipe.name.should == 'This is an Example'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should raise an exception if the file is incorrectly formatted' do
|
50
|
+
file = StringIO.new <<-RUBY
|
51
|
+
# just ruby, no YAML
|
52
|
+
RUBY
|
53
|
+
lambda{RailsWizard::Recipe.generate('testing',file)}.should raise_error(ArgumentError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#compile' do
|
58
|
+
it 'should say the name' do
|
59
|
+
subject.name = "Awesome Sauce"
|
60
|
+
subject.new.compile.should be_include("say_recipe 'Awesome Sauce'")
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should include the template' do
|
64
|
+
subject.template = "This is only a test."
|
65
|
+
subject.new.compile.should be_include(subject.template)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should set default attributes' do
|
71
|
+
recipe = RailsWizard::Recipe.generate('abc','# test')
|
72
|
+
|
73
|
+
RailsWizard::Recipe::DEFAULT_ATTRIBUTES.each_pair do |k,v|
|
74
|
+
recipe.send(k).should == v
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'Comparable' do
|
79
|
+
subject{ RailsWizard::Recipe }
|
80
|
+
it 'a < b.run_after(a)' do
|
81
|
+
A = subject.generate('a', '#')
|
82
|
+
B = subject.generate('b', '#', :run_after => ['a'])
|
83
|
+
|
84
|
+
(A < B).should be_true
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'a > b.run_before(a)' do
|
88
|
+
A = subject.generate('a', '#')
|
89
|
+
B = subject.generate('b', '#', :run_before => ['a'])
|
90
|
+
|
91
|
+
(A > B).should be_true
|
92
|
+
end
|
93
|
+
|
94
|
+
after do
|
95
|
+
Object.send :remove_const, :A if defined?(A)
|
96
|
+
Object.send :remove_const, :B if defined?(B)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
__END__
|
102
|
+
|
103
|
+
this is a test
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# This is a simple set of tests to make sure that
|
4
|
+
# all of the recipes conform to the base requirements.
|
5
|
+
|
6
|
+
RailsWizard::Recipes.list_classes.each do |recipe|
|
7
|
+
describe recipe do
|
8
|
+
it("should have a name"){ recipe.name.should be_kind_of(String) }
|
9
|
+
it("should have a description"){ recipe.description.should be_kind_of(String) }
|
10
|
+
it("should have a template"){ recipe.template.should be_kind_of(String) }
|
11
|
+
it("should be able to compile"){ recipe.new.compile.should be_kind_of(String) }
|
12
|
+
|
13
|
+
it "should have a string or nil category" do
|
14
|
+
if recipe.category
|
15
|
+
recipe.category.should be_kind_of(String)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have a Config or nil config" do
|
20
|
+
if recipe.config
|
21
|
+
recipe.config.should be_kind_of(RailsWizard::Config)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be in the list" do
|
26
|
+
RailsWizard::Recipes.list_classes.should be_include(recipe)
|
27
|
+
RailsWizard::Recipes.list.should be_include(recipe.key)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsWizard::Recipes do
|
4
|
+
subject{ RailsWizard::Recipes }
|
5
|
+
let(:recipe){ RailsWizard::Recipe.generate("recipe_test", "# Testing", :name => "Test Recipe", :category => "test", :description => "Just a test.")}
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
RailsWizard::Recipes.add(recipe)
|
9
|
+
end
|
10
|
+
|
11
|
+
it '.list_classes should include recipe classes' do
|
12
|
+
subject.list_classes.should be_include(recipe)
|
13
|
+
end
|
14
|
+
|
15
|
+
it '.list should include recipe keys' do
|
16
|
+
subject.list.should be_include('recipe_test')
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '.for' do
|
20
|
+
it 'should find for a given category' do
|
21
|
+
RailsWizard::Recipes.for('test').should be_include('recipe_test')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsWizard::Template do
|
4
|
+
subject{ RailsWizard::Template }
|
5
|
+
let(:recipe){ RailsWizard::Recipe.generate('name','# test') }
|
6
|
+
|
7
|
+
describe '#initialize' do
|
8
|
+
it 'should work with classes' do
|
9
|
+
subject.new([recipe]).recipes.should == [recipe]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#recipes_with_dependencies' do
|
14
|
+
def r(*deps)
|
15
|
+
mock(:Class, :requires => deps, :superclass => RailsWizard::Recipe)
|
16
|
+
end
|
17
|
+
|
18
|
+
subject do
|
19
|
+
@template = RailsWizard::Template.new([])
|
20
|
+
@template.stub!(:recipes).and_return(@recipes)
|
21
|
+
@template.stub!(:recipe_classes).and_return(@recipes)
|
22
|
+
@template
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should return the same number recipes if none have dependencies' do
|
26
|
+
@recipes = [r, r]
|
27
|
+
subject.recipes_with_dependencies.size.should == 2
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should handle simple dependencies' do
|
31
|
+
@recipes = [r(r, r), r(r)]
|
32
|
+
subject.recipes_with_dependencies.size.should == 5
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should handle multi-level dependencies' do
|
36
|
+
@recipes = [r(r(r))]
|
37
|
+
subject.recipes_with_dependencies.size.should == 3
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should uniqify' do
|
41
|
+
a = r
|
42
|
+
b = r(a)
|
43
|
+
c = r(r, a, b)
|
44
|
+
@recipes = [a,b,c]
|
45
|
+
subject.recipes_with_dependencies.size.should == 4
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|