sinatra-gen 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ == 0.4.1
2
+
3
+ * Cucumber support with --integration_framework=cucumber [Thanks Rob Holland]
4
+ * Explicitly set RACK_ENV in the test helper
5
+
1
6
  == 0.4.0 2009-08-13
2
7
 
3
8
  * Unless --tiny is specified generate an app that < Sinatra::Application
@@ -18,16 +18,17 @@ class SinatraAppGenerator < RubiGen::Base
18
18
 
19
19
  default_options :author => nil
20
20
 
21
- attr_accessor :app_name,
22
- :vendor,
23
- :tiny,
24
- :git,
25
- :git_init,
26
- :heroku,
27
- :test_framework,
28
- :view_framework,
29
- :install_scripts,
30
- :cap,
21
+ attr_accessor :app_name,
22
+ :vendor,
23
+ :tiny,
24
+ :git,
25
+ :git_init,
26
+ :heroku,
27
+ :test_framework,
28
+ :integration_framework,
29
+ :view_framework,
30
+ :install_scripts,
31
+ :cap,
31
32
  :actions,
32
33
  :middleware,
33
34
  :bin_name
@@ -45,26 +46,34 @@ class SinatraAppGenerator < RubiGen::Base
45
46
  record do |m|
46
47
  # Ensure appropriate folder(s) exists
47
48
  m.directory ''
48
-
49
+
49
50
  if git_init
50
51
  m.run("#{git} init")
51
- end
52
+ end
52
53
 
53
54
  m.template 'config.ru.erb', 'config.ru'
54
55
  m.template 'Rakefile.erb' , 'Rakefile'
55
-
56
+
56
57
  test_dir = (tests_are_specs? ? 'spec' : 'test')
57
-
58
+
58
59
  unless tiny
59
60
  BASEDIRS.each { |path| m.directory path }
60
61
  m.directory test_dir
61
62
  m.file 'config.yml', 'config.yml'
62
63
  m.template 'lib/app.rb.erb', "lib/#{app_name}.rb"
63
64
  m.template 'test/test_helper.rb.erb', "#{test_dir}/#{test_dir}_helper.rb"
64
- m.template "test/test_app_#{test_framework}.rb.erb",
65
+ m.template "test/test_app_#{test_framework}.rb.erb",
65
66
  "#{test_dir}/#{(tests_are_specs? ? "#{app_name}_spec" : "test_#{app_name}")}.rb"
66
67
  m.template "views/#{view_framework}_index.erb", "views/index.#{view_framework}"
67
68
  m.template "views/#{view_framework}_layout.erb", "views/layout.#{view_framework}" unless view_framework == 'builder'
69
+
70
+ case options[:integration_framework]
71
+ when 'cucumber'
72
+ m.directory 'features'
73
+ m.directory 'features/support'
74
+ m.template 'features/support/env.rb.erb', 'features/support/env.rb'
75
+ m.directory 'features/step_definitions'
76
+ end
68
77
  else
69
78
  m.template "lib/app.rb.erb", "#{app_name}.rb"
70
79
  end
@@ -78,7 +87,7 @@ class SinatraAppGenerator < RubiGen::Base
78
87
  m.directory 'vendor'
79
88
  if git_init || File.exists?(File.join(@destination_root, '.git'))
80
89
  command = "#{git} submodule add #{SINATRA_GIT_URL} vendor/sinatra"
81
- else
90
+ else
82
91
  command = "#{git} clone #{SINATRA_GIT_URL} vendor/sinatra"
83
92
  end
84
93
  m.run(command)
@@ -93,11 +102,12 @@ class SinatraAppGenerator < RubiGen::Base
93
102
  if install_scripts
94
103
  m.dependency "install_rubigen_scripts", [destination_root, 'sinatra-gen'], :shebang => options[:shebang], :collision => :force
95
104
  end
96
-
105
+
97
106
  if heroku
107
+ m.template 'dot_gems', '.gems'
98
108
  m.run("#{heroku} create #{app_name}")
99
109
  end
100
-
110
+
101
111
  end
102
112
  end
103
113
 
@@ -123,6 +133,7 @@ class SinatraAppGenerator < RubiGen::Base
123
133
  opts.on("--scripts", "Install the rubigen scripts (script/generate, script/destroy)") {|o| options[:scripts] = o }
124
134
  opts.on("--git /path/to/git", "Specify a different path for 'git'") {|o| options[:git] = o }
