SimpliTest 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +22 -0
- data/SimpliTest.gemspec +42 -0
- data/bin/SimpliTest +22 -0
- data/lib/SimpliTest.rb +2 -0
- data/lib/SimpliTest/cli/main.rb +305 -0
- data/lib/SimpliTest/config/configuration.rb +107 -0
- data/lib/SimpliTest/config/directory_paths.rb +36 -0
- data/lib/SimpliTest/config/environment.rb +67 -0
- data/lib/SimpliTest/config/local_environment.rb +20 -0
- data/lib/SimpliTest/config/profiles/chrome.rb +18 -0
- data/lib/SimpliTest/config/profiles/firefox.rb +14 -0
- data/lib/SimpliTest/config/profiles/internet_explorer.rb +12 -0
- data/lib/SimpliTest/config/profiles/phantom.rb +9 -0
- data/lib/SimpliTest/config/profiles/phantom_debug.rb +12 -0
- data/lib/SimpliTest/config/profiles/selenium.rb +13 -0
- data/lib/SimpliTest/config/screen_size.rb +25 -0
- data/lib/SimpliTest/config/steps.rb +8 -0
- data/lib/SimpliTest/helpers/data_validation.rb +60 -0
- data/lib/SimpliTest/helpers/file.rb +38 -0
- data/lib/SimpliTest/helpers/project_setup.rb +186 -0
- data/lib/SimpliTest/helpers/step_helpers/custom_chrome_helpers.rb +14 -0
- data/lib/SimpliTest/helpers/step_helpers/custom_date_helpers.rb +64 -0
- data/lib/SimpliTest/helpers/step_helpers/custom_form_helpers.rb +66 -0
- data/lib/SimpliTest/helpers/step_helpers/custom_phantomjs_helpers.rb +49 -0
- data/lib/SimpliTest/helpers/step_helpers/custom_selenium_helpers.rb +41 -0
- data/lib/SimpliTest/helpers/step_helpers/html_selectors_helpers.rb +154 -0
- data/lib/SimpliTest/helpers/step_helpers/navigation_helpers.rb +196 -0
- data/lib/SimpliTest/helpers/step_helpers/tolerance_for_sync_issues.rb +38 -0
- data/lib/SimpliTest/helpers/step_helpers/within_helpers.rb +6 -0
- data/lib/SimpliTest/helpers/windows_ui.rb +52 -0
- data/lib/SimpliTest/steps/debugging_steps.rb +19 -0
- data/lib/SimpliTest/steps/form_steps.rb +352 -0
- data/lib/SimpliTest/steps/form_verification_steps.rb +190 -0
- data/lib/SimpliTest/steps/navigation_steps.rb +47 -0
- data/lib/SimpliTest/steps/scoper.rb +42 -0
- data/lib/SimpliTest/steps/verification_steps.rb +306 -0
- data/lib/SimpliTest/tasks/document.rb +169 -0
- data/lib/SimpliTest/tasks/examples.rb +18 -0
- data/lib/SimpliTest/tasks/internal_release.rb +39 -0
- data/lib/SimpliTest/tasks/testinstall.rb +5 -0
- data/lib/SimpliTest/templates/NewSimpliTestProject/Readme.txt +5 -0
- data/lib/SimpliTest/templates/NewSimpliTestProject/cucumber.yml +26 -0
- data/lib/SimpliTest/templates/NewSimpliTestProject/documentation/step_definitions.html +87 -0
- data/lib/SimpliTest/templates/NewSimpliTestProject/features/specifications/RegressionTests/HelloWorld.feature +4 -0
- data/lib/SimpliTest/templates/NewSimpliTestProject/features/specifications/SmokeTest/HelloWorld.feature +4 -0
- data/lib/SimpliTest/templates/NewSimpliTestProject/features/specifications/accessibilityTests/HelloWorld.feature +4 -0
- data/lib/SimpliTest/templates/NewSimpliTestProject/features/support/config/environments.yml +11 -0
- data/lib/SimpliTest/templates/NewSimpliTestProject/features/support/config/pages.yml +26 -0
- data/lib/SimpliTest/templates/NewSimpliTestProject/features/support/config/selectors.yml +44 -0
- data/lib/SimpliTest/templates/NewSimpliTestProject/features/support/config/settings.yml +26 -0
- data/lib/SimpliTest/templates/NewSimpliTestProject/features/support/env.rb +33 -0
- data/lib/SimpliTest/templates/NewSimpliTestProject/license.txt +30 -0
- data/lib/SimpliTest/templates/document/css/style.css +28 -0
- data/lib/SimpliTest/templates/document/index.html +60 -0
- data/lib/version.rb +3 -0
- metadata +395 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'pathname'
|
3
|
+
require 'SimpliTest/helpers/project_setup'
|
4
|
+
# exports instance variables for various directories of interest in the gem and the satelite projects
|
5
|
+
module SimpliTest
|
6
|
+
extend ProjectSetupHelpers
|
7
|
+
@config_dir = File.dirname(__FILE__)
|
8
|
+
@SimpliTest_dir = Pathname.new( @config_dir).parent.to_s
|
9
|
+
@helpers_dir = File.join(@SimpliTest_dir, 'helpers')
|
10
|
+
@steps_dir = File.join(@SimpliTest_dir, 'steps')
|
11
|
+
@step_helpers_dir = File.join(@helpers_dir, 'step_helpers')
|
12
|
+
@templates_dir = File.join(@SimpliTest_dir, 'templates')
|
13
|
+
@lib_dir = Pathname.new(@SimpliTest_dir).parent.to_s
|
14
|
+
@tasks_dir = File.join(@SimpliTest_dir, 'tasks')
|
15
|
+
@gem_dir = Pathname.new(@lib_dir).parent.to_s
|
16
|
+
class << self
|
17
|
+
#TODO: Using method missing despite all the reasons not to
|
18
|
+
#FIXME: Get rid of this
|
19
|
+
def method_missing(meth, *args, &block)
|
20
|
+
if match = meth.to_s.match(/^config_(.+)$/)
|
21
|
+
config[match[1].to_sym]
|
22
|
+
elsif match = meth.to_s.match(/^path_to_(.+)$/)
|
23
|
+
instance_variable_get("@#{match[1]}")
|
24
|
+
else
|
25
|
+
super # You *must* call super if you don't handle the
|
26
|
+
# method, otherwise you'll mess up Ruby's method
|
27
|
+
# lookup.
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def respond_to_missing?(method_name, include_private = false)
|
32
|
+
method_name.to_s.start_with?('config_') || meth.to_s.start_with?('path_to_') || super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'capybara'
|
2
|
+
require 'capybara/cucumber'
|
3
|
+
require 'capybara/dsl'
|
4
|
+
require 'rspec'
|
5
|
+
require "nokogiri"
|
6
|
+
require 'open-uri'
|
7
|
+
require_relative './local_environment'
|
8
|
+
require_relative './screen_size'
|
9
|
+
require_relative './steps'
|
10
|
+
require File.join(SimpliTest.path_to_helpers_dir, 'project_setup')
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.include Capybara::DSL
|
13
|
+
end
|
14
|
+
|
15
|
+
Capybara.save_and_open_page_path = File.expand_path(File.join(SimpliTest.config_support_directory,'../../tmp')) if SimpliTest.config[:support_directory]
|
16
|
+
Capybara.default_max_wait_time = 2
|
17
|
+
|
18
|
+
driver = SimpliTest.driver #default is selenium
|
19
|
+
profiles_dir = File.join(File.dirname(__FILE__), 'profiles')
|
20
|
+
profiles = {
|
21
|
+
'phantomjs' => 'phantom',
|
22
|
+
'phantom_debug' => 'phantom_debug',
|
23
|
+
'chrome' => 'chrome',
|
24
|
+
'selenium' => 'selenium',
|
25
|
+
'ie' => 'internet_explorer',
|
26
|
+
'fire' => 'firefox'
|
27
|
+
}
|
28
|
+
profile = File.join profiles_dir, profiles[driver]
|
29
|
+
require profile
|
30
|
+
puts "Loaded Environment"
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
#Leave the window open after a test fails if this tag is provided
|
35
|
+
After('@leave_the_window_open') do |scenario|
|
36
|
+
if scenario.respond_to?(:status) && scenario.status == :failed
|
37
|
+
print "Step Failed. Press Return to close browser"
|
38
|
+
STDIN.getc
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Before do |s|
|
43
|
+
# if SimpliTest.env_or_setting('JIRA_INTEGRATION_ENABLED') && SimpliTest.env_or_setting('JIRA_URL')
|
44
|
+
# $has_jira_info ||= false
|
45
|
+
# return $has_jira_info if $has_jira_info
|
46
|
+
# $jira = SimpliTest::JiraIntegration.load_project_details
|
47
|
+
# $has_jira_info = true
|
48
|
+
# end
|
49
|
+
end
|
50
|
+
|
51
|
+
After do |s|
|
52
|
+
|
53
|
+
#Reuse Browser sessions
|
54
|
+
if SimpliTest.config[:settings]['REUSE_BROWSER_SESSIONS']
|
55
|
+
Capybara.current_session.instance_variable_set('@touched', !SimpliTest.config[:settings]['REUSE_BROWSER_SESSIONS'])
|
56
|
+
else
|
57
|
+
Capybara.current_session.instance_variable_set('@touched', true)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Tell Cucumber to quit after this scenario is done - if it failed.
|
61
|
+
#Cucumber.wants_to_quit = true if SimpliTest.config[:settings][QUIT_ON_FAIL] && s.failed?
|
62
|
+
#zephyr_reporter = SimpliTest::JiraIntegration.new(s)
|
63
|
+
#zephyr_reporter.report
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SimpliTest
|
2
|
+
def self.gems_installed?(list)
|
3
|
+
specs = []
|
4
|
+
list.each do |gem|
|
5
|
+
dep = Gem::Dependency.new(gem)
|
6
|
+
specs << !dep.matching_specs.empty?
|
7
|
+
end
|
8
|
+
specs.uniq == [true]
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.chromedriver_detected?
|
12
|
+
installed = `chromedriver --help` rescue false
|
13
|
+
installed ? true : false
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.env_or_setting(setting_name)
|
17
|
+
ENV[setting_name] || SimpliTest.config_settings[setting_name]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
if SimpliTest.chromedriver_detected?
|
2
|
+
require 'selenium/webdriver'
|
3
|
+
Capybara.register_driver :chrome do |app|
|
4
|
+
Capybara::Selenium::Driver.new(app, :browser => :chrome)
|
5
|
+
end
|
6
|
+
|
7
|
+
Before do
|
8
|
+
Capybara.current_driver = :chrome
|
9
|
+
Capybara.javascript_driver = :chrome
|
10
|
+
end
|
11
|
+
|
12
|
+
World(CustomSeleniumHelpers)
|
13
|
+
World(CustomChromeHelpers)
|
14
|
+
else
|
15
|
+
alert "Could not find ChromeDriver. Please make sure it is installed and try again"
|
16
|
+
end
|
17
|
+
|
18
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
Capybara.register_driver :firefox do |app|
|
3
|
+
require 'selenium/webdriver'
|
4
|
+
profile = Selenium::WebDriver::Firefox::Profile.new
|
5
|
+
profile.native_events = true
|
6
|
+
Capybara::Selenium::Driver.new(app, :browser => :firefox)
|
7
|
+
end
|
8
|
+
|
9
|
+
Before do
|
10
|
+
Capybara.current_driver = :firefox
|
11
|
+
SimpliTest.driver = 'firefox'
|
12
|
+
end
|
13
|
+
|
14
|
+
World(CustomSeleniumHelpers)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
Capybara.register_driver :internet_explorer do |app|
|
3
|
+
require 'selenium/webdriver'
|
4
|
+
Capybara::Selenium::Driver.new(app, :browser => :internet_explorer)
|
5
|
+
end
|
6
|
+
|
7
|
+
Before do
|
8
|
+
Capybara.current_driver = :internet_explorer
|
9
|
+
SimpliTest.driver = 'internet_explorer'
|
10
|
+
end
|
11
|
+
|
12
|
+
World(CustomSeleniumHelpers)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'capybara/poltergeist'
|
2
|
+
Capybara.register_driver :poltergeist_debug do |app|
|
3
|
+
Capybara::Poltergeist::Driver.new(app, :inspector => true)
|
4
|
+
end
|
5
|
+
|
6
|
+
Before do
|
7
|
+
Capybara.current_driver = :poltergeist_debug
|
8
|
+
Capybara.javascript_driver = :poltergeist_debug
|
9
|
+
SimpliTest.driver = 'poltergeist'
|
10
|
+
end
|
11
|
+
|
12
|
+
World(CustomPhantomjsHelpers)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Capybara.register_driver :selenium do |app|
|
2
|
+
require 'selenium/webdriver'
|
3
|
+
profile = Selenium::WebDriver::Firefox::Profile.new
|
4
|
+
profile.native_events = true
|
5
|
+
Capybara::Selenium::Driver.new(app, :browser => :firefox, profile: profile)
|
6
|
+
end
|
7
|
+
|
8
|
+
Before do
|
9
|
+
Capybara.current_driver = :selenium
|
10
|
+
SimpliTest.driver = 'selenium'
|
11
|
+
end
|
12
|
+
|
13
|
+
World(CustomSeleniumHelpers)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
desktop_max_height = SimpliTest.config[:settings]["DESKTOP_MAX_HEIGHT"] || 980
|
3
|
+
desktop_max_width = SimpliTest.config[:settings]["DESKTOP_MAX_WIDTH"] || 1045
|
4
|
+
mobile_max_height = SimpliTest.config[:settings]["MOBILE_MAX_HEIGHT"] || 868
|
5
|
+
mobile_max_width = SimpliTest.config[:settings]["MOBILE_MAX_WIDTH"] || 362
|
6
|
+
tablet_max_height= SimpliTest.config[:settings]["TABLET_MAX_HEIGHT"] || 868
|
7
|
+
tablet_max_width = SimpliTest.config[:settings]["TABLET_MAX_WIDTH"] || 814
|
8
|
+
landscape_max_height = SimpliTest.config[:settings]["LANDSCAPE_MAX_HEIGHT"] || 362
|
9
|
+
landscape_max_width = SimpliTest.config[:settings]["LANDSCAPE_MAX_WIDTH"] || 522
|
10
|
+
|
11
|
+
|
12
|
+
case SimpliTest.screen_size
|
13
|
+
when "Mobile"
|
14
|
+
MAX_HEIGHT = mobile_max_height
|
15
|
+
MAX_WIDTH = mobile_max_width
|
16
|
+
when "Tablet"
|
17
|
+
MAX_HEIGHT = tablet_max_height
|
18
|
+
MAX_WIDTH = tablet_max_width
|
19
|
+
when "Desktop"
|
20
|
+
MAX_HEIGHT = desktop_max_height
|
21
|
+
MAX_WIDTH = desktop_max_width
|
22
|
+
when "Landscape"
|
23
|
+
MAX_HEIGHT = landscape_max_height
|
24
|
+
MAX_WIDTH = landscape_max_width
|
25
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'erb'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'net/http'
|
5
|
+
# monkey patching Hash for an intersection method
|
6
|
+
class Hash
|
7
|
+
def &(other)
|
8
|
+
reject { |k, v| !(other.include?(k) && other[k] == v) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
module SimpliTest
|
14
|
+
module DataValidationHelpers
|
15
|
+
def validate_service_against(db, service_dir, variables)
|
16
|
+
require File.join(service_dir, 'mapper')
|
17
|
+
#TODO: Horrible hard coding temporarily...will fix later
|
18
|
+
SimpliTest.configure( {:support_directory => File.join(@project_path, 'features', 'support')})
|
19
|
+
@service_dir = service_dir
|
20
|
+
query_results = get_data_from_db(db, variables)
|
21
|
+
if defined?(map_service_results)
|
22
|
+
service_results = map_service_results(get_data_from_service(variables))
|
23
|
+
query_results.each_with_index do |result, index|
|
24
|
+
if result & service_results[index] == service_results[index]
|
25
|
+
puts "Passed"
|
26
|
+
else
|
27
|
+
raise "Test Failed for #{service_results[index]}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
else
|
31
|
+
raise "It seems you have not defined a mapper for this service yet!"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_data_from_db(db, variables)
|
36
|
+
query = preprocess_template('query.sql', variables)
|
37
|
+
db.execute query
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_data_from_service(variables)
|
41
|
+
service = YAML.load(preprocess_template('service.yml', variables))
|
42
|
+
service_path = service['url']
|
43
|
+
uri = service_url_for service_path
|
44
|
+
JSON.parse Net::HTTP.get(uri)
|
45
|
+
end
|
46
|
+
|
47
|
+
def preprocess_template(file, variables)
|
48
|
+
template = File.read(File.join(@service_dir, file))
|
49
|
+
ERB.new(template).result(OpenStruct.new(variables).instance_eval { binding })
|
50
|
+
end
|
51
|
+
|
52
|
+
def service_url_for(path)
|
53
|
+
uri = URI.parse(path)
|
54
|
+
service_host = SimpliTest.config[:environments][SimpliTest.config_environment + "_Services"]
|
55
|
+
service_host = SimpliTest.config[:environments][SimpliTest.config_environment] unless service_host
|
56
|
+
uri.absolute? ? uri : URI.parse(service_host + path)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module FileHelpers
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
def make_directory(dirname)
|
5
|
+
FileUtils.mkdir_p(dirname)
|
6
|
+
end
|
7
|
+
|
8
|
+
def copy_file(source, target)
|
9
|
+
FileUtils.cp(source, target)
|
10
|
+
end
|
11
|
+
|
12
|
+
def copy_folder(source, target)
|
13
|
+
FileUtils.copy_entry(source, target)
|
14
|
+
end
|
15
|
+
|
16
|
+
def make_subdirectories_in(directory, *subdirectories)
|
17
|
+
subdirectories.each do |subdir|
|
18
|
+
FileUtils.mkdir_p(File.join(directory, subdir))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def template_path_to(*args)
|
23
|
+
relative_path = args.join(File::Separator)
|
24
|
+
File.join(SimpliTest.path_to_templates_dir, relative_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def copy_file_with_replacement_args(template_name, target_location, args={})
|
28
|
+
file = File.open(template_path_to(template_name))
|
29
|
+
content = file.read
|
30
|
+
target_location = File.join(@pwd, template_name) unless target_location
|
31
|
+
args.each do |key, value|
|
32
|
+
content = content.gsub(/#{key}/,value )
|
33
|
+
end
|
34
|
+
File.open(target_location, 'w') { |f| f.write(content) }
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
module ProjectSetupHelpers
|
2
|
+
|
3
|
+
#*****************************REQUIRES/INCLUDE/EXTEND******************************************
|
4
|
+
require 'rbconfig'
|
5
|
+
require File.join(File.dirname(__FILE__), 'file.rb')
|
6
|
+
require File.join(File.dirname(__FILE__), 'windows_ui.rb')
|
7
|
+
|
8
|
+
def self.included klass #always include FileHelpers/WindowsUIHelpers with this module
|
9
|
+
klass.class_eval do
|
10
|
+
include FileHelpers
|
11
|
+
include WindowsUIHelpers
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.extended klass #always extend FileHelpers/WindowsUIHelpers with this module
|
16
|
+
klass.class_eval do
|
17
|
+
extend FileHelpers
|
18
|
+
extend WindowsUIHelpers
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
#**********************************PLATFORM****************************************************
|
23
|
+
|
24
|
+
def windows?
|
25
|
+
@windows = RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
26
|
+
end
|
27
|
+
|
28
|
+
#**********************************PROJECT******************************************************
|
29
|
+
|
30
|
+
|
31
|
+
#TODO: Need a massive fix...some of this stuff isn't even right...
|
32
|
+
#We shouldnt just be taking the last features directory in path...this could be a big problem
|
33
|
+
def project_path_for(directory)
|
34
|
+
project_not_found unless project_exists_in?(directory)
|
35
|
+
@project_path = directory if @features_sub_dir_exists
|
36
|
+
@project_path = File.expand_path('..', directory) if @is_in_the_same_dir_as_features
|
37
|
+
@project_path = last_features_dir_in_path if (@feature_files_exist || @index_of_features_dir_in_path)
|
38
|
+
if @project_path
|
39
|
+
return @project_path
|
40
|
+
else
|
41
|
+
project_not_found
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def project_exists_in?(directory)
|
46
|
+
# see if current_dir == features
|
47
|
+
# see if current_dir.sub_dir.include?(features)
|
48
|
+
# see if parent_dir == features
|
49
|
+
# see if parent_dir == features/support features/specifications
|
50
|
+
# see if parent_dir == features/support/config
|
51
|
+
# see if parent_dir == features/support/config/selectors.yml
|
52
|
+
# see if sibling_dir == features example: project/documentation and project/features
|
53
|
+
@directory ||= directory
|
54
|
+
features_sub_dir_exists_in? ||
|
55
|
+
is_in_the_same_dir_as_features? ||
|
56
|
+
feature_files_exist_in? ||
|
57
|
+
is_a_nested_subdirectory_of_features?
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
def project_not_found
|
63
|
+
alert "Could not find the project. Try running this from the main project directory that has the features directory in it"
|
64
|
+
raise "Project Not Found Error"
|
65
|
+
end
|
66
|
+
|
67
|
+
def features_sub_dir_exists_in?(directory=@directory)
|
68
|
+
@features_sub_dir_exists = has_sub_dir?(directory, 'features')
|
69
|
+
end
|
70
|
+
|
71
|
+
def has_sub_dir?(dir, sub_dir)
|
72
|
+
file = File.join(dir, sub_dir)
|
73
|
+
File.directory? file
|
74
|
+
end
|
75
|
+
|
76
|
+
def feature_files_exist_in?(dir=@directory)
|
77
|
+
@feature_files_exist = Dir[File.join(dir, '*.feature')].any?
|
78
|
+
end
|
79
|
+
|
80
|
+
def is_a_nested_subdirectory_of_features?(directory=@directory)
|
81
|
+
@index_of_features_dir_in_path = directories_in_path(directory).rindex('features')
|
82
|
+
end
|
83
|
+
|
84
|
+
def last_features_dir_in_path(directory=@directory)
|
85
|
+
directories = directories_in_path(directory)
|
86
|
+
index = @index_of_features_dir_in_path || is_a_nested_subdirectory_of_features?(directory)
|
87
|
+
File.expand_path directories[0,index].join(File::SEPARATOR)
|
88
|
+
end
|
89
|
+
|
90
|
+
def directories_in_path(directory=@directory)
|
91
|
+
@directories_in_path = directory.split(File::SEPARATOR)
|
92
|
+
end
|
93
|
+
|
94
|
+
def feature_dir_for(dir=@directory)
|
95
|
+
index = is_a_nested_subdirectory_of_features?(dir)
|
96
|
+
raise "Invalid Project. It seems your feature is not part of a proper project" unless index
|
97
|
+
directories_in_path(dir)[0,index].join(File::SEPARATOR)
|
98
|
+
end
|
99
|
+
|
100
|
+
def is_in_the_same_dir_as_features?(directory=@directory)
|
101
|
+
parent = File.expand_path('..', directory)
|
102
|
+
@is_in_the_same_dir_as_features = features_sub_dir_exists_in?(parent)
|
103
|
+
end
|
104
|
+
|
105
|
+
#*****************************USER ALERTS/CONFIRMATION************************************************
|
106
|
+
|
107
|
+
def alert(message)
|
108
|
+
windows? ? user_informed_via_prompt?(message) : puts(message)
|
109
|
+
end
|
110
|
+
|
111
|
+
def user_consents?
|
112
|
+
question = initialization_message + "\nThis will create new files and folders in the current directory. \nWould you still like to proceed?(Y/n)"
|
113
|
+
windows? ? user_consents_via_prompt?(question) : user_consents_via_console?(question)
|
114
|
+
end
|
115
|
+
|
116
|
+
def user_consents_via_console?(question)
|
117
|
+
STDOUT.puts question
|
118
|
+
response = STDIN.gets.strip
|
119
|
+
%w[y yes].include?(response.downcase)
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
#*****************************TEMPLATES****************************************************
|
124
|
+
|
125
|
+
def get_templates_from(*directories)
|
126
|
+
templates = []
|
127
|
+
directories.each do |dir|
|
128
|
+
templates << templates_in(dir)
|
129
|
+
end
|
130
|
+
templates = templates.flatten
|
131
|
+
templates = templates.select { |f| File.file?(f) } #only select files, ignore directories
|
132
|
+
templates
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
def relative_path_for(template)
|
137
|
+
path = template.gsub("#{@templates_dir}/features", '')
|
138
|
+
path = File.join(@features_dir, path)
|
139
|
+
path = File.join(Pathname.new(File.expand_path(@features_dir)).parent.to_s, 'cucumber.yml') if template =~ /cucumber.yml/
|
140
|
+
path
|
141
|
+
end
|
142
|
+
|
143
|
+
def templates_in( directory)
|
144
|
+
Dir.glob(File.join(@templates_dir, directory, '**/*'))
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
#********************************MESSAGES*************************************************
|
149
|
+
|
150
|
+
|
151
|
+
def directory_exists_message
|
152
|
+
%Q{ You already have a features directory!!
|
153
|
+
Your features directory may contain settings, configuration, test cases and code that you will lose if you choose to delete this directory.
|
154
|
+
If you are sure you need a fresh start, please delete the features directory and re run this command.
|
155
|
+
Don't forget to backup any files you might need in the future before you delete the features directory."}
|
156
|
+
end
|
157
|
+
|
158
|
+
def initialization_message
|
159
|
+
"Initializing a new SimpliTest Project in #{Dir.pwd} \n"
|
160
|
+
end
|
161
|
+
|
162
|
+
def abort_message
|
163
|
+
"No modifications were made. SimpliTest Project initialization has been aborted"
|
164
|
+
end
|
165
|
+
|
166
|
+
def problem_creating_directories_message
|
167
|
+
"There was a problem creating a file or directory required for the new SimpliTest project. This is most likely a file permissions issue. Try running this command as an administrator"
|
168
|
+
end
|
169
|
+
|
170
|
+
def success_message
|
171
|
+
"You have successfully initialized a new SimpliTest project!! See sample files in the features directory"
|
172
|
+
end
|
173
|
+
|
174
|
+
def npp_plugin_generated_message
|
175
|
+
"A gherkin.xml file has been placed in the current directory.\n" +
|
176
|
+
"Now, within Notepad++ open the User Defined dialogue from the View menu.\n" +
|
177
|
+
"Click on import and browse to the generated gherkin.xml file.\n" +
|
178
|
+
"If you open a .feature file from Notepad++ now, it should now have some color coding."
|
179
|
+
end
|
180
|
+
|
181
|
+
def framework_correctly_installed_message
|
182
|
+
"Version: #{SimpliTest::VERSION} is correctly installed! Please read the documentation to get started"
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|