Permalink
Browse files

Added test=bacon option

Fixing test generation for 0.9
  • Loading branch information...
1 parent bc052d3 commit 6b9f3782c404bfcd202d69aebf338c4b73f0014e @quirkey quirkey committed Feb 10, 2009
View
2 app_generators/sinatra_app/USAGE
@@ -1,7 +1,7 @@
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://sinatra.rubyforge.org
+ For more information on sinatra, check out http://sinatrarb.com
Usage:
View
20 app_generators/sinatra_app/templates/test/test_app_bacon.rb.erb
@@ -0,0 +1,20 @@
+require 'test_helper'
+
+describe '<%= klass_name %>' do
+
+ <%- unless actions.empty? -%>
+ <% actions.each do |meth, path| %>
+ it 'should <%= meth %> <%= path %>' do
+ <%= meth %> '<%= path %>'
+ should.be.ok
+ end
+
+ <%- end -%>
+ <%- else -%>
+ it 'should load the index' do
+ get '/'
+ should.be.ok
+ end
+ <%- end -%>
+end
+
View
4 app_generators/sinatra_app/templates/test/test_app_rspec.rb.erb
@@ -5,14 +5,14 @@ describe '<%= klass_name %>' do
<%- unless actions.empty? -%>
<% actions.each do |meth, path| %>
it 'should <%= meth %> <%= path %>' do
- <%= meth %>_it '<%= path %>'
+ <%= meth %> '<%= path %>'
@response.should be_ok
end
<%- end -%>
<%- else -%>
it 'should load the index' do
- get_it '/'
+ get '/'
@response.should be_ok
end
<%- end -%>
View
4 app_generators/sinatra_app/templates/test/test_app_shoulda.rb.erb
@@ -7,7 +7,7 @@ class <%= klass_name -%>Test < Test::Unit::TestCase
<% actions.each do |meth, path| %>
context "<%= meth %> <%= path %>" do
setup do
- <%= meth %>_it '<%= path %>'
+ <%= meth %> '<%= path %>'
end
should "respond" do
@@ -19,7 +19,7 @@ class <%= klass_name -%>Test < Test::Unit::TestCase
<%- else -%>
context "getting the index" do
setup do
- get_it '/'
+ get '/'
end
should "respond" do
View
4 app_generators/sinatra_app/templates/test/test_app_spec.rb.erb
@@ -5,14 +5,14 @@ describe '<%= klass_name %>' do
<%- unless actions.empty? -%>
<% actions.each do |meth, path| %>
it 'should <%= meth %> <%= path %>' do
- <%= meth %>_it '<%= path %>'
+ <%= meth %> '<%= path %>'
should.be.ok
end
<%- end -%>
<%- else -%>
it 'should load the index' do
- get_it '/'
+ get '/'
should.be.ok
end
<%- end -%>
View
4 app_generators/sinatra_app/templates/test/test_app_unit.rb.erb
@@ -5,13 +5,13 @@ class <%= klass_name -%>Test < Test::Unit::TestCase
<%- unless actions.empty? -%>
<% actions.each do |meth, path| %>
def test_<%= meth %>_<%= path.to_s.gsub(/[^a-z0-9\_]/, '') %>_should
- <%= meth %>_it '<%= path %>'
+ <%= meth %> '<%= path %>'
end
<%- end -%>
<%- else -%>
def test_my_default
- get_it '/'
+ get '/'
end
<%- end -%>
View
5 app_generators/sinatra_app/templates/test/test_helper.rb.erb
@@ -1,4 +1,3 @@
-require 'rubygems'
<%- if vendor -%>
$:.unshift File.join(File.dirname(__FILE__), '..', 'vendor', 'sinatra', 'lib')
require 'sinatra'
@@ -9,6 +8,8 @@ require 'sinatra'
<%- when 'rspec' -%>
require 'spec'
require 'sinatra/test/rspec'
+<%- when 'bacon' -%>
+require 'sinatra/test/bacon'
<%- when 'spec' -%>
require 'sinatra/test/spec'
<%- when 'shoulda' -%>
@@ -17,4 +18,4 @@ require 'shoulda'
<%- when 'unit' -%>
require 'sinatra/test/unit'
<%- end -%>
-require File.join(File.dirname(__FILE__), '..', 'app.rb')
+require File.join(File.dirname(__FILE__), '..', '<%= app_name %>.rb')
View
27 test/test_sinatra_app_generator.rb
@@ -30,7 +30,7 @@ def test_generate_app_with_vendor_option
def test_generate_app_with_tiny_option
run_generator('sinatra_app', [APP_ROOT, '--tiny'], sources)
assert_generated_file 'config.ru'
- assert_generated_file 'app.rb'
+ assert_generated_file "#{app_name}.rb"
assert_generated_file 'Rakefile'
end
@@ -94,11 +94,22 @@ def test_generate_app_with_test_unit_option
assert_match(/def test/, test_contents)
end
end
+
+ def test_generate_app_with_test_bacon_option
+ run_generator('sinatra_app', [APP_ROOT, '--test=bacon'], sources)
+ assert_basic_paths_and_files
+ assert_generated_file 'test/test_helper.rb' do |helper_contents|
+ assert_match(/sinatra\/test\/bacon/, helper_contents)
+ end
+ assert_generated_file "test/test_#{app_name}.rb" do |test_contents|
+ assert_match(/describe/, test_contents)
+ end
+ end
def test_generate_app_with_views_haml_option
run_generator('sinatra_app', [APP_ROOT, '--views=erb'], sources)
assert_basic_paths_and_files
- assert_generated_file 'app.rb' do |app_contents|
+ assert_generated_file "#{app_name}.rb" do |app_contents|
assert_match(/erb \:index/, app_contents)
end
assert_generated_file 'views/layout.erb'
@@ -108,7 +119,7 @@ def test_generate_app_with_views_haml_option
def test_generate_app_with_views_haml_option
run_generator('sinatra_app', [APP_ROOT, '--views=haml'], sources)
assert_basic_paths_and_files
- assert_generated_file 'app.rb' do |app_contents|
+ assert_generated_file "#{app_name}.rb" do |app_contents|
assert_match(/haml \:index/, app_contents)
end
assert_generated_file 'views/layout.haml'
@@ -118,7 +129,7 @@ def test_generate_app_with_views_haml_option
def test_generate_app_with_views_builder_option
run_generator('sinatra_app', [APP_ROOT, '--views=builder'], sources)
assert_basic_paths_and_files
- assert_generated_file 'app.rb' do |app_contents|
+ assert_generated_file "#{app_name}.rb" do |app_contents|
assert_match(/builder \:index/, app_contents)
end
assert_generated_file 'views/index.builder'
@@ -135,7 +146,7 @@ def test_generate_app_with_scripts_option
def test_generate_app_with_actions_and_no_options
run_generator('sinatra_app', [APP_ROOT, 'get:/', 'post:/users/:id', 'put:/users/*'], sources)
assert_basic_paths_and_files
- assert_generated_file 'app.rb' do |app_contents|
+ assert_generated_file "#{app_name}.rb" do |app_contents|
assert_match(/get '\/' do/, app_contents)
assert_match(/post '\/users\/\:id' do/, app_contents)
assert_match(/put '\/users\/\*' do/, app_contents)
@@ -145,9 +156,9 @@ def test_generate_app_with_actions_and_no_options
def test_generate_app_with_actions_and_options
run_generator('sinatra_app', [APP_ROOT, 'get:/', 'post:/users/:id', '--tiny', 'put:/users/*'], sources)
assert_generated_file 'config.ru'
- assert_generated_file 'app.rb'
+ assert_generated_file "#{app_name}.rb"
assert_generated_file 'Rakefile'
- assert_generated_file 'app.rb' do |app_contents|
+ assert_generated_file "#{app_name}.rb" do |app_contents|
assert_match(/get '\/' do/, app_contents)
assert_match(/post '\/users\/\:id' do/, app_contents)
assert_match(/put '\/users\/\*' do/, app_contents)
@@ -161,7 +172,7 @@ def assert_basic_paths_and_files
assert_directory_exists 'public'
assert_directory_exists 'views'
assert_generated_file 'config.ru'
- assert_generated_file 'app.rb'
+ assert_generated_file "#{app_name}.rb"
assert_generated_file 'Rakefile'
assert_generated_file 'config.yml'
assert_generated_module "lib/#{app_name}"

0 comments on commit 6b9f378

Please sign in to comment.