module FWToolkit module Tasks class Frank < Thor include Rake::DSL if defined?(Rake::DSL) include Thor::Actions def self.source_root File.join(File.dirname(__FILE__), '..', '..', '..') end no_tasks do def install_tasks namespace :frank do desc 'Setup Frank' task :setup, [:target, :prefix] do |t, args| args.with_defaults(:prefix => '') setup(args[:target], args[:prefix]) end desc 'Create Frank model files from CoreData' task :model, [:model_file, :prefix] do |t, args| args.with_defaults(:model_file => nil) args.with_defaults(:prefix => 'true') prefix = args[:prefix].eql? 'true' @no_prefix = !prefix # validation step - core_data_model should be of type .xcdatamodel output_dir = File.join('Frank', 'features', 'support', 'models') makedirs output_dir unless Dir.exists? output_dir model = CoreData::DataModel.new(File.join(args[:model_file], 'contents')) @models = model.entities @models.each do |entity| @model = entity @class_name = class_name(@model) factory_template = File.join 'templates', 'models', 'model.rb.erb' template(factory_template, File.join(output_dir, "#{class_name(@model).ruby_format}.rb")) end factory_template = File.join 'templates', 'models', 'factories.rb.erb' template(factory_template, File.join(output_dir, 'factories.rb')) end Cucumber::Rake::Task.new(:ci_test, 'Run Frank acceptance tests with CI options') do |t| ENV['APP_BUNDLE_PATH'] = File.join( Dir.pwd, 'Frank/frankified_build/Frankified.app' ) ENV['USE_SIM_LAUNCHER_SERVER'] = 'YES' artifacts_dir = ENV['CC_BUILD_ARTIFACTS'] ? ENV['CC_BUILD_ARTIFACTS'] : '/tmp' t.cucumber_opts = "Frank/features --tags ~@wip --format pretty --format html --out '#{artifacts_dir}/frank_results.html' --format rerun --out '#{artifacts_dir}/frank_rerun.txt'" end desc 'Run Frank acceptance tests' task :test, :cucumber_options do |t, args| args.with_defaults(:cucumber_options => 'Frank/features --tag ~@wip') ENV['APP_BUNDLE_PATH'] = File.join( Dir.pwd, 'Frank/frankified_build/Frankified.app' ) ENV['USE_SIM_LAUNCHER_SERVER'] = nil run "cucumber #{args.cucumber_options}" end desc 'Run Frank acceptance tests for a tag' task :tag, :tag_name do |t, args| args.with_defaults(:tag_name => '') cucumber_options = "Frank/features --tag #{args.tag_name}" ENV['APP_BUNDLE_PATH'] = File.join( Dir.pwd, 'Frank/frankified_build/Frankified.app' ) ENV['USE_SIM_LAUNCHER_SERVER'] = nil run "cucumber #{cucumber_options}" end end end def class_name(entity) @no_prefix ? entity.name : entity.name[3..-1] end def setup(target = nil, prefix = nil, project_directory = target, project_file = "#{target}.xcodeproj") run 'frank setup' features_dir = File.join('Frank', 'features') remove_file(File.join(features_dir, 'my_first.feature')) if target test_dir = File.join(FWToolkit::Tasks::BuildTask::TEMPLATES_DIR, 'cucumber') directory(File.join(FWToolkit::Tasks::BuildTask::TEMPLATES_DIR, 'cucumber', 'features'), features_dir, {:force => true}) @prefix = prefix template 'templates/cucumber/AppDelegate+Frank.h.erb', File.join(project_directory, "#{prefix}AppDelegate+Frank.h") template 'templates/cucumber/AppDelegate+Frank.m.erb', File.join(project_directory, "#{prefix}AppDelegate+Frank.m") project = Xcodeproj::Project.new(project_file) project.new_file(File.join(project_directory, "#{prefix}AppDelegate+Frank.h"), project_directory) frank_app_d_m = project.new_file(File.join(project_directory, "#{prefix}AppDelegate+Frank.m"), project_directory) target = project.targets.select{|t| t.name.eql? target}[0] target.add_file_references([frank_app_d_m]) project.save_as(project_file) end end end end end end