From 1c5e516e7159abd9c26401e0c9bafa658701b560 Mon Sep 17 00:00:00 2001 From: Randy Eppinger Date: Thu, 16 May 2019 17:55:43 -0400 Subject: [PATCH] Added --with_config option --- features/with_config.feature | 25 ++++++++++++ lib/testgen/cli.rb | 4 +- lib/testgen/generators/project.rb | 48 +++++++++++++++-------- lib/testgen/generators/project/Gemfile.tt | 3 ++ lib/testgen/generators/project/env.rb.tt | 3 ++ 5 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 features/with_config.feature diff --git a/features/with_config.feature b/features/with_config.feature new file mode 100644 index 0000000..fba8200 --- /dev/null +++ b/features/with_config.feature @@ -0,0 +1,25 @@ +Feature: Adding the --with_config flag + As a cucumber author + I want FigNewton and a config environment setup + So that I can avoid manually configuring them for every project + + Background: + When I run `testgen project sample --with_config` + + Scenario: Adding the fig_newton gem to Gemfile + Then a file named "sample/Gemfile" should exist + And the file "sample/Gemfile" should contain "gem 'fig_newton'" + + Scenario: Adding fig_newton to env.rb + Then a file named "sample/features/support/env.rb" should exist + And the file "sample/features/support/env.rb" should contain "require 'fig_newton'" + + Scenario: Creating the config set of directories + Then the following directories should exist: + | sample/config | + | sample/config/environments | + + Scenario: Generating the cucumber.yml file in the config folder + Then a file named "sample/config/cucumber.yml" should exist + And a file named "sample/cucumber.yml" should not exist + And the file "sample/config/cucumber.yml" should contain "default: --no-source --color --format pretty" diff --git a/lib/testgen/cli.rb b/lib/testgen/cli.rb index 6ffec68..b29627b 100644 --- a/lib/testgen/cli.rb +++ b/lib/testgen/cli.rb @@ -8,12 +8,14 @@ class CLI < Thor method_option :with_lib, :type => :boolean, :desc => "Place shared objects under lib directory" method_option :with_mohawk, :type => :boolean, :desc => 'Adds support for mohawk gem' method_option :with_appium, :type => :boolean, :desc => 'Add support for appium' + method_option :with_config, :type => :boolean, :desc => 'Add config/environments directories and FigNewton gem' def project(name) with_lib = options[:with_lib] ? 'true' : 'false' with_mohawk = options[:with_mohawk] ? 'true' : 'false' with_appium = options[:with_appium] ? 'true' : 'false' - TestGen::Generators::Project.start([name, with_lib, with_mohawk, with_appium]) + with_config = options[:with_config] ? 'true' : 'false' + TestGen::Generators::Project.start([name, with_lib, with_mohawk, with_appium, with_config]) end end diff --git a/lib/testgen/generators/project.rb b/lib/testgen/generators/project.rb index b520d00..9594de1 100644 --- a/lib/testgen/generators/project.rb +++ b/lib/testgen/generators/project.rb @@ -4,52 +4,64 @@ module TestGen module Generators class Project < Thor::Group include Thor::Actions - + argument :name, :type => :string, :desc => 'The name of the project' argument :with_lib, :type => :string, :desc => 'Place all shared objects in the lib directory' argument :with_mohawk, :type => :string, :desc => 'Add support for the mohawk gem' argument :with_appium, :type => :string, :desc => 'Add support for appium gem' + argument :with_config, :type => :string, :desc => 'Add config/environments directories and FigNewton gem' desc "Generates a project structure for testing with Cucumber" - + def self.source_root File.dirname(__FILE__) + "/project" end - + def create_top_directory empty_directory(name) end - - def copy_cucumber_yml - template "cucumber.yml.tt", "#{name}/cucumber.yml" - end - + def copy_gemfile template "Gemfile.tt", "#{name}/Gemfile" end - + def copy_rakefile copy_file "Rakefile", "#{name}/Rakefile" end - + def create_cucumber_directories empty_directory("#{name}/features") empty_directory("#{name}/features/support") empty_directory("#{name}/features/step_definitions") end - + + def create_config_directories + if gen_config + empty_directory("#{name}/config") + empty_directory("#{name}/config/environments") + end + end + + def copy_cucumber_yml + if gen_config + template "cucumber.yml.tt", "#{name}/config/cucumber.yml" + else + template "cucumber.yml.tt", "#{name}/cucumber.yml" + end + end + def copy_env template "env.rb.tt", "#{name}/features/support/env.rb" end - + def copy_hooks template "hooks.rb.tt", "#{name}/features/support/hooks.rb" if gen_pageobject end - + def create_lib_directory empty_directory("#{name}/lib") if gen_lib end - + def create_pages_directory if gen_lib empty_directory("#{name}/lib/pages") if gen_pageobject @@ -59,16 +71,20 @@ def create_pages_directory empty_directory("#{name}/features/support/screens") unless gen_pageobject end end - + private def gen_pageobject with_mohawk == 'false' && with_appium == 'false' end - + def gen_lib with_lib == 'true' end + + def gen_config + with_config == 'true' + end end end end diff --git a/lib/testgen/generators/project/Gemfile.tt b/lib/testgen/generators/project/Gemfile.tt index 6ee8278..efb6dfa 100644 --- a/lib/testgen/generators/project/Gemfile.tt +++ b/lib/testgen/generators/project/Gemfile.tt @@ -7,6 +7,9 @@ gem 'rake' gem 'page-object', '~> 2.0' gem 'data_magic' <% end -%> +<% if with_config =='true' -%> +gem 'fig_newton' +<% end -%> <% if with_lib == 'true' or with_appium == 'true' -%> gem 'require_all' <% end -%> diff --git a/lib/testgen/generators/project/env.rb.tt b/lib/testgen/generators/project/env.rb.tt index cc6cec9..c325693 100644 --- a/lib/testgen/generators/project/env.rb.tt +++ b/lib/testgen/generators/project/env.rb.tt @@ -7,6 +7,9 @@ require 'rspec' require 'page-object' require 'data_magic' <% end -%> +<% if with_config == 'true' -%> +require 'fig_newton' +<% end -%> <% if with_mohawk == 'true' -%> require 'mohawk' require 'win32/screenshot'