sinatra_app_gen 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ tmp
7
+ demo_sequel
8
+ demo_mongomapper
9
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source :gemcutter
2
+
3
+ gem "jeweler"
4
+ gem "cucumber", ">= 0.6.2"
5
+ gem "rspec", ">= 2.0.0.a"
6
+ gem "aruba", ">= 0.1.6"
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ Sinatra App Gen
2
+ ---------------
3
+
4
+ Simple rubigen-based sinatra application generator
5
+
6
+ How-to use ?
7
+ ------------
8
+
9
+ gem install sinatra_app_gen
10
+
11
+ # By default it generate a Sequel backed app
12
+ sinatra_app my_app
13
+
14
+ # Change the application base module name
15
+ # given module name is camelized
16
+ sinatra_app my_app --namespace=sinatra_sequel
17
+ or
18
+ sinatra_app my_app --namespace=SinatraSequel
19
+
20
+ # Use MongoMapper instead of Sequel
21
+ sinatra_app my_app --orm=MongoMapper
22
+
23
+ ... WIP
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require "rubygems"
2
+ require "rake"
3
+
4
+ begin
5
+ require "jeweler"
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.version = "0.2.0"
8
+ gem.name = "sinatra_app_gen"
9
+ gem.summary = "Creates a new Sinatra / Sequel or MongoMapper / RSpec / Cucumber / Bundler app."
10
+ gem.description = "Our default app template"
11
+ gem.email = "team@openhood.com"
12
+ gem.homepage = "http://github.com/openhood/sinatra_app_gen"
13
+ gem.authors = ["Jonathan Tron", "Joseph Halter"]
14
+ gem.add_dependency "rubigen"
15
+ gem.add_development_dependency "jeweler"
16
+ gem.add_development_dependency "cucumber", ">= 0.6.2"
17
+ gem.add_development_dependency "rspec", ">= 2.0.0a"
18
+ gem.add_development_dependency "aruba", ">= 0.1.6"
19
+ gem.add_development_dependency "bundler", ">= 0.9.9"
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
24
+ end
25
+
26
+ begin
27
+ require "cucumber/rake/task"
28
+ Cucumber::Rake::Task.new
29
+ task :cucumber => :check_dependencies
30
+
31
+ require "lib/cucumber/rvm"
32
+ namespace :rvm do
33
+ desc "Install all gemsets"
34
+ task :install_gems do
35
+ Cucumber::Rvm.each do |rvm|
36
+ rvm.install_gems
37
+ end
38
+ end
39
+ end
40
+ rescue LoadError
41
+ raise "ERROR: #{$!}"
42
+ task :cucumber do
43
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
44
+ end
45
+ end
46
+
47
+ task :default => :cucumber
data/bin/sinatra_app ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "rubigen"
5
+ require "digest/sha1"
6
+
7
+ if %w(-v --version).include? ARGV.first
8
+ require File.dirname(__FILE__) + "/../lib/newgem"
9
+ puts "#{File.basename($0)} #{Newgem::VERSION}"
10
+ exit(0)
11
+ end
12
+
13
+ require "rubigen/scripts/generate"
14
+
15
+ require "pp"
16
+ RubiGen::Base.use_application_sources! :rubygems
17
+ RubiGen::Base.prepend_sources(*[
18
+ RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__), "..", "lib/generators"))
19
+ ])
20
+
21
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => "sinatra_app", :backtrace => false)
@@ -0,0 +1,104 @@
1
+ @announce-cmd
2
+ Feature: Generator
3
+ In order to have a usable Sinatra app
4
+ Sinatra App Gen should generate a fully functionnal application on ruby 1.8.7, 1.9.1 and 1.9.2-head
5
+
6
+ Scenario Outline: without argument
7
+ Given I am using rvm "<ruby_version>"
8
+ And I am using rvm gemset "sinatra_app_gen"
9
+ When I successfully run "../../bin/sinatra_app"
10
+ Then it should pass with:
11
+ """
12
+ Creates a new Sinatra / Sequel or MongoMapper / RSpec / Cucumber app.
13
+
14
+ USAGE: sinatra_app directory_name [options]
15
+
16
+ sinatra_app options:
17
+ --namespace my_namespace Use a different module name (default is camelized directory_name).
18
+ --orm ORM Specify which ORM to use (Default: Sequel; Possible: Sequel, MongoMapper)
19
+ --[no-]async Specify if you want to have async built-in via sinatra-async (Default: true)
20
+ --[no-]rspec Specify if you want to have RSpec built-in (Default: true)
21
+ --[no-]cucumber Specify if you want to have Cucumber built-in (Default: true)
22
+ -v, --version Show the sinatra_app version number and quit.
23
+ """
24
+
25
+ Examples:
26
+ | ruby_version |
27
+ | ree-1.8.7 |
28
+ | 1.9.1 |
29
+ | 1.9.2-head |
30
+
31
+ Scenario Outline: with arguments
32
+ Given I am using rvm "<ruby_version>"
33
+ And I am using rvm gemset "sinatra_app_gen"
34
+ When I successfully run "../../bin/sinatra_app <args>"
35
+ And I cd to "demo_app"
36
+ Then the following files should exist:
37
+ | app.rb |
38
+ | config.ru |
39
+ | Rakefile |
40
+ | Gemfile |
41
+ | features/step_definitions/web_steps.rb |
42
+ | features/support/env.rb |
43
+ | features/support/paths.rb |
44
+ | spec/spec_helper.rb |
45
+ | spec/support/blueprints.rb |
46
+ And the file "app.rb" should contain "<app_name>::App"
47
+ And the file "config.ru" should contain "<app_name>::App"
48
+ And the file "Gemfile" should contain "<gemfile_1>"
49
+ And the file "Gemfile" should contain "<gemfile_2>"
50
+
51
+ Examples:
52
+ | ruby_version | args | app_name | gemfile_1 | gemfile_2 |
53
+ | ree-1.8.7 | demo_app | DemoApp | pg | sequel |
54
+ | ree-1.8.7 | demo_app --namespace=my_app | MyApp | pg | sequel |
55
+ | ree-1.8.7 | demo_app --orm=Sequel | DemoApp | pg | sequel |
56
+ | ree-1.8.7 | demo_app --orm=MongoMapper | DemoApp | mongo_ext | mongo_mapper |
57
+ | 1.9.1 | demo_app | DemoApp | pg | sequel |
58
+ | 1.9.1 | demo_app --namespace=my_app | MyApp | pg | sequel |
59
+ | 1.9.1 | demo_app --orm=Sequel | DemoApp | pg | sequel |
60
+ | 1.9.1 | demo_app --orm=MongoMapper | DemoApp | mongo_ext | mongo_mapper |
61
+ | 1.9.2-head | demo_app | DemoApp | pg | sequel |
62
+ | 1.9.2-head | demo_app --namespace=my_app | MyApp | pg | sequel |
63
+ | 1.9.2-head | demo_app --orm=Sequel | DemoApp | pg | sequel |
64
+ | 1.9.2-head | demo_app --orm=MongoMapper | DemoApp | mongo_ext | mongo_mapper |
65
+
66
+ Scenario Outline: generated app can run cucumber
67
+ Given I am using rvm "<ruby_version>"
68
+ And I am using rvm gemset "sinatra_app_gen"
69
+ When I successfully run "../../bin/sinatra_app demo_app"
70
+ And I cd to "demo_app"
71
+ When I successfully run "bundle install"
72
+ When I successfully run "bundle exec cucumber"
73
+ Then it should pass with:
74
+ """
75
+ 0 scenarios
76
+ 0 steps
77
+ 0m0.000s
78
+ """
79
+
80
+ Examples:
81
+ | ruby_version |
82
+ | ree-1.8.7 |
83
+ # Bundler bug with gems requiring rake prevent the test to pass (http://github.com/carlhuda/bundler/issues#issue/15)
84
+ # | 1.9.1 |
85
+ # | 1.9.2-head |
86
+
87
+ Scenario Outline: generated app can run rspec
88
+ Given I am using rvm "<ruby_version>"
89
+ And I am using rvm gemset "sinatra_app_gen"
90
+ When I successfully run "../../bin/sinatra_app demo_app"
91
+ And I cd to "demo_app"
92
+ When I successfully run "bundle install"
93
+ When I run "bundle exec rake spec"
94
+ Then it should fail with:
95
+ """
96
+ 1 example, 1 failures
97
+ """
98
+
99
+ Examples:
100
+ | ruby_version |
101
+ | ree-1.8.7 |
102
+ # Bundler bug with gems requiring rake prevent the test to pass (http://github.com/carlhuda/bundler/issues#issue/15)
103
+ # | 1.9.1 |
104
+ # | 1.9.2-head |
@@ -0,0 +1,12 @@
1
+ begin
2
+ require "aruba"
3
+ require "rspec/expectations"
4
+ rescue => e
5
+ puts "ERROR : #{e.inspect}"
6
+ end
7
+
8
+ class SinatraAppGenWorld
9
+ include Rspec::Matchers
10
+ end
11
+
12
+ World { SinatraAppGenWorld.new }
@@ -0,0 +1,47 @@
1
+ # Initial idea and code from work on cucumber-rails by Aslak Hellesøy
2
+ # http://github.com/aslakhellesoy/cucumber-rails
3
+ module Cucumber
4
+ class Rvm #:nodoc:
5
+ RVMS = YAML.load_file(File.dirname(__FILE__) + '/../../rvm.yml')
6
+
7
+ class << self
8
+ def each(&proc)
9
+ RVMS["rubies"].each do |ruby_name, ruby_version|
10
+ proc.call(new(ruby_name, RVMS["dev_gems"], nil))
11
+ end
12
+ end
13
+ end
14
+
15
+ def initialize(ruby_name, gems_with_version, world)
16
+ @ruby_version, @gems_with_version, @world = RVMS['rubies'][ruby_name], gems_with_version, world
17
+ raise "NO RUBY VERSION FOUND FOR #{ruby_name}. Check your rvms.yml" if @ruby_version.nil?
18
+ end
19
+
20
+ begin
21
+ require 'aruba/api'
22
+ include Aruba::Api
23
+ rescue LoadError => ignore
24
+ STDOUT.puts "The aruba gem ins not installed. That's ok."
25
+ def run(cmd)
26
+ system(cmd)
27
+ end
28
+ end
29
+
30
+ def rvm(cmd)
31
+ rvm_cmd = "rvm #{@ruby_version}%sinatra_app_gen #{cmd}"
32
+ if @world
33
+ @world.announce(rvm_cmd)
34
+ else
35
+ puts(rvm_cmd)
36
+ end
37
+ run(rvm_cmd)
38
+ raise "STDOUT:\n#{@last_stdout}\nSTDERR:\n#{@last_stderr}" if @last_exit_status && @last_exit_status != 0
39
+ end
40
+
41
+ def install_gems
42
+ @gems_with_version.each do |gem_with_version|
43
+ rvm("-S gem install #{gem_with_version}")
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,117 @@
1
+ class SinatraAppGenerator < RubiGen::Base
2
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
3
+ Config::CONFIG['ruby_install_name'])
4
+
5
+ default_options :namespace => nil,
6
+ :orm => "Sequel",
7
+ :async => true,
8
+ :rspec => true,
9
+ :cucumber => true
10
+ attr_reader :name
11
+
12
+ def initialize(runtime_args, runtime_options = {})
13
+ super
14
+ usage if args.empty?
15
+ @destination_root = File.expand_path(args.shift)
16
+ @name = (options[:namespace] || base_name).camelize
17
+ end
18
+
19
+ def template(m, filename)
20
+ m.template "#{filename}.erb", filename
21
+ end
22
+
23
+ def manifest
24
+ record do |m|
25
+ # Ensure appropriate folder(s) exists
26
+ m.directory ''
27
+ BASEDIRS.each { |path| m.directory path }
28
+
29
+ # root
30
+ template m, "app.rb"
31
+ template m, "config.ru"
32
+ template m, "Gemfile"
33
+ template m, "Rakefile"
34
+
35
+ # config
36
+ m.directory "config"
37
+ template m, "config/test.yml"
38
+
39
+ if use_cucumber?
40
+ # cucumber
41
+ m.directory "features/support"
42
+ m.directory "features/step_definitions"
43
+ template m, "features/support/env.rb"
44
+ template m, "features/support/paths.rb"
45
+ template m, "features/support/blueprints.rb" unless use_rspec?
46
+ template m, "features/step_definitions/web_steps.rb"
47
+ end
48
+
49
+ if use_rspec?
50
+ # rspec
51
+ m.directory "spec"
52
+ template m, "spec/spec_helper.rb"
53
+ m.directory "spec/support"
54
+ template m, "spec/support/blueprints.rb"
55
+ m.directory "spec/models"
56
+ template m, "spec/models/demo_spec.rb"
57
+ end
58
+ end
59
+ end
60
+
61
+ protected
62
+ def use_sequel?
63
+ options[:orm].eql?("Sequel")
64
+ end
65
+
66
+ def use_mongomapper?
67
+ options[:orm].eql?("MongoMapper")
68
+ end
69
+
70
+ def use_async?
71
+ options[:async]
72
+ end
73
+
74
+ def use_rspec?
75
+ options[:rspec]
76
+ end
77
+
78
+ def use_cucumber?
79
+ options[:cucumber]
80
+ end
81
+
82
+ def banner
83
+ <<-EOS
84
+ Creates a new Sinatra / Sequel or MongoMapper / RSpec / Cucumber app.
85
+
86
+ USAGE: #{spec.name} directory_name [options]
87
+ EOS
88
+ end
89
+
90
+ def add_options!(opts)
91
+ opts.separator ''
92
+ opts.separator "#{File.basename($0)} options:"
93
+ opts.on("--namespace my_namespace", "Use a different module name (default is camelized directory_name).") do |o|
94
+ options[:namespace] = o
95
+ end
96
+ opts.on("--orm ORM", ["Sequel", "MongoMapper"], "Specify which ORM to use (Default: Sequel; Possible: Sequel, MongoMapper)") do |o|
97
+ options[:orm] = o
98
+ end
99
+ opts.on("--[no-]async", "Specify if you want to have async built-in via sinatra-async (Default: true)") do |o|
100
+ options[:async] = o
101
+ end
102
+ opts.on("--[no-]rspec", "Specify if you want to have RSpec built-in (Default: true)") do |o|
103
+ options[:rspec] = o
104
+ end
105
+ opts.on("--[no-]cucumber", "Specify if you want to have Cucumber built-in (Default: true)") do |o|
106
+ options[:cucumber] = o
107
+ end
108
+ opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
109
+ end
110
+
111
+ # Installation skeleton. Intermediate directories are automatically
112
+ # created so don't sweat their absence here.
113
+ BASEDIRS = %w(
114
+ lib
115
+ spec
116
+ )
117
+ end
@@ -0,0 +1,46 @@
1
+ source :gemcutter
2
+ source "http://gems.github.com"
3
+
4
+ gem "thin"
5
+ gem "sinatra", "~> 1.0a"
6
+ <% if use_async? -%>
7
+ gem "raggi-async_sinatra"
8
+ <% end -%>
9
+ gem "haml", ">= 2.2.2"
10
+ gem "yajl-ruby"
11
+ <% if use_sequel? -%>
12
+ gem "pg", "~> 0.9.0"
13
+ gem "sequel"
14
+ <% elsif use_mongomapper? -%>
15
+ gem "mongo_ext", "0.18.3", :require => nil
16
+ gem "mongo_mapper"
17
+ <% end -%>
18
+ gem "JosephHalter-string_cleaner"
19
+ gem "nakajima-rack-flash"
20
+ gem "sinatra_rake_tasks", ">= 0.2.0"
21
+
22
+ group :development do
23
+ gem "shotgun"
24
+ end
25
+ <% if use_rspec? || use_cucumber? %>
26
+ group :test, :cucumber do
27
+ gem "timecop"
28
+ gem "rspec", ">= 2.0.0.a"
29
+ <% if use_mongomapper? -%>
30
+ gem "machinist_mongo", :require => "machinist/mongo_mapper"
31
+ <% end -%>
32
+ end
33
+ <% end -%>
34
+ <% if use_rspec? %>
35
+ group :test do
36
+ <% if use_sequel? -%>
37
+ gem "rspec_sequel_matchers", ">= 0.2.0"
38
+ <% end -%>
39
+ end
40
+ <% end -%>
41
+ <% if use_cucumber? %>
42
+ group :cucumber do
43
+ gem "capybara", ">= 0.3.5"
44
+ gem "cucumber", ">= 0.6.2"
45
+ end
46
+ <% end -%>
@@ -0,0 +1,8 @@
1
+ require "sinatra_rake_tasks"
2
+ OpenHood::Rake::SpecTask.new
3
+ OpenHood::Rake::CucumberTask.new
4
+ <% if use_sequel? -%>
5
+ OpenHood::Rake::SequelTask.new
6
+ <% end -%>
7
+ OpenHood::Rake::CITask.new
8
+ OpenHood::Rake::ConsoleTask.new
@@ -0,0 +1,95 @@
1
+ begin
2
+ # Try to require the preresolved locked set of gems.
3
+ require ::File.expand_path('../.bundle/environment', __FILE__)
4
+ rescue LoadError
5
+ # Fall back on doing an unlocked resolve at runtime.
6
+ require "rubygems"
7
+ require "bundler"
8
+ Bundler.setup
9
+ end
10
+
11
+ bundle_env = [:default]
12
+ bundle_env << ENV["RACK_ENV"].to_sym if ENV["RACK_ENV"]
13
+ Bundler.require *bundle_env
14
+
15
+ require "yaml"
16
+ require "logger"
17
+ require "yajl"
18
+ require "logger"
19
+ require "haml"
20
+ <% if use_sequel? -%>
21
+ require "sequel"
22
+ require "sequel/extensions/blank"
23
+ require "sequel/extensions/inflector"
24
+ <% end -%>
25
+ require "sinatra/base"
26
+ <% if use_async? -%>
27
+ require "sinatra/async"
28
+ <% end %>
29
+ require "rack-flash"
30
+ require "string_cleaner"
31
+
32
+ module <%= name %>
33
+ class App < Sinatra::Base
34
+
35
+ # load environment config
36
+ def self.config
37
+ @@config ||= begin
38
+ filename = ::File.join(::File.dirname(__FILE__), "config", "#{environment}.yml")
39
+ ::File.exists?(filename) ? YAML.load_file(filename) : raise("No config/#{environment}.yml found")
40
+ end
41
+ end
42
+
43
+ configure do
44
+ set :root, ::File.dirname(__FILE__)
45
+ set :static, true
46
+ set :public, ::File.join(root, "public")
47
+ set :views, ::File.join(root, "views")
48
+ enable :logging
49
+ enable :sessions
50
+
51
+ # setup logger and connect to db
52
+ FileUtils.mkdir_p ::File.join(root, "log")
53
+ logger = Logger.new(::File.join(root, "log", "#{environment}.log"))
54
+ logger.level = production? ? Logger::ERROR : Logger::DEBUG
55
+ <% if use_sequel? -%>
56
+ Sequel.connect(config[:db][:uri], :loggers => [logger])
57
+ <% elsif use_mongomapper? -%>
58
+ MongoMapper.connection = Mongo::Connection.new(config[:db][:host] || "127.0.0.1", config[:db][:port] || 27017, {:logger => logger})
59
+ MongoMapper.database = config[:db][:name] || "<%= name -%>-#{environment}"
60
+ <% end -%>
61
+
62
+ # load models
63
+ Dir.glob(::File.join(root, "models", "*.rb")).each do |m|
64
+ require m
65
+ end
66
+
67
+ # load helpers
68
+ helpers do
69
+ alias_method :h, :escape_html
70
+ def config
71
+ <%= name %>::App.config
72
+ end
73
+ Dir.glob(::File.join(root, "helpers", "*.rb")).each do |h|
74
+ require h
75
+ module_name = "#{::File.basename(h, ".rb").camelize}Helper"
76
+ include <%= name %>.const_get(module_name) if <%= name %>.const_defined?(module_name)
77
+ end
78
+ end
79
+
80
+ use Rack::Session::Cookie
81
+ use Rack::Flash
82
+ end
83
+
84
+ # load fake controllers
85
+ Dir.glob(::File.join(root, "controllers", "*.rb")).each do |c|
86
+ require c
87
+ end
88
+
89
+ end
90
+ end
91
+
92
+ # define default port if launched directly via "ruby app.rb"
93
+ if $0 == __FILE__
94
+ <%= name %>::App.run! :host => "localhost", :port => 4567
95
+ end
@@ -0,0 +1,8 @@
1
+ :db:
2
+ <% if use_sequel? -%>
3
+ :uri: postgres://localhost/<%= name.underscore -%>_test
4
+ <% elsif use_mongomapper? -%>
5
+ :host: 127.0.0.1
6
+ :port: 27017
7
+ :name: <%= name.underscore -%>_test
8
+ <% end -%>
@@ -0,0 +1,11 @@
1
+ require "rubygems"
2
+ require "app"
3
+
4
+ # log for passenger
5
+ FileUtils.mkdir_p "log" unless ::File.exists?("log")
6
+ log = ::File.new("log/sinatra.log", "a+")
7
+ $stdout.reopen(log)
8
+ $stderr.reopen(log)
9
+
10
+ # run the server
11
+ run <%= name %>::App
@@ -0,0 +1,156 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
2
+
3
+ Given /^I am on (.+)$/ do |page_name|
4
+ visit path_to(page_name)
5
+ end
6
+
7
+ When /^I visit "([^\"]+)"$/ do |page_name|
8
+ visit path_to(page_name)
9
+ end
10
+
11
+ When /^I go to (.+)$/ do |page_name|
12
+ visit path_to(page_name)
13
+ end
14
+
15
+ When /^I press "([^\"]*)"$/ do |button|
16
+ click_button(button)
17
+ end
18
+
19
+ When /^I follow "([^\"]*)"$/ do |link|
20
+ click_link(link)
21
+ end
22
+
23
+ When /^I submit form "([^\"]*)"$/ do |form|
24
+ submit_form(form)
25
+ end
26
+
27
+ When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
28
+ fill_in(field, :with => value)
29
+ end
30
+
31
+ When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
32
+ select(value, :from => field)
33
+ end
34
+
35
+ # Use this step in conjunction with Rail's datetime_select helper. For example:
36
+ # When I select "December 25, 2008 10:00" as the date and time
37
+ When /^I select "([^\"]*)" as the date and time$/ do |time|
38
+ select_datetime(time)
39
+ end
40
+
41
+ # Use this step when using multiple datetime_select helpers on a page or
42
+ # you want to specify which datetime to select. Given the following view:
43
+ # <%%= f.label :preferred %><br />
44
+ # <%%= f.datetime_select :preferred %>
45
+ # <%%= f.label :alternative %><br />
46
+ # <%%= f.datetime_select :alternative %>
47
+ # The following steps would fill out the form:
48
+ # When I select "November 23, 2004 11:20" as the "Preferred" data and time
49
+ # And I select "November 25, 2004 10:30" as the "Alternative" data and time
50
+ When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
51
+ select_datetime(datetime, :from => datetime_label)
52
+ end
53
+
54
+ # Use this step in conjuction with Rail's time_select helper. For example:
55
+ # When I select "2:20PM" as the time
56
+ # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
57
+ # will convert the 2:20PM to 14:20 and then select it.
58
+ When /^I select "([^\"]*)" as the time$/ do |time|
59
+ select_time(time)
60
+ end
61
+
62
+ # Use this step when using multiple time_select helpers on a page or you want to
63
+ # specify the name of the time on the form. For example:
64
+ # When I select "7:30AM" as the "Gym" time
65
+ When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
66
+ select_time(time, :from => time_label)
67
+ end
68
+
69
+ # Use this step in conjuction with Rail's date_select helper. For example:
70
+ # When I select "February 20, 1981" as the date
71
+ When /^I select "([^\"]*)" as the date$/ do |date|
72
+ select_date(date)
73
+ end
74
+
75
+ # Use this step when using multiple date_select helpers on one page or
76
+ # you want to specify the name of the date on the form. For example:
77
+ # When I select "April 26, 1982" as the "Date of Birth" date
78
+ When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
79
+ select_date(date, :from => date_label)
80
+ end
81
+
82
+ When /^I check "([^\"]*)"$/ do |field|
83
+ check(field)
84
+ end
85
+
86
+ When /^I uncheck "([^\"]*)"$/ do |field|
87
+ uncheck(field)
88
+ end
89
+
90
+ When /^I choose "([^\"]*)"$/ do |field|
91
+ choose(field)
92
+ end
93
+
94
+ When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |filename, field|
95
+ path = File.join(Rails.root, "features", "fixtures", filename)
96
+ attach_file(field, path)
97
+ end
98
+
99
+ Then /^I should see "([^\"]*)"$/ do |text|
100
+ response.body.should =~ /#{Regexp.escape(text)}/m
101
+ end
102
+
103
+ Then /^I should not see "([^\"]*)"$/ do |text|
104
+ response.body.should_not =~ /#{Regexp.escape(text)}/m
105
+ end
106
+
107
+ Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
108
+ field_labeled(label).should be_checked
109
+ end
110
+
111
+ Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
112
+ field_labeled(label).should_not be_checked
113
+ end
114
+
115
+ Then /^the "([^\"]*)" item from "([^\"]*)" should be selected$/ do |item, label|
116
+ field_locate(label).should have_tag("option[selected]", item)
117
+ end
118
+
119
+ Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
120
+ field_labeled(field).value.should =~ /#{value}/
121
+ end
122
+
123
+ Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
124
+ field_labeled(field).value.should_not =~ /#{value}/
125
+ end
126
+
127
+ Then /^I should see a link to (.+)$/ do |page|
128
+ response.should have_tag("a[href=?]", path_to(page))
129
+ end
130
+
131
+ Then /^I should see a form with (delete|post|put|get) method to (.+)$/ do |method, page|
132
+ if ["delete", "put", "post"].include?(method)
133
+ form_tag = "form[method=post][action=?]"
134
+ else
135
+ form_tag = "form[method=get][action=?]"
136
+ end
137
+
138
+ response.body.should have_tag(form_tag, path_to(page)) do
139
+ if ["delete", "put"].include?(method)
140
+ with_tag("input[type=hidden][name=_method][value=?]", method)
141
+ else
142
+ without_tag("input[type=hidden][name=_method][value=?]", "delete")
143
+ without_tag("input[type=hidden][name=_method][value=?]", "put")
144
+ end
145
+ end
146
+ end
147
+
148
+ Then /^I should see a select with :$/ do |select_table|
149
+ select_table.hashes.each do |hash|
150
+ response.should have_tag("option", hash["display"])
151
+ end
152
+ end
153
+
154
+ Then /^I should be on (.+)$/ do |page_name|
155
+ URI.parse(current_url).path.should == path_to(page_name)
156
+ end
@@ -0,0 +1,21 @@
1
+ ENV["RACK_ENV"] = "test"
2
+ $VERBOSE=nil # until MongoMapper guy stop undefining object_id in belongs_to_proxy.rb
3
+ require File.join(File.dirname(__FILE__), *%w[.. .. app.rb])
4
+ <% if use_rspec? %>
5
+ require File.join(File.dirname(__FILE__), *%w[.. .. spec support blueprints.rb])
6
+ <% end %>
7
+ require "rspec/expectations"
8
+ require "capybara/cucumber"
9
+ require "capybara/session"
10
+
11
+ Capybara.app = <%= name -%>::App
12
+ Capybara.class_eval do
13
+ include Rspec::Matchers
14
+ end
15
+
16
+ <% if use_sequel? -%>
17
+ <% elsif use_mongomapper? -%>
18
+ Before do |scenario|
19
+ ::MongoMapper.database.collections.each{|c| c.remove}
20
+ end
21
+ <% end -%>
@@ -0,0 +1,16 @@
1
+ module NavigationHelpers
2
+ def path_to(page_name)
3
+ case page_name
4
+ when /the home page/i
5
+ "/"
6
+ else
7
+ if page_name.include? "/"
8
+ page_name # page_name is already a path
9
+ else
10
+ raise "Can't find mapping from \"#{page_name}\" to a path."
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ World(NavigationHelpers)
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Demo" do
4
+ it "should be ok" do
5
+ 1.should == 1
6
+ end
7
+ end
@@ -0,0 +1,44 @@
1
+ ENV["RACK_ENV"] = "test"
2
+
3
+ # Load the Sinatra app
4
+ require File.join(File.dirname(__FILE__), "..", "app")
5
+
6
+ # Load the testing libraries
7
+ require "rspec"
8
+
9
+ <% if use_sequel? -%>
10
+ require "sequel/extensions/migration"
11
+ require "rspec_sequel_matchers"
12
+ <% end -%>
13
+
14
+ # Set the Sinatra environment
15
+ <%= name %>::App.configure do |c|
16
+ c.set :environment, :test
17
+ c.disable :run
18
+ c.enable :raise_errors
19
+ c.disable :logging
20
+ end
21
+
22
+ Rspec.configure do |c|
23
+ c.mock_framework = :rspec
24
+ c.color_enabled = true
25
+ <% if use_sequel? -%>
26
+ c.include(RspecSequel::Matchers)
27
+ c.before(:suite) do
28
+ Sequel::Model.db.tables.each do |table_name|
29
+ Sequel::Model.db.drop_table table_name
30
+ end
31
+ dirname = File.join(TestRspec::App.root, "..", "migrations")
32
+ Sequel::Migrator.apply(Sequel::Model.db, dirname) if File.directory?(dirname)
33
+ end
34
+ c.after(:each) do
35
+ Sequel::Model.db.tables.each do |table_name|
36
+ Sequel::Model.db["TRUNCATE #{table_name}"]
37
+ end
38
+ end
39
+ <% elsif use_mongomapper? -%>
40
+ config.before(:each) do
41
+ ::MongoMapper.database.collections.each{|c| c.remove}
42
+ end
43
+ <% end -%>
44
+ end
data/rvm.yml ADDED
@@ -0,0 +1,11 @@
1
+ rubies:
2
+ # 1.8.7: ruby-1.8.7-tv1_8_7_174
3
+ ree-1.8.7: ree-1.8.7-2010.01
4
+ 1.9.1: ruby-1.9.1-p378
5
+ 1.9.2: ruby-1.9.2-head
6
+ dev_gems:
7
+ - jeweler
8
+ - cucumber -v '>= 0.6.2'
9
+ - rspec -v '>= 2.0.0.a9'
10
+ - aruba -v '>= 0.1.6'
11
+ - bundler
@@ -0,0 +1,79 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{sinatra_app_gen}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jonathan Tron", "Joseph Halter"]
12
+ s.date = %q{2010-03-03}
13
+ s.default_executable = %q{sinatra_app}
14
+ s.description = %q{Our default app template}
15
+ s.email = %q{team@openhood.com}
16
+ s.executables = ["sinatra_app"]
17
+ s.extra_rdoc_files = [
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ ".gitignore",
22
+ "Gemfile",
23
+ "README.md",
24
+ "Rakefile",
25
+ "bin/sinatra_app",
26
+ "features/generator.feature",
27
+ "features/support/env.rb",
28
+ "lib/cucumber/rvm.rb",
29
+ "lib/generators/sinatra_app/sinatra_app_generator.rb",
30
+ "lib/generators/sinatra_app/templates/Gemfile.erb",
31
+ "lib/generators/sinatra_app/templates/Rakefile.erb",
32
+ "lib/generators/sinatra_app/templates/app.rb.erb",
33
+ "lib/generators/sinatra_app/templates/config.ru.erb",
34
+ "lib/generators/sinatra_app/templates/config/test.yml.erb",
35
+ "lib/generators/sinatra_app/templates/features/step_definitions/web_steps.rb.erb",
36
+ "lib/generators/sinatra_app/templates/features/support/blueprints.rb.erb",
37
+ "lib/generators/sinatra_app/templates/features/support/env.rb.erb",
38
+ "lib/generators/sinatra_app/templates/features/support/paths.rb.erb",
39
+ "lib/generators/sinatra_app/templates/spec/models/demo_spec.rb.erb",
40
+ "lib/generators/sinatra_app/templates/spec/spec_helper.rb.erb",
41
+ "lib/generators/sinatra_app/templates/spec/support/blueprints.rb.erb",
42
+ "rvm.yml",
43
+ "sinatra_app_gen.gemspec"
44
+ ]
45
+ s.homepage = %q{http://github.com/openhood/sinatra_app_gen}
46
+ s.rdoc_options = ["--charset=UTF-8"]
47
+ s.require_paths = ["lib"]
48
+ s.rubygems_version = %q{1.3.6}
49
+ s.summary = %q{Creates a new Sinatra / Sequel or MongoMapper / RSpec / Cucumber / Bundler app.}
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ s.add_runtime_dependency(%q<rubigen>, [">= 0"])
57
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
58
+ s.add_development_dependency(%q<cucumber>, [">= 0.6.2"])
59
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0a"])
60
+ s.add_development_dependency(%q<aruba>, [">= 0.1.6"])
61
+ s.add_development_dependency(%q<bundler>, [">= 0.9.9"])
62
+ else
63
+ s.add_dependency(%q<rubigen>, [">= 0"])
64
+ s.add_dependency(%q<jeweler>, [">= 0"])
65
+ s.add_dependency(%q<cucumber>, [">= 0.6.2"])
66
+ s.add_dependency(%q<rspec>, [">= 2.0.0a"])
67
+ s.add_dependency(%q<aruba>, [">= 0.1.6"])
68
+ s.add_dependency(%q<bundler>, [">= 0.9.9"])
69
+ end
70
+ else
71
+ s.add_dependency(%q<rubigen>, [">= 0"])
72
+ s.add_dependency(%q<jeweler>, [">= 0"])
73
+ s.add_dependency(%q<cucumber>, [">= 0.6.2"])
74
+ s.add_dependency(%q<rspec>, [">= 2.0.0a"])
75
+ s.add_dependency(%q<aruba>, [">= 0.1.6"])
76
+ s.add_dependency(%q<bundler>, [">= 0.9.9"])
77
+ end
78
+ end
79
+
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra_app_gen
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
+ platform: ruby
11
+ authors:
12
+ - Jonathan Tron
13
+ - Joseph Halter
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-03-03 00:00:00 +01:00
19
+ default_executable: sinatra_app
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rubigen
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: jeweler
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ version: "0"
43
+ type: :development
44
+ version_requirements: *id002
45
+ - !ruby/object:Gem::Dependency
46
+ name: cucumber
47
+ prerelease: false
48
+ requirement: &id003 !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ - 6
55
+ - 2
56
+ version: 0.6.2
57
+ type: :development
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec
61
+ prerelease: false
62
+ requirement: &id004 !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 2
68
+ - 0
69
+ - 0a
70
+ version: 2.0.0a
71
+ type: :development
72
+ version_requirements: *id004
73
+ - !ruby/object:Gem::Dependency
74
+ name: aruba
75
+ prerelease: false
76
+ requirement: &id005 !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ - 1
83
+ - 6
84
+ version: 0.1.6
85
+ type: :development
86
+ version_requirements: *id005
87
+ - !ruby/object:Gem::Dependency
88
+ name: bundler
89
+ prerelease: false
90
+ requirement: &id006 !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
96
+ - 9
97
+ - 9
98
+ version: 0.9.9
99
+ type: :development
100
+ version_requirements: *id006
101
+ description: Our default app template
102
+ email: team@openhood.com
103
+ executables:
104
+ - sinatra_app
105
+ extensions: []
106
+
107
+ extra_rdoc_files:
108
+ - README.md
109
+ files:
110
+ - .gitignore
111
+ - Gemfile
112
+ - README.md
113
+ - Rakefile
114
+ - bin/sinatra_app
115
+ - features/generator.feature
116
+ - features/support/env.rb
117
+ - lib/cucumber/rvm.rb
118
+ - lib/generators/sinatra_app/sinatra_app_generator.rb
119
+ - lib/generators/sinatra_app/templates/Gemfile.erb
120
+ - lib/generators/sinatra_app/templates/Rakefile.erb
121
+ - lib/generators/sinatra_app/templates/app.rb.erb
122
+ - lib/generators/sinatra_app/templates/config.ru.erb
123
+ - lib/generators/sinatra_app/templates/config/test.yml.erb
124
+ - lib/generators/sinatra_app/templates/features/step_definitions/web_steps.rb.erb
125
+ - lib/generators/sinatra_app/templates/features/support/blueprints.rb.erb
126
+ - lib/generators/sinatra_app/templates/features/support/env.rb.erb
127
+ - lib/generators/sinatra_app/templates/features/support/paths.rb.erb
128
+ - lib/generators/sinatra_app/templates/spec/models/demo_spec.rb.erb
129
+ - lib/generators/sinatra_app/templates/spec/spec_helper.rb.erb
130
+ - lib/generators/sinatra_app/templates/spec/support/blueprints.rb.erb
131
+ - rvm.yml
132
+ - sinatra_app_gen.gemspec
133
+ has_rdoc: true
134
+ homepage: http://github.com/openhood/sinatra_app_gen
135
+ licenses: []
136
+
137
+ post_install_message:
138
+ rdoc_options:
139
+ - --charset=UTF-8
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ segments:
154
+ - 0
155
+ version: "0"
156
+ requirements: []
157
+
158
+ rubyforge_project:
159
+ rubygems_version: 1.3.6
160
+ signing_key:
161
+ specification_version: 3
162
+ summary: Creates a new Sinatra / Sequel or MongoMapper / RSpec / Cucumber / Bundler app.
163
+ test_files: []
164
+