sinatra-gen 0.1.1 → 0.2.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/History.txt +6 -0
- data/README.rdoc +36 -4
- data/app_generators/sinatra_app/sinatra_app_generator.rb +5 -1
- data/app_generators/sinatra_app/templates/app.rb.erb +9 -1
- data/app_generators/sinatra_app/templates/test/test_app_rspec.rb.erb +10 -1
- data/app_generators/sinatra_app/templates/test/test_app_shoulda.rb.erb +15 -0
- data/app_generators/sinatra_app/templates/test/test_app_spec.rb.erb +10 -0
- data/app_generators/sinatra_app/templates/test/test_app_unit.rb.erb +9 -0
- data/lib/sinatra-gen.rb +1 -1
- data/sinatra-gen.gemspec +2 -2
- data/test/test_sinatra_app_generator.rb +22 -14
- metadata +2 -2
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -14,13 +14,41 @@ user into any specific frameworks/dev practices.
|
|
14
14
|
|
15
15
|
Run:
|
16
16
|
|
17
|
-
sinatra-gen [appname] [options]
|
17
|
+
sinatra-gen [appname] [actions] [options]
|
18
18
|
|
19
19
|
e.g.
|
20
20
|
|
21
|
-
sinatra-gen mysinatrapp --vendor --init --test=shoulda --views=haml
|
21
|
+
sinatra-gen mysinatrapp get:/ post:/:id --vendor --init --test=shoulda --views=haml
|
22
22
|
|
23
|
-
|
23
|
+
=== Actions
|
24
|
+
|
25
|
+
!! NEW as of 0.2.0 (12/23/08)
|
26
|
+
|
27
|
+
For even faster app development you specify actions to include in your app when generating.
|
28
|
+
Actions are written out as
|
29
|
+
|
30
|
+
http_method:path
|
31
|
+
|
32
|
+
And are seperated by spaces. For example:
|
33
|
+
|
34
|
+
get:/ post:/:id put:/update/*
|
35
|
+
|
36
|
+
Will be added you your app as:
|
37
|
+
|
38
|
+
get '/' do
|
39
|
+
end
|
40
|
+
|
41
|
+
post '/:id' do
|
42
|
+
end
|
43
|
+
|
44
|
+
put '/update/*' do
|
45
|
+
end
|
46
|
+
|
47
|
+
It will also generate test skeletons in the test framework of your choosing.
|
48
|
+
|
49
|
+
=== Options
|
50
|
+
|
51
|
+
(can also be obtained by running sinatra-gen with no arguments):
|
24
52
|
|
25
53
|
-v, --version Show the sinatra-gen version number and quit.
|
26
54
|
-d, --vendor Extract the latest sinatra to vendor/sinatra
|
@@ -47,4 +75,8 @@ To run the app without using the vendor option, the sinatra gem must be installe
|
|
47
75
|
|
48
76
|
== INSTALL:
|
49
77
|
|
50
|
-
sudo gem install sintra-gen
|
78
|
+
sudo gem install sintra-gen
|
79
|
+
|
80
|
+
You can also install directly from github:
|
81
|
+
|
82
|
+
sudo gem install quirkey-sinatra-gen -s http://gems.github.com
|
@@ -5,7 +5,7 @@ class SinatraAppGenerator < RubiGen::Base
|
|
5
5
|
|
6
6
|
default_options :author => nil
|
7
7
|
|
8
|
-
attr_accessor :app_name, :vendor, :tiny, :git, :git_init, :test_framework, :view_framework, :install_scripts, :cap
|
8
|
+
attr_accessor :app_name, :vendor, :tiny, :git, :git_init, :test_framework, :view_framework, :install_scripts, :cap, :actions
|
9
9
|
|
10
10
|
def initialize(runtime_args, runtime_options = {})
|
11
11
|
super
|
@@ -13,6 +13,7 @@ class SinatraAppGenerator < RubiGen::Base
|
|
13
13
|
@destination_root = File.expand_path(args.shift)
|
14
14
|
self.app_name = base_name
|
15
15
|
extract_options
|
16
|
+
parse_actions(args)
|
16
17
|
end
|
17
18
|
|
18
19
|
def manifest
|
@@ -102,6 +103,9 @@ EOS
|
|
102
103
|
app_name.classify
|
103
104
|
end
|
104
105
|
|
106
|
+
def parse_actions(*action_args)
|
107
|
+
@actions = action_args.flatten.collect { |a| a.split(':', 2) }
|
108
|
+
end
|
105
109
|
|
106
110
|
# Installation skeleton. Intermediate directories are automatically
|
107
111
|
# created so don't sweat their absence here.
|
@@ -12,6 +12,14 @@ set :public, 'public'
|
|
12
12
|
set :views, 'views'
|
13
13
|
<%- end -%>
|
14
14
|
|
15
|
+
<%- unless actions.empty? -%>
|
16
|
+
<%- actions.each do |meth, path| -%>
|
17
|
+
<%= meth %> '<%= path %>' do
|
18
|
+
end
|
19
|
+
|
20
|
+
<%- end -%>
|
21
|
+
<%- else -%>
|
15
22
|
get '/' do
|
16
23
|
<%= view_framework -%> :index
|
17
|
-
end
|
24
|
+
end
|
25
|
+
<%- end -%>
|
@@ -1,10 +1,19 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
describe '<%= klass_name %>' do
|
4
|
+
|
5
|
+
<%- unless actions.empty? -%>
|
6
|
+
<% actions.each do |meth, path| %>
|
7
|
+
it 'should <%= meth %> <%= path %>' do
|
8
|
+
<%= meth %>_it '<%= path %>'
|
9
|
+
@response.should be_ok
|
10
|
+
end
|
4
11
|
|
12
|
+
<%- end -%>
|
13
|
+
<%- else -%>
|
5
14
|
it 'should load the index' do
|
6
15
|
get_it '/'
|
7
16
|
@response.should be_ok
|
8
17
|
end
|
9
|
-
|
18
|
+
<%- end -%>
|
10
19
|
end
|
@@ -3,6 +3,20 @@ require 'test_helper'
|
|
3
3
|
class <%= klass_name -%>Test < Test::Unit::TestCase
|
4
4
|
|
5
5
|
context "<%= klass_name -%>" do
|
6
|
+
<%- unless actions.empty? -%>
|
7
|
+
<% actions.each do |meth, path| %>
|
8
|
+
context "<%= meth %> <%= path %>" do
|
9
|
+
setup do
|
10
|
+
<%= meth %>_it '<%= path %>'
|
11
|
+
end
|
12
|
+
|
13
|
+
should "respond" do
|
14
|
+
assert @response.body
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
<%- end -%>
|
19
|
+
<%- else -%>
|
6
20
|
context "getting the index" do
|
7
21
|
setup do
|
8
22
|
get_it '/'
|
@@ -12,6 +26,7 @@ class <%= klass_name -%>Test < Test::Unit::TestCase
|
|
12
26
|
assert @response.body
|
13
27
|
end
|
14
28
|
end
|
29
|
+
<%- end -%>
|
15
30
|
end
|
16
31
|
|
17
32
|
end
|
@@ -2,9 +2,19 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
describe '<%= klass_name %>' do
|
4
4
|
|
5
|
+
<%- unless actions.empty? -%>
|
6
|
+
<% actions.each do |meth, path| %>
|
7
|
+
it 'should <%= meth %> <%= path %>' do
|
8
|
+
<%= meth %>_it '<%= path %>'
|
9
|
+
should.be.ok
|
10
|
+
end
|
11
|
+
|
12
|
+
<%- end -%>
|
13
|
+
<%- else -%>
|
5
14
|
it 'should load the index' do
|
6
15
|
get_it '/'
|
7
16
|
should.be.ok
|
8
17
|
end
|
18
|
+
<%- end -%>
|
9
19
|
|
10
20
|
end
|
@@ -2,8 +2,17 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class <%= klass_name -%>Test < Test::Unit::TestCase
|
4
4
|
|
5
|
+
<%- unless actions.empty? -%>
|
6
|
+
<% actions.each do |meth, path| %>
|
7
|
+
def test_<%= meth %>_<%= path.to_s.gsub(/[^a-z0-9\_]/, '') %>_should
|
8
|
+
<%= meth %>_it '<%= path %>'
|
9
|
+
end
|
10
|
+
|
11
|
+
<%- end -%>
|
12
|
+
<%- else -%>
|
5
13
|
def test_my_default
|
6
14
|
get_it '/'
|
7
15
|
end
|
16
|
+
<%- end -%>
|
8
17
|
|
9
18
|
end
|
data/lib/sinatra-gen.rb
CHANGED
data/sinatra-gen.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{sinatra-gen}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Aaron Quint"]
|
9
|
-
s.date = %q{2008-12-
|
9
|
+
s.date = %q{2008-12-23}
|
10
10
|
s.default_executable = %q{sinatra-gen}
|
11
11
|
s.description = %q{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://sinatra.rubyforge.org}
|
12
12
|
s.email = ["aaron@quirkey.com"]
|
@@ -11,20 +11,6 @@ class TestSinatraAppGenerator < Test::Unit::TestCase
|
|
11
11
|
bare_teardown
|
12
12
|
end
|
13
13
|
|
14
|
-
# Some generator-related assertions:
|
15
|
-
# assert_generated_file(name, &block) # block passed the file contents
|
16
|
-
# assert_directory_exists(name)
|
17
|
-
# assert_generated_class(name, &block)
|
18
|
-
# assert_generated_module(name, &block)
|
19
|
-
# assert_generated_test_for(name, &block)
|
20
|
-
# The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
|
21
|
-
# assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
|
22
|
-
#
|
23
|
-
# Other helper methods are:
|
24
|
-
# app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
|
25
|
-
# bare_setup - place this in setup method to create the APP_ROOT folder for each test
|
26
|
-
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test
|
27
|
-
|
28
14
|
def test_generate_app_without_options
|
29
15
|
run_generator('sinatra_app', [APP_ROOT], sources)
|
30
16
|
assert_basic_paths_and_files
|
@@ -146,6 +132,28 @@ class TestSinatraAppGenerator < Test::Unit::TestCase
|
|
146
132
|
assert_generated_file 'script/generate'
|
147
133
|
end
|
148
134
|
|
135
|
+
def test_generate_app_with_actions_and_no_options
|
136
|
+
run_generator('sinatra_app', [APP_ROOT, 'get:/', 'post:/users/:id', 'put:/users/*'], sources)
|
137
|
+
assert_basic_paths_and_files
|
138
|
+
assert_generated_file 'app.rb' do |app_contents|
|
139
|
+
assert_match(/get '\/' do/, app_contents)
|
140
|
+
assert_match(/post '\/users\/\:id' do/, app_contents)
|
141
|
+
assert_match(/put '\/users\/\*' do/, app_contents)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_generate_app_with_actions_and_options
|
146
|
+
run_generator('sinatra_app', [APP_ROOT, 'get:/', 'post:/users/:id', '--tiny', 'put:/users/*'], sources)
|
147
|
+
assert_generated_file 'config.ru'
|
148
|
+
assert_generated_file 'app.rb'
|
149
|
+
assert_generated_file 'Rakefile'
|
150
|
+
assert_generated_file 'app.rb' do |app_contents|
|
151
|
+
assert_match(/get '\/' do/, app_contents)
|
152
|
+
assert_match(/post '\/users\/\:id' do/, app_contents)
|
153
|
+
assert_match(/put '\/users\/\*' do/, app_contents)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
149
157
|
private
|
150
158
|
def assert_basic_paths_and_files
|
151
159
|
assert_directory_exists 'lib'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Quint
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-23 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|