125
135
  opts.on("--test=test_framework", String, "Specify your testing framework (bacon (default)/rspec/spec/shoulda/test)") {|o| options[:test_framework] = o }
136
+ opts.on("--integration=integration_framework", String, "Specify your integration framework (cucumber)") {|o| options[:integration_framework] = o }
126
137
  opts.on("--views=view_framework", "Specify your view framework (haml (default)/erb/builder)") {|o| options[:view_framework] = o }
127
138
  opts.on("--middleware=rack-middleware", Array, "Specify Rack Middleware to be required and included (comma delimited)") {|o| options[:middleware] = o }
128
139
  opts.on("--vegas=[bin_name]", "--bin=[bin_name]", "Create an executable bin using Vegas. Pass an optional bin_name") {|o| options[:bin] = true; options[:bin_name] = o }
@@ -132,21 +143,22 @@ class SinatraAppGenerator < RubiGen::Base
132
143
  # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
133
144
  # Templates can access these value via the attr_reader-generated methods, but not the
134
145
  # raw instance variable value.
135
- self.vendor = options[:vendor]
136
- self.tiny = options[:tiny]
137
- self.cap = options[:cap]
138
- self.git = options[:git] || `which git`.strip
139
- self.heroku = options[:heroku] ? `which heroku`.strip : false
140
- self.git_init = options[:init] || !!heroku || false
141
- self.test_framework = options[:test_framework] || 'bacon'
142
- self.view_framework = options[:view_framework] || 'haml'
143
- self.install_scripts = options[:scripts] || false
144
- self.middleware = options[:middleware] ? options[:middleware].reject {|m| m.blank? } : []
145
- self.bin_name = options[:bin_name] || app_name
146
+ self.vendor = options[:vendor]
147
+ self.tiny = options[:tiny]
148
+ self.cap = options[:cap]
149
+ self.git = options[:git] || `which git`.strip
150
+ self.heroku = options[:heroku] ? `which heroku`.strip : false
151
+ self.git_init = options[:init] || !!heroku || false
152
+ self.test_framework = options[:test_framework] || 'bacon'
153
+ self.integration_framework = options[:integration_framework]
154
+ self.view_framework = options[:view_framework] || 'haml'
155
+ self.install_scripts = options[:scripts] || false
156
+ self.middleware = options[:middleware] ? options[:middleware].reject {|m| m.blank? } : []
157
+ self.bin_name = options[:bin_name] || app_name
146
158
  end
147
159
 
148
160
  def klass_name
149
- app_name.classify
161
+ app_name.tr('.','_').classify
150
162
  end
151
163
 
152
164
  def app_klass
@@ -156,7 +168,7 @@ class SinatraAppGenerator < RubiGen::Base
156
168
  def parse_actions(*action_args)
157
169
  @actions = action_args.flatten.collect { |a| a.split(':', 2) }
158
170
  end
159
-
171
+
160
172
  def tests_are_specs?
161
173
  ['rspec','spec','bacon'].include?(test_framework)
162
174
  end
@@ -33,8 +33,8 @@ end
33
33
 
34
34
  <%- else -%>
35
35
  class <%= klass_name -%> < Sinatra::Application
36
-
37
- set :root, APP_ROOT
36
+
37
+ set :root, APP_ROOT
38
38
  <%- middleware.each do |m| -%>
39
39
  use <%= m.to_s.classify %>
40
40
  <%- end -%>
@@ -3,18 +3,17 @@ require 'spec_helper'
3
3
  describe '<%= klass_name %>' do
4
4
 
5
5
  <%- unless actions.empty? -%>
6
- <% actions.each do |meth, path| %>
6
+ <% actions.each do |meth, path| %>
7
7
  it 'should <%= meth %> <%= path %>' do
8
8
  <%= meth %> '<%= path %>'
9
9
  last_response.should.be.ok
10
10
  end
11
-
11
+
12
12
  <%- end -%>
13
- <%- else -%>
13
+ <%- else -%>
14
14
  it 'should load the index' do
15
15
  get '/'
16
16
  last_response.should.be.ok
17
17
  end
18
18
  <%- end -%>
19
19
  end
20
-
@@ -3,14 +3,14 @@ require 'spec_helper'
3
3
  describe '<%= klass_name %>' do
4
4
 
5
5
  <%- unless actions.empty? -%>
6
- <% actions.each do |meth, path| %>
6
+ <% actions.each do |meth, path| %>
7
7
  it 'should <%= meth %> <%= path %>' do
