SimpliTest 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -21
  3. data/SimpliTest.gemspec +42 -42
  4. data/bin/SimpliTest +22 -22
  5. data/lib/SimpliTest.rb +2 -2
  6. data/lib/SimpliTest/cli/main.rb +333 -333
  7. data/lib/SimpliTest/config/configuration.rb +107 -107
  8. data/lib/SimpliTest/config/directory_paths.rb +36 -36
  9. data/lib/SimpliTest/config/environment.rb +67 -67
  10. data/lib/SimpliTest/config/local_environment.rb +20 -20
  11. data/lib/SimpliTest/config/profiles/chrome.rb +18 -18
  12. data/lib/SimpliTest/config/profiles/firefox.rb +14 -14
  13. data/lib/SimpliTest/config/profiles/internet_explorer.rb +11 -11
  14. data/lib/SimpliTest/config/profiles/phantom.rb +9 -9
  15. data/lib/SimpliTest/config/profiles/phantom_debug.rb +12 -12
  16. data/lib/SimpliTest/config/profiles/selenium.rb +13 -13
  17. data/lib/SimpliTest/config/screen_size.rb +25 -25
  18. data/lib/SimpliTest/config/steps.rb +8 -8
  19. data/lib/SimpliTest/helpers/data_validation.rb +60 -60
  20. data/lib/SimpliTest/helpers/file.rb +38 -38
  21. data/lib/SimpliTest/helpers/project_setup.rb +186 -186
  22. data/lib/SimpliTest/helpers/step_helpers/custom_chrome_helpers.rb +14 -14
  23. data/lib/SimpliTest/helpers/step_helpers/custom_date_helpers.rb +64 -64
  24. data/lib/SimpliTest/helpers/step_helpers/custom_form_helpers.rb +66 -66
  25. data/lib/SimpliTest/helpers/step_helpers/custom_phantomjs_helpers.rb +49 -49
  26. data/lib/SimpliTest/helpers/step_helpers/custom_selenium_helpers.rb +41 -41
  27. data/lib/SimpliTest/helpers/step_helpers/html_selectors_helpers.rb +154 -154
  28. data/lib/SimpliTest/helpers/step_helpers/navigation_helpers.rb +206 -206
  29. data/lib/SimpliTest/helpers/step_helpers/tolerance_for_sync_issues.rb +38 -38
  30. data/lib/SimpliTest/helpers/step_helpers/within_helpers.rb +6 -6
  31. data/lib/SimpliTest/helpers/windows_ui.rb +51 -51
  32. data/lib/SimpliTest/steps/debugging_steps.rb +19 -19
  33. data/lib/SimpliTest/steps/form_steps.rb +348 -352
  34. data/lib/SimpliTest/steps/form_verification_steps.rb +189 -189
  35. data/lib/SimpliTest/steps/navigation_steps.rb +58 -47
  36. data/lib/SimpliTest/steps/scoper.rb +42 -42
  37. data/lib/SimpliTest/steps/verification_steps.rb +306 -306
  38. data/lib/SimpliTest/tasks/document.rb +169 -169
  39. data/lib/SimpliTest/tasks/examples.rb +18 -18
  40. data/lib/SimpliTest/tasks/testinstall.rb +5 -5
  41. data/lib/SimpliTest/templates/NewSimpliTestProject/Readme.txt +4 -4
  42. data/lib/SimpliTest/templates/NewSimpliTestProject/cucumber.yml +26 -26
  43. data/lib/SimpliTest/templates/NewSimpliTestProject/documentation/step_definitions.html +88 -87
  44. data/lib/SimpliTest/templates/NewSimpliTestProject/features/specifications/RegressionTests/HelloWorld.feature +3 -3
  45. data/lib/SimpliTest/templates/NewSimpliTestProject/features/specifications/SmokeTest/HelloWorld.feature +3 -3
  46. data/lib/SimpliTest/templates/NewSimpliTestProject/features/specifications/accessibilityTests/HelloWorld.feature +3 -3
  47. data/lib/SimpliTest/templates/NewSimpliTestProject/features/support/config/environments.yml +10 -10
  48. data/lib/SimpliTest/templates/NewSimpliTestProject/features/support/config/pages.yml +26 -26
  49. data/lib/SimpliTest/templates/NewSimpliTestProject/features/support/config/selectors.yml +44 -44
  50. data/lib/SimpliTest/templates/NewSimpliTestProject/features/support/config/settings.yml +26 -26
  51. data/lib/SimpliTest/templates/NewSimpliTestProject/features/support/env.rb +33 -33
  52. data/lib/SimpliTest/templates/NewSimpliTestProject/license.txt +29 -29
  53. data/lib/SimpliTest/templates/document/css/style.css +28 -28
  54. data/lib/SimpliTest/templates/document/index.html +60 -60
  55. data/lib/version.rb +3 -3
  56. metadata +4 -4
@@ -1,18 +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
-
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
+
@@ -1,14 +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)
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)
@@ -1,12 +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
-
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
12
  World(CustomSeleniumHelpers)
@@ -1,9 +1,9 @@
1
- require 'capybara/poltergeist'
2
- Before do
3
- Capybara.current_driver = :poltergeist
4
- Capybara.javascript_driver = :poltergeist
5
- SimpliTest.driver= 'poltergeist'
6
- end
7
-
8
- World(CustomPhantomjsHelpers)
9
-
1
+ require 'capybara/poltergeist'
2
+ Before do
3
+ Capybara.current_driver = :poltergeist
4
+ Capybara.javascript_driver = :poltergeist
5
+ SimpliTest.driver= 'poltergeist'
6
+ end
7
+
8
+ World(CustomPhantomjsHelpers)
9
+
@@ -1,12 +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)
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)
@@ -1,13 +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)
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)
@@ -1,25 +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
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
@@ -1,8 +1,8 @@
1
- require 'uri'
2
- require 'cgi'
3
- load_directories = [File.join(SimpliTest.path_to_steps_dir, '*.rb'), File.join(SimpliTest.path_to_step_helpers_dir, '*.rb')]
4
- load_directories.each do |dir|
5
- Dir[dir].each {|file| require file }
6
- end
7
-
8
-
1
+ require 'uri'
2
+ require 'cgi'
3
+ load_directories = [File.join(SimpliTest.path_to_steps_dir, '*.rb'), File.join(SimpliTest.path_to_step_helpers_dir, '*.rb')]
4
+ load_directories.each do |dir|
5
+ Dir[dir].each {|file| require file }
6
+ end
7
+
8
+
@@ -1,60 +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
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
@@ -1,38 +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
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
@@ -1,186 +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
-
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
+