ey_rails_wizard 0.3.1

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.
Files changed (93) hide show
  1. data/.gitignore +8 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +6 -0
  4. data/ChangeLog.md +23 -0
  5. data/Gemfile +3 -0
  6. data/MIT_LICENSE +20 -0
  7. data/README.md +78 -0
  8. data/Rakefile +45 -0
  9. data/autotest/discover.rb +1 -0
  10. data/bin/ey_rails_wizard +7 -0
  11. data/ey_rails_wizard.gemspec +28 -0
  12. data/lib/rails_wizard/command.rb +79 -0
  13. data/lib/rails_wizard/config.rb +86 -0
  14. data/lib/rails_wizard/recipe.rb +106 -0
  15. data/lib/rails_wizard/recipes.rb +38 -0
  16. data/lib/rails_wizard/template.rb +67 -0
  17. data/lib/rails_wizard.rb +10 -0
  18. data/recipes/active_admin.rb +18 -0
  19. data/recipes/activerecord.rb +69 -0
  20. data/recipes/cancan.rb +16 -0
  21. data/recipes/capybara.rb +34 -0
  22. data/recipes/carrierwave.rb +42 -0
  23. data/recipes/carrierwave_direct.rb +13 -0
  24. data/recipes/cartographer.rb +33 -0
  25. data/recipes/cucumber.rb +17 -0
  26. data/recipes/delayed_job.rb +16 -0
  27. data/recipes/devise.rb +52 -0
  28. data/recipes/devise_invitable.rb +23 -0
  29. data/recipes/env_yaml.rb +53 -0
  30. data/recipes/event_calendar.rb +12 -0
  31. data/recipes/eycloud.rb +30 -0
  32. data/recipes/eycloud_recipes_on_deploy.rb +20 -0
  33. data/recipes/factory_girl.rb +38 -0
  34. data/recipes/ffaker.rb +22 -0
  35. data/recipes/fixture_builder.rb +35 -0
  36. data/recipes/forgery.rb +15 -0
  37. data/recipes/git.rb +15 -0
  38. data/recipes/haml.rb +11 -0
  39. data/recipes/heroku.rb +58 -0
  40. data/recipes/hoptoad.rb +34 -0
  41. data/recipes/inherited_resources.rb +12 -0
  42. data/recipes/jammit.rb +43 -0
  43. data/recipes/jasmine.rb +12 -0
  44. data/recipes/jquery.rb +20 -0
  45. data/recipes/mini_magick.rb +13 -0
  46. data/recipes/mongo_mapper.rb +20 -0
  47. data/recipes/mongohq.rb +61 -0
  48. data/recipes/mongoid.rb +20 -0
  49. data/recipes/mootools.rb +23 -0
  50. data/recipes/mysql.rb +19 -0
  51. data/recipes/nifty_generators.rb +21 -0
  52. data/recipes/oa_oauth.rb +12 -0
  53. data/recipes/omniauth.rb +17 -0
  54. data/recipes/paper_trail.rb +17 -0
  55. data/recipes/pow.rb +12 -0
  56. data/recipes/prototype.rb +11 -0
  57. data/recipes/puma.rb +10 -0
  58. data/recipes/rails_admin.rb +21 -0
  59. data/recipes/rails_basics.rb +45 -0
  60. data/recipes/rails_dev_tweaks.rb +10 -0
  61. data/recipes/rails_erd.rb +9 -0
  62. data/recipes/rails_footnotes.rb +14 -0
  63. data/recipes/ransack.rb +32 -0
  64. data/recipes/redis.rb +15 -0
  65. data/recipes/resque.rb +37 -0
  66. data/recipes/rmagick.rb +13 -0
  67. data/recipes/rspec.rb +21 -0
  68. data/recipes/sass.rb +13 -0
  69. data/recipes/sequel.rb +13 -0
  70. data/recipes/settingslogic.rb +43 -0
  71. data/recipes/shoulda_matchers.rb +11 -0
  72. data/recipes/simple_form.rb +19 -0
  73. data/recipes/slim.rb +11 -0
  74. data/recipes/sqlite3.rb +10 -0
  75. data/recipes/test_unit.rb +11 -0
  76. data/recipes/thin.rb +10 -0
  77. data/recipes/thinking_sphinx.rb +14 -0
  78. data/recipes/twitter_bootstrap_rails.rb +142 -0
  79. data/recipes/unicorn.rb +10 -0
  80. data/sample.rb +77 -0
  81. data/spec/rails_wizard/config_spec.rb +99 -0
  82. data/spec/rails_wizard/recipe_spec.rb +103 -0
  83. data/spec/rails_wizard/recipes/sanity_spec.rb +30 -0
  84. data/spec/rails_wizard/recipes_spec.rb +24 -0
  85. data/spec/rails_wizard/template_spec.rb +48 -0
  86. data/spec/spec_helper.rb +11 -0
  87. data/spec/support/rails_directory.rb +17 -0
  88. data/spec/support/template_runner.rb +28 -0
  89. data/templates/helpers.erb +45 -0
  90. data/templates/layout.erb +45 -0
  91. data/templates/recipe.erb +10 -0
  92. data/version.rb +3 -0
  93. metadata +232 -0