8
8
  <%= meth %> '<%= path %>'
9
9
  last_response.should be_ok
10
10
  end
11
-
11
+
12
12
  <%- end -%>
13
- <%- else -%>
13
+ <%- else -%>
14
14
  it 'should load the index' do
15
15
  get '/'
16
16
  last_response.should be_ok
@@ -9,19 +9,19 @@ class <%= klass_name -%>Test < Test::Unit::TestCase
9
9
  setup do
10
10
  <%= meth %> '<%= path %>'
11
11
  end
12
-
12
+
13
13
  should "respond" do
14
14
  assert body
15
15
  end
16
16
  end
17
-
17
+
18
18
  <%- end -%>
19
19
  <%- else -%>
20
20
  context "getting the index" do
21
21
  setup do
22
22
  get '/'
23
23
  end
24
-
24
+
25
25
  should "respond" do
26
26
  assert body
27
27
  end
@@ -1,20 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe '<%= klass_name %>' do
4
-
4
+
5
5
  <%- unless actions.empty? -%>
6
- <% actions.each do |meth, path| %>
6
+ <% actions.each do |meth, path| %>
7
7
  it 'should <%= meth %> <%= path %>' do
8
8
  <%= meth %> '<%= path %>'
9
9
  last_response.should.be.ok
10
10
  end
11
-
11
+
12
12
  <%- end -%>
13
- <%- else -%>
13
+ <%- else -%>
14
14
  it 'should load the index' do
15
15
  get '/'
16
- last_response.should.be.ok
16
+ last_response.should.be.ok
17
17
  end
18
+
18
19
  <%- end -%>
19
-
20
20
  end
@@ -3,13 +3,13 @@ require 'test_helper'
3
3
  class <%= klass_name -%>Test < Test::Unit::TestCase
4
4
 
5
5
  <%- unless actions.empty? -%>
6
- <% actions.each do |meth, path| %>
6
+ <% actions.each do |meth, path| %>
7
7
  def test_<%= meth %>_<%= path.to_s.gsub(/[^a-z0-9\_]/, '') %>_should
8
8
  <%= meth %> '<%= path %>'
9
9
  end
10
10
 
11
11
  <%- end -%>
12
- <%- else -%>
12
+ <%- else -%>
13
13
  def test_my_default
14
14
  get '/'
15
15
  end
@@ -4,6 +4,10 @@ $:.unshift File.join(File.dirname(__FILE__), '..', 'vendor', 'sinatra', 'lib')
4
4
  require 'sinatra'
5
5
  require 'rack/test'
6
6
 
7
+ ENV['RACK_ENV'] = 'test'
8
+
9
+ require File.join(File.dirname(__FILE__), '..', <%- unless tiny -%>'lib', <%- end -%>'<%= app_name %>.rb')
10
+
7
11
  <%= app_klass -%>.set(
8
12
  :environment => :test,
9
13
  :run => false,
@@ -11,23 +15,20 @@ require 'rack/test'
11
15
  :logging => false
12
16
  )
13
17
 
14
- require File.join(File.dirname(__FILE__), '..', <%- unless tiny -%>'lib', <%- end -%>'<%= app_name %>.rb')
15
-
16
18
  module TestHelper
17
-
19
+
18
20
  def app
19
- # change to your app class if using the 'classy' style
20
- Sinatra::Application.new
21
+ <%= app_klass %>.new
21
22
  end
22
-
23
+
23
24
  def body
24
25
  last_response.body
25
26
  end
26
-
27
+
27
28
  def status
28
29
  last_response.status
29
30
  end
30
-
31
+
31
32
  include Rack::Test::Methods
32
33
 
33
34
  end
@@ -55,4 +56,4 @@ Test::Unit::TestCase.send(:include, TestHelper)
55
56
  require 'test/unit'
56
57
 
57
58
  Test::Unit::TestCase.send(:include, TestHelper)
58
- <%- end -%>
59
+ <%- end -%>
@@ -1,12 +1,9 @@
1
1
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
2
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
-
4
3
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
4
  <head>
6
5
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
-
8
6
  <title><%= app_name %></title>
9
-
10
7
  </head>
11
8
 
12
9
  <body>
@@ -2,5 +2,5 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module SinatraGen
5
- VERSION = '0.4.0'
5
+ VERSION = '0.4.1'
6
6
  end
