Given 'a working directory' do @working_dir = File.expand_path File.join(File.dirname(__FILE__), '..', '..', 'tmp') FileUtils.rm_rf @working_dir FileUtils.mkdir_p @working_dir end When /^I use the gigantron command to generate a project named "([^\"]*)"$/ do |name| @project_name = name @project_dir = File.join(@working_dir,@project_name) return_to = Dir.pwd gigantron = File.expand_path File.join(File.dirname(__FILE__), '..', '..', 'bin', 'gigantron') begin FileUtils.cd @working_dir @stdout = `#{gigantron} #{@project_name}` ensure FileUtils.cd return_to end end When /^I use script\/generate to make a (.+) named "([^\"]*)"$/ do |type,created| return_to = Dir.pwd begin FileUtils.cd(@project_dir) @stdout = `script/generate #{type} #{created}` ensure FileUtils.cd return_to end end When /^I configure an sqlite3 database named "([^\"]*)"$/ do |name| file = File.expand_path(File.join(@project_dir,'db','db.sqlite3')) File.open(File.join(@project_dir,'database.yml'),'w') do |out| out.puts ":real:" out.puts " :adapter: sqlite3" out.puts " :database: #{file}" out.puts ":test:" out.puts " :adapter: sqlite3" out.puts " :database: #{file}" end end When /^I create simple migration for the model "([^\"]*)"$/ do |name| migration = Dir.glob("#{@project_dir}/db/migrate/*_create_#{name}s.rb").first File.open(migration,'w') do |f| f.puts <<-EOF class Create#{name.pluralize.camelcase} < ActiveRecord::Migration def self.up create_table :#{name.pluralize} do |t| t.string :name end end def self.down end end EOF end end When /^I use rake to migrate the database up$/ do FileUtils.cd(@project_dir) do @stdout = `rake db:migrate` end end When /^I create (\d) "([^\"]*)" records in the database$/ do |number, type| require File.join(@project_dir,'initialize.rb') get_db_conn(:real) number.to_i.times do Kernel.const_get(type.camelize).create :name => 'test' end end Then /^a directory named "([^\"]*)" is created$/ do |directory| directory = File.join(@working_dir, directory) assert File.exists?(directory), "#{directory} did not exist" assert File.directory?(directory), "#{directory} is not a directory" end Then /^a file named "([^\"]*)" is created$/ do |file| file = File.join(@working_dir, file) assert File.exists?(file), "#{file} did not exist" assert !File.directory?(file), "#{file} is a directory" end Then /^(\d) "([^\"]*)" records are saved to the database$/ do |number, type| require File.join(@project_dir,'initialize.rb') get_db_conn(:real) assert Kernel.const_get(type.camelize).count == number.to_i end Then /^calling the rake "([^\"]*)" task should not produce an error$/ do |task_name| FileUtils.cd(@project_dir) do @sucessful = system("rake #{task_name}") end assert @sucessful end After do FileUtils.rm_rf @working_dir if @working_dir end