@@ -0,0 +1,19 @@
1
+ gem 'simple_form'
2
+
3
+ after_bundler do
4
+ if recipe? "twitter_bootstrap_rails"
5
+ generate "simple_form:install --bootstrap"
6
+ else
7
+ generate "simple_form:install"
8
+ end
9
+ end
10
+
11
+ __END__
12
+
13
+ name: Simple Form
14
+ description: Install Simple Form to generate nicely formatted forms.
15
+ author: jonochang
16
+
17
+ exclusive: forms
18
+ category: other
19
+ tags: [forms]
data/recipes/slim.rb ADDED
@@ -0,0 +1,11 @@
1
+ gem 'slim'
2
+ gem 'slim-rails'
3
+
4
+ __END__
5
+
6
+ name: Slim
7
+ description: "Use Slim as the default templating engine."
8
+ author: mbleigh
9
+
10
+ category: templating
11
+ exclusive: templating
@@ -0,0 +1,10 @@
1
+ gem "sqlite3", :group => [:development, :test]
2
+
3
+ __END__
4
+
5
+ name: Sqlite3
6
+ description: Use Sqlite3 for development and testing (not available for production)
7
+ author: drnic
8
+
9
+ category: persistence
10
+ tags: [sql, orm, mysql]
@@ -0,0 +1,11 @@
1
+ # No additional code required.
2
+
3
+ __END__
4
+
5
+ name: Test::Unit
6
+ description: "Utilize the default Rails test facilities."
7
+ author: mbleigh
8
+
9
+ exclusive: unit_testing
10
+ category: testing
11
+ tags: [defaults]
data/recipes/thin.rb ADDED
@@ -0,0 +1,10 @@
1
+ gem 'thin'
2
+
3
+ __END__
4
+
5
+ name: Thin
6
+ description: "A very fast & simple Ruby web server"
7
+ author: lightyrs
8
+
9
+ category: deployment
10
+ exclusive: appserver
@@ -0,0 +1,14 @@
1
+ gem 'thinking-sphinx', '>= 2.0.4', :require => 'thinking_sphinx'
2
+
3
+
4
+ __END__
5
+
6
+ name: Thinking Sphinx
7
+ description: "Include thinking sphinx to enable search"
8
+ author: porta
9
+ website: http://freelancing-god.github.com/ts/en/
10
+
11
+ category: search
12
+ tags: [thinking_sphinx, search]
13
+
14
+ requires: [thinking_sphinx]
@@ -0,0 +1,142 @@
1
+ gem 'twitter-bootstrap-rails', :git => 'https://github.com/jonochang/twitter-bootstrap-rails.git'
2
+
3
+ if config['use_simple_form']
4
+ after_everything do
5
+ gsub_file "config/initializers/simple_form.rb", '# config.label_text = lambda { |label, required| "#{required} #{label}" }', 'config.label_text = lambda { |label, required| "#{label} #{required}" }'
6
+
7
+ original_wrapper = <<-RB
8
+ config.wrappers :class => :input, :error_class => :field_with_errors do |b|
9
+ b.use :placeholder
10
+ b.use :label_input
11
+ b.use :hint, :tag => :span, :class => :hint
12
+ b.use :error, :tag => :span, :class => :error
13
+ end
14
+ RB
15
+ new_wrapper = <<-RB
16
+
17
+ config.wrappers :inline, :class => 'clearfix', :error_class => :error do |b|
18
+ b.use :placeholder
19
+ b.use :label
20
+ b.use :tag => 'div', :class => 'input' do |ba|
21
+ ba.use :input
22
+ ba.use :error, :tag => :span, :class => :'help-inline'
23
+ ba.use :hint, :tag => :span, :class => :'help-block'
24
+ end
25
+ end
26
+
27
+ config.wrappers :stacked, :class => "clearfix", :error_class => :error do |b|
28
+ b.use :placeholder
29
+ b.use :label
30
+ b.use :hint, :tag => :span, :class => :'help-block'
31
+ b.use :tag => 'div', :class => 'input' do |input|
32
+ input.use :input
33
+ input.use :error, :tag => :span, :class => :'help-inline'
34
+ end
35
+ end
36
+ RB
37
+ gsub_file "config/initializers/simple_form.rb", original_wrapper, new_wrapper
38
+ gsub_file "config/initializers/simple_form.rb", "# config.button_class = 'button'", "config.button_class = 'btn'"
39
+
40
+ application_layout_body = <<-ERB
41
+ <body>
42
+
43
+ <%= yield %>
44
+
45
+ </body>
46
+ ERB
47
+
48
+ application_layout_body_new = <<-ERB
49
+ <body>
50
+ <div class="topbar">
51
+ <div class="fill">
52
+ <div class="container">
53
+
54
+ <h3><%= link_to "TODO Logo", '/' %></h3>
55
+
56
+ <ul class="nav">
57
+ <li><%= link_to "Users", '/users' %></li>
58
+ </ul>
59
+
60
+ <% if not logged_in? %>
61
+
62
+ <ul class="nav secondary-nav">
63
+ </ul>
64
+
65
+ <% else %>
66
+
67
+ <ul class="nav secondary-nav">
68
+ <li class="menu">
69
+ <a class="menu" href="#">
70
+ <%= current_user.name %>
71
+ <i>(signed in with <%= current_user.provider.titleize %>)</i>
72
+ </a>
73
+ <ul class="menu-dropdown">
74
+ <li><%= link_to "My Questions", user_questions_path(current_user) %></li>
75
+ <li class="divider"></li>
76
+ <li><%= link_to "Sign out", signout_path %></li>
77
+ </ul>
78
+ </li>
79
+ </ul>
80
+
81
+ <% end %>
82
+
83
+
84
+ </div>
85
+ </div>
86
+ </div>
87
+
88
+ <div class="container">
89
+ <% if alert %>
90
+ <div class="alert-message error"><%= alert %></div>
91
+ <% end %>
92
+
93
+ <% if notice %>
94
+ <div class="alert-message info"><%= notice %></div>
95
+ <% end %>
96
+
97
+ <%= yield %>
98
+ </div>
99
+
100
+ </body>
101
+
102
+ ERB
103
+
104
+ gsub_file 'app/views/layouts/application.html.erb', application_layout_body, application_layout_body_new
105
+
106
+ end
107
+
108
+ create_file "app/assets/stylesheets/application.css.new", <<-CSS
109
+ /*
110
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
111
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
112
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
113
+ *= require_self
114
+ *= require_tree .
115
+ *= require bootstrap-1.3.0.min
116
+ */
117
+
118
+ label {
119
+ margin-right: 20px;
120
+ }
121
+ CSS
122
+
123
+ run 'mv app/assets/stylesheets/application.css.new app/assets/stylesheets/application.css'
124
+ end
125
+
126
+ __END__
127
+
128
+ name: Twitter Bootstrap Rails
129
+ description: Add Twitter Bootstrap CSS to project
130
+
131
+ category: stylesheet
132
+ exclusive: stylesheet
133
+ tags: [css, stylesheet]
134
+
135
+ run_after: [simple_form]
136
+ config:
137
+ - use_simple_form:
138
+ type: boolean
139
+ prompt: "Using Simple Form?"
140
+ if_recipe: simple_form
141
+
142
+
@@ -0,0 +1,10 @@
1
+ gem 'unicorn'
2
+
3
+ __END__
4
+
5
+ name: Unicorn
6
+ description: Rack HTTP server for fast clients and Unix
7
+ author: drnic
8
+
9
+ category: deployment
10
+ exclusive: appserver
data/sample.rb ADDED
@@ -0,0 +1,77 @@
1
+ # >---------------------------[ Install Command ]-----------------------------<
2
+ # rails new APP_NAME -m http://railswizard.local/b9755a02fbf7886df8b2.rb
3
+ # >---------------------------------------------------------------------------<
4
+ #
5
+ # _____ _ _ __ ___ _
6
+ # | __ \ (_) | \ \ / (_) | |
7
+ # | |__) |__ _ _| |___\ \ /\ / / _ ______ _ _ __ __| |
8
+ # | _ // _` | | / __|\ \/ \/ / | |_ / _` | '__/ _` |
9
+ # | | \ \ (_| | | \__ \ \ /\ / | |/ / (_| | | | (_| |
10
+ # |_| \_\__,_|_|_|___/ \/ \/ |_/___\__,_|_| \__,_|
11
+ #
12
+ # This template was generated by RailsWizard, the amazing and awesome Rails
13
+ # application template builder. Get started at http://railswizard.org
14
+ #
15
+ # ___________________________________________________________________________
16
+ # |/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/|
17
+ # | | |
18
+ # | Name: | b9755a02fbf7886df8b2 |
19
+ # | URL: | http://railswizard.local/b9755a02fbf7886df8b2.rb |
20
+ # | Updated: | March 12, 2011 at 21:47PM |
21
+ # | | |
22
+ # |\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\|
23
+ # ---------------------------------------------------------------------------
24
+
25
+ # >----------------------------[ Initial Setup ]------------------------------<
26
+
27
+ initializer 'generators.rb', <<-RUBY
28
+ Rails.application.config.generators do |g|
29
+ end
30
+ RUBY
31
+
32
+ recipes = ["activerecord", "devise", "prototype"]
33
+
34
+ def say_custom(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}" end
35
+ def say_recipe(name); say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..." end
36
+ def say_wizard(text); say_custom('wizard', text) end
37
+ def ask_wizard(question)
38
+ ask "\033[1m\033[30m\033[46m" + "prompt".rjust(10) + "\033[0m\033[36m" + " #{question}\033[0m"
39
+ end
40
+ def yes_wizard?(question)
41
+ answer = ask_wizard(question + " \033[33m(y/n)\033[0m")
42
+ case answer.downcase
43
+ when "yes", "y"
44
+ true
45
+ when "no", "n"
46
+ false
47
+ else
48
+ yes_wizard?(question)
49
+ end
50
+ end
51
+ def no_wizard?(question); !yes_wizard?(question) end
52
+ def multiple_choice(question, choices)
53
+ say_custom('question', question)
54
+ values = {}
55
+ choices.each_with_index do |choice,i|
56
+ values[(i + 1).to_s] = choice[1]
57
+ say_custom (i + 1).to_s + '.', choice[0]
58
+ end
59
+ answer = ask_wizard("Enter your selection:") while !values.keys.include?(answer)
60
+ values[answer]
61
+ end
62
+
63
+ @after_blocks = []
64
+ def after_bundler(&block); @after_blocks << block; end
65
+
66
+
67
+ say_wizard ask_wizard("What do you want to know?")
68
+ say_wizard yes_wizard?("Is there a god?")
69
+ say_wizard multiple_choice("What do you like?", [["Puppies","puppies"],["Kitties","kitties"]])
70
+
71
+ # >-----------------------------[ Run Bundler ]-------------------------------<
72
+
73
+ say_wizard "Running Bundler install. This will take a while."
74
+ run 'bundle install'
75
+ say_wizard "Running after Bundler callbacks."
76
+ @after_blocks.each{|b| b.call}
77
+
@@ -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
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ Bundler.setup
3
+ require 'rspec'
4
+
5
+ Dir[File.dirname(__FILE__) + '/support/*'].each{|path| require path}
6
+
7
+ require 'rails_wizard'
8
+
9
+ RSpec.configure do |config|
10
+
11
+ end
@@ -0,0 +1,17 @@
1
+ class RailsDirectory
2
+ def initialize(path)
3
+ @path = path
4
+ end
5
+
6
+ def file_path(path)
7
+ File.join(@path, path)
8
+ end
9
+
10
+ def has_file?(path)
11
+ File.exist?(file_path(path))
12
+ end
13
+
14
+ def [](path)
15
+ File.open(file_path(path)).read
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ class TemplateRunner
2
+ attr_reader :template, :config, :app_name, :dir, :rails_dir, :output
3
+ def initialize(template, config)
4
+ @template = template
5
+ @config = config
6
+ end
7
+
8
+ def run(app_name = 'rails_app')
9
+ @app_name = app_name
10
+ @dir = Dir.mktmpdir
11
+ @rails_dir = File.join(@dir, @app_name)
12
+ Dir.chrdir(@dir) do
13
+ template_file = File.open 'template.rb', 'w'
14
+ template_file.write
15
+ template_file.close
16
+ @output = `rails new #{@app_name} -m template.rb`
17
+ end
18
+ @output
19
+ end
20
+
21
+ def rails
22
+ RailsDirectory.new(@rails_dir)
23
+ end
24
+
25
+ def clean
26
+ FileUtils.remove_entry_secure @dir
27
+ end
28
+ end