@@ -35,7 +35,7 @@ class TestSinatraAppGenerator < Test::Unit::TestCase
35
35
  end
36
36
 
37
37
  def test_generate_app_with_init_option
38
- run_generator('sinatra_app', [APP_ROOT, '-i'], sources)
38
+ run_generator('sinatra_app', [APP_ROOT, '--init'], sources)
39
39
  assert_basic_paths_and_files('spec')
40
40
  assert_directory_exists '.git'
41
41
  end
@@ -43,6 +43,9 @@ class TestSinatraAppGenerator < Test::Unit::TestCase
43
43
  def test_generate_app_with_heroku_option
44
44
  run_generator('sinatra_app', [APP_ROOT, '--heroku'], sources)
45
45
  assert_basic_paths_and_files('spec')
46
+ assert_generated_file '.gems' do |contents|
47
+ assert_match(/sinatra/, contents)
48
+ end
46
49
  assert_directory_exists '.git'
47
50
  assert_generated_file '.git/config' do |config_contents|
48
51
  assert_match(/\[remote "heroku"\]/, config_contents)
@@ -115,6 +118,15 @@ class TestSinatraAppGenerator < Test::Unit::TestCase
115
118
  end
116
119
  end
117
120
 
121
+ def test_generate_app_with_integration_cucumber_option
122
+ run_generator('sinatra_app', [APP_ROOT, '--integration=cucumber'], sources)
123
+ assert_basic_paths_and_files('features')
124
+ assert_basic_paths_and_files('features/support')
125
+ assert_generated_file 'features/support/env.rb' do |env_contents|
126
+ assert_match(/World/, env_contents)
127
+ end
128
+ end
129
+
118
130
  def test_generate_app_with_views_erb_option
119
131
  run_generator('sinatra_app', [APP_ROOT, '--views=erb'], sources)
120
132
  assert_basic_paths_and_files('spec')
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 1
9
+ version: 0.4.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - Aaron Quint
@@ -9,59 +14,79 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-08-13 00:00:00 -04:00
17
+ date: 2010-05-15 00:00:00 -04:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rubigen
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - "="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 5
30
+ - 2
23
31
  version: 1.5.2
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: sinatra
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 9
44
+ - 4
33
45
  version: 0.9.4
34
- version:
46
+ type: :runtime
47
+ version_requirements: *id002
35
48
  - !ruby/object:Gem::Dependency
36
49
  name: rack-test
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
40
52
  requirements:
41
53
  - - ">="
42
54
  - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ - 4
58
+ - 1
43
59
  version: 0.4.1
44
- version:
60
+ type: :runtime
61
+ version_requirements: *id003
45
62
  - !ruby/object:Gem::Dependency
46
63
  name: newgem
47
- type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
50
66
  requirements:
51
67
  - - ">="
52
68
  - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 5
72
+ - 2
53
73
  version: 1.5.2
54
- version:
74
+ type: :development
75
+ version_requirements: *id004
55
76
  - !ruby/object:Gem::Dependency
56
77
  name: hoe
57
- type: :development
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Requirement
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
60
80
  requirements:
61
81
  - - ">="
62
82
  - !ruby/object:Gem::Version
63
- version: 2.3.3
64
- version:
83
+ segments:
84
+ - 2
85
+ - 6
86
+ - 0
87
+ version: 2.6.0
88
+ type: :development
89
+ version_requirements: *id005
65
90
  description: sinatra-gen generates a common file structure and basic app files for a web app utilizing the sinatra framework. For more information on sinatra, check out http://sinatrarb.com
66
91
  email:
67
92
  - aaron@quirkey.com
@@ -116,18 +141,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
141
  requirements:
117
142
  - - ">="
118
143
  - !ruby/object:Gem::Version
144
+ segments:
145
+ - 0
119
146
  version: "0"
120
- version:
121
147
  required_rubygems_version: !ruby/object:Gem::Requirement
122
148
  requirements:
123
149
  - - ">="
124
150
  - !ruby/object:Gem::Version
151
+ segments:
152
+ - 0
125
153
  version: "0"
126
- version:
127
154
  requirements: []
128
155
 
129
156
  rubyforge_project: quirkey
130
- rubygems_version: 1.3.5
157
+ rubygems_version: 1.3.6
131
158
  signing_key:
132
159
  specification_version: 3
133
160
  summary: sinatra-gen generates a common file structure and basic app files for a web app utilizing the sinatra framework