Skip to content

Commit

Permalink
steak generator written, tests a work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
ethnt authored and namusyaka committed Oct 15, 2013
1 parent 3e551c9 commit c504790
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
93 changes: 93 additions & 0 deletions padrino-gen/lib/padrino-gen/generators/components/tests/steak.rb
@@ -0,0 +1,93 @@
STEAK_SETUP = (<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_SETUP)
PADRINO_ENV = 'test' unless defined?(PADRINO_ENV)
require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
RSpec.configure do |conf|
conf.include Rack::Test::Methods
conf.include Capybara
end
def app
##
# You can handle all padrino applications using instead:
# Padrino.application
CLASS_NAME.tap { |app| }
end
Capybara.app = app
TEST

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

STEAK_CONTROLLER_ACCEPTANCE_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_CONTROLLER_ACCEPTANCE_TEST)
require 'spec_helper'
feature "!NAME!Controller" do
background do
visit "/"
end
scenario "returns hello world" do
page.should.have_content == "Hello World"
end
end
TEST

STEAK_RAKE = (<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_RAKE)
require 'rspec/core/rake_task'
spec_tasks = Dir['spec/*/'].map { |d| File.basename(d) }
spec_tasks.each do |folder|
RSpec::Core::RakeTask.new("spec:\#{folder}") do |t|
t.pattern = "./spec/\#{folder}/**/*_spec.rb"
t.rspec_opts = %w(-fs --color)
end
end
desc "Run complete application spec suite"
task 'spec' => spec_tasks.map { |f| "spec:\#{f}" }
TEST

STEAK_MODEL_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_MODEL_TEST)
require 'spec_helper'
describe !NAME! do
end
TEST

def setup_test
require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
require_dependencies 'steak', :group => 'test'
insert_test_suite_setup STEAK_SETUP, :path => "spec/spec_helper.rb"
create_file destination_root("spec/spec.rake"), STEAK_RAKE
end

# Generates a controller test given the controllers name
def generate_controller_test(name)
spec_contents = STEAK_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
controller_spec_path = File.join('spec',options[:app],'controllers',"#{name.to_s.underscore}_controller_spec.rb")
create_file destination_root(controller_spec_path), spec_contents, :skip => true

acceptance_contents = STEAK_CONTROLLER_ACCEPTANCE_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
controller_acceptance_path = File.join('spec',options[:app],'acceptance','controllers',"#{name.to_s.underscore}_controller_spec.rb")
create_file destination_root(controller_acceptance_path), acceptance_contents, :skip => true
end

def generate_model_test(name)
rspec_contents = STEAK_MODEL_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize).gsub(/!DNAME!/, name.to_s.underscore)
model_spec_path = File.join('spec',options[:app],'models',"#{name.to_s.underscore}_spec.rb")
create_file destination_root(model_spec_path), rspec_contents, :skip => true
end
8 changes: 8 additions & 0 deletions padrino-gen/test/test_controller_generator.rb
Expand Up @@ -140,6 +140,14 @@ def teardown
assert_file_exists("#{@apptmp}/sample_project/test/subby/controllers/demo_items_controller_test.rb")
end

should "generate controller test for steak" do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=steak') }
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
assert_match_in_file(/describe "DemoItemsController" do/m, "#{@apptmp}/sample_project/spec/subby/controllers/demo_items_controller_spec.rb")
assert_match_in_file(/feature "DemoItemsController" do/m, "#{@apptmp}/sample_project/spec/subby/acceptance/controllers/demo_items_controller_spec.rb")
end

should "generate controller test for cucumber" do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=cucumber') }
capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
Expand Down
14 changes: 14 additions & 0 deletions padrino-gen/test/test_project_generator.rb
Expand Up @@ -557,6 +557,20 @@ def teardown
assert_match_in_file(/task 'test' => test_tasks/,"#{@apptmp}/sample_project/test/test.rake")
end

should "properly generate for steak" do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=steak', '--script=none') }
assert_match(/applying.*?steak.*?test/, out)
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 'steak'/, "#{@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(/RSpec.configure/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
assert_file_exists("#{@apptmp}/sample_project/spec/spec.rake")
assert_match_in_file(/RSpec::Core::RakeTask\.new\("spec:\#/,"#{@apptmp}/sample_project/spec/spec.rake")
assert_match_in_file(/task 'spec' => spec_tasks/,"#{@apptmp}/sample_project/spec/spec.rake")
end

should "properly generate for minitest" do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=minitest', '--script=none') }
assert_match(/applying.*?minitest.*?test/, out)
Expand Down

0 comments on commit c504790

Please sign in to comment.