Skip to content

Commit

Permalink
Merge branch 'master' of github.com:padrino/padrino-framework
Browse files Browse the repository at this point in the history
  • Loading branch information
DAddYE committed Oct 17, 2010
2 parents d9acfb1 + a4e128c commit e333ef3
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rdoc
Expand Up @@ -8,6 +8,8 @@
* Correct path in spec [Thanks to Spllr]
* Bypass admin login in development
* Norwegian translation [Thanks to Fossmo]
* Updated generator for new rspec version [Thanks to rosstimson]
* Additional generator for old rspec version

== 0.9.18

Expand Down
Expand Up @@ -79,7 +79,7 @@ def setup_test
create_file destination_root("features/add.feature"), CUCUMBER_FEATURE
create_file destination_root("features/step_definitions/add_steps.rb"), CUCUMBER_STEP
create_file destination_root("cucumber.yml"), CUCUMBER_YML
require_dependencies 'rspec', :require => 'spec', :group => 'test'
require_dependencies 'rspec', :group => 'test'
insert_test_suite_setup RSPEC_SETUP, :path => "spec/spec_helper.rb"
create_file destination_root("spec/spec.rake"), RSPEC_RAKE
end
end
10 changes: 5 additions & 5 deletions padrino-gen/lib/padrino-gen/generators/components/tests/rspec.rb
Expand Up @@ -29,11 +29,11 @@ def app
TEST

RSPEC_RAKE = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_RAKE)
require 'spec/rake/spectask'
require 'rspec/core/rake_task'
Spec::Rake::SpecTask.new(:spec) do |t|
t.spec_files = Dir['spec/**/*_spec.rb']
t.spec_opts = %w(-fs --color)
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = "./spec/**/*_spec.rb"
# Put spec opts in a file named .rspec in root
end
TEST

Expand All @@ -50,7 +50,7 @@ def app

def setup_test
require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
require_dependencies 'rspec', :require => 'spec', :group => 'test'
require_dependencies 'rspec', :group => 'test'
insert_test_suite_setup RSPEC_SETUP, :path => "spec/spec_helper.rb"
create_file destination_root("spec/spec.rake"), RSPEC_RAKE
end
Expand Down
67 changes: 67 additions & 0 deletions padrino-gen/lib/padrino-gen/generators/components/tests/rspec1.rb
@@ -0,0 +1,67 @@
RSPEC_SETUP = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_SETUP)
PADRINO_ENV = 'test' unless defined?(PADRINO_ENV)
require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
Spec::Runner.configure do |conf|
conf.include Rack::Test::Methods
end
def app
##
# You can handle all padrino applications using instead:
# Padrino.application
CLASS_NAME.tap { |app| }
end
TEST

RSPEC_CONTROLLER_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_CONTROLLER_TEST)
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe "!NAME!Controller" do
before do
get "/"
end
it "returns hello world" do
last_response.body.should == "Hello World"
end
end
TEST

RSPEC_RAKE = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_RAKE)
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |t|
t.spec_files = Dir['spec/**/*_spec.rb']
t.spec_opts = %w(-fs --color)
end
TEST

RSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_MODEL_TEST)
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe "!NAME! Model" do
let(:!DNAME!) { !NAME!.new }
it 'can be created' do
!DNAME!.should_not be_nil
end
end
TEST

def setup_test
require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
require_dependencies 'rspec', :version => "~> 1.2.3", :require => 'spec', :group => 'test'
insert_test_suite_setup RSPEC_SETUP, :path => "spec/spec_helper.rb"
create_file destination_root("spec/spec.rake"), RSPEC_RAKE
end

# Generates a controller test given the controllers name
def generate_controller_test(name)
rspec_contents = RSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
create_file destination_root("spec/controllers/#{name.to_s.underscore}_controller_spec.rb"), rspec_contents, :skip => true
end

def generate_model_test(name)
rspec_contents = RSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.to_s.underscore)
create_file destination_root("spec/models/#{name.to_s.underscore}_spec.rb"), rspec_contents, :skip => true
end
2 changes: 1 addition & 1 deletion padrino-gen/lib/padrino-gen/generators/project.rb
Expand Up @@ -31,7 +31,7 @@ def self.banner; "padrino-gen project [name] [options]"; end

# Definitions for the available customizable components
component_option :orm, "database engine", :aliases => '-d', :choices => [:activerecord, :datamapper, :mongomapper, :mongoid, :sequel, :couchrest, :ohm, :mongomatic], :default => :none
component_option :test, "testing framework", :aliases => '-t', :choices => [:rspec, :shoulda, :cucumber, :bacon, :testspec, :riot], :default => :none
component_option :test, "testing framework", :aliases => '-t', :choices => [:rspec1, :rspec, :shoulda, :cucumber, :bacon, :testspec, :riot], :default => :none
component_option :mock, "mocking library", :aliases => '-m', :choices => [:mocha, :rr], :default => :none
component_option :script, "javascript library", :aliases => '-s', :choices => [:jquery, :prototype, :rightjs, :mootools, :extcore, :dojo], :default => :none
component_option :renderer, "template engine", :aliases => '-e', :choices => [:haml, :erb, :erubis, :liquid], :default => :haml
Expand Down
16 changes: 14 additions & 2 deletions padrino-gen/test/test_project_generator.rb
Expand Up @@ -396,13 +396,25 @@ def teardown
assert_file_exists("#{@apptmp}/sample_project/test/test.rake")
end

should "properly generate for rspec1" do
buffer = silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=rspec1', '--script=none') }
assert_match(/Applying.*?rspec.*?test/, buffer)
assert_match_in_file(/gem 'rack-test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:require => "rack\/test"/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:group => "test"/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'rspec'.*?"~>\s*1.2.3".*?:require => "spec"/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
assert_match_in_file(/Spec::Runner/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
assert_file_exists("#{@apptmp}/sample_project/spec/spec.rake")
end

should "properly generate for rspec" do
buffer = silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=rspec', '--script=none') }
assert_match(/Applying.*?rspec.*?test/, buffer)
assert_match_in_file(/gem 'rack-test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:require => "rack\/test"/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:group => "test"/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'rspec'.*?:require => "spec"/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'rspec'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
assert_match_in_file(/Spec::Runner/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
assert_file_exists("#{@apptmp}/sample_project/spec/spec.rake")
Expand Down Expand Up @@ -438,7 +450,7 @@ def teardown
assert_match_in_file(/gem 'rack-test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:require => "rack\/test"/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:group => "test"/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'rspec'.*?:require => "spec"/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'rspec'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'cucumber'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'capybara'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
Expand Down

0 comments on commit e333ef3

Please sign in to comment.