Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added --with_config option #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions features/with_config.feature
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 3 additions & 1 deletion lib/testgen/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 32 additions & 16 deletions lib/testgen/generators/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 3 additions & 0 deletions lib/testgen/generators/project/Gemfile.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand Down
3 changes: 3 additions & 0 deletions lib/testgen/generators/project/env.rb.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down