Module: ProjectSetupHelpers

Included in:
SimpliTest, SimpliTest::Cli::Main
Defined in:
lib/SimpliTest/helpers/project_setup.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object

always extend FileHelpers/WindowsUIHelpers with this module



15
16
17
18
19
20
# File 'lib/SimpliTest/helpers/project_setup.rb', line 15

def self.extended klass #always extend FileHelpers/WindowsUIHelpers with this module
  klass.class_eval do
    extend FileHelpers
    extend WindowsUIHelpers
  end
end

.included(klass) ⇒ Object

always include FileHelpers/WindowsUIHelpers with this module



8
9
10
11
12
13
# File 'lib/SimpliTest/helpers/project_setup.rb', line 8

def self.included klass #always include FileHelpers/WindowsUIHelpers with this module
  klass.class_eval do
    include FileHelpers
    include WindowsUIHelpers
  end
end

Instance Method Details

#abort_messageObject



162
163
164
# File 'lib/SimpliTest/helpers/project_setup.rb', line 162

def abort_message
  "No modifications were made. SimpliTest Project initialization has been aborted"
end

#alert(message) ⇒ Object

*****************************USER ALERTS/CONFIRMATION************************************************



107
108
109
# File 'lib/SimpliTest/helpers/project_setup.rb', line 107

def alert(message)
  windows? ? user_informed_via_prompt?(message) : puts(message)
end

#directories_in_path(directory = @directory) ⇒ Object



90
91
92
# File 'lib/SimpliTest/helpers/project_setup.rb', line 90

def directories_in_path(directory=@directory)
  @directories_in_path = directory.split(File::SEPARATOR)
end

#directory_exists_messageObject



151
152
153
154
155
156
# File 'lib/SimpliTest/helpers/project_setup.rb', line 151

def directory_exists_message
  %Q{ You already have a features directory!!
Your features directory may contain settings, configuration, test cases and code that you will lose if you choose to delete this directory.
If you are sure you need a fresh start, please delete the features directory and re run this command.
Don't forget to backup any files you might need in the future before you delete the features directory."}
end

#feature_dir_for(dir = @directory) ⇒ Object



94
95
96
97
98
# File 'lib/SimpliTest/helpers/project_setup.rb', line 94

def feature_dir_for(dir=@directory)
  index = is_a_nested_subdirectory_of_features?(dir)
  raise "Invalid Project. It seems your feature is not part of a proper project" unless index
  directories_in_path(dir)[0,index].join(File::SEPARATOR)
end

#feature_files_exist_in?(dir = @directory) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/SimpliTest/helpers/project_setup.rb', line 76

def feature_files_exist_in?(dir=@directory)
  @feature_files_exist = Dir[File.join(dir, '*.feature')].any?
end

#features_sub_dir_exists_in?(directory = @directory) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/SimpliTest/helpers/project_setup.rb', line 67

def features_sub_dir_exists_in?(directory=@directory)
  @features_sub_dir_exists = has_sub_dir?(directory, 'features')
end

#framework_correctly_installed_messageObject



181
182
183
# File 'lib/SimpliTest/helpers/project_setup.rb', line 181

def framework_correctly_installed_message
  "Version: #{SimpliTest::VERSION} is correctly installed! Please read the documentation to get started"
end

#get_templates_from(*directories) ⇒ Object

*****************************TEMPLATES****************************************************



125
126
127
128
129
130
131
132
133
# File 'lib/SimpliTest/helpers/project_setup.rb', line 125

def get_templates_from(*directories)
  templates = []
  directories.each do |dir|
    templates << templates_in(dir)
  end
  templates = templates.flatten
  templates = templates.select { |f| File.file?(f) } #only select files, ignore directories
  templates
end

#has_sub_dir?(dir, sub_dir) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/SimpliTest/helpers/project_setup.rb', line 71

def has_sub_dir?(dir, sub_dir)
  file = File.join(dir, sub_dir)
  File.directory? file
end

#initialization_messageObject



158
159
160
# File 'lib/SimpliTest/helpers/project_setup.rb', line 158

def initialization_message
  "Initializing a new SimpliTest Project in #{Dir.pwd} \n"
end

#is_a_nested_subdirectory_of_features?(directory = @directory) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/SimpliTest/helpers/project_setup.rb', line 80

def is_a_nested_subdirectory_of_features?(directory=@directory)
  @index_of_features_dir_in_path = directories_in_path(directory).rindex('features')
end

#is_in_the_same_dir_as_features?(directory = @directory) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
103
# File 'lib/SimpliTest/helpers/project_setup.rb', line 100

def is_in_the_same_dir_as_features?(directory=@directory)
  parent = File.expand_path('..', directory)
  @is_in_the_same_dir_as_features = features_sub_dir_exists_in?(parent)
end

#last_features_dir_in_path(directory = @directory) ⇒ Object



84
85
86
87
88
# File 'lib/SimpliTest/helpers/project_setup.rb', line 84

def last_features_dir_in_path(directory=@directory)
  directories = directories_in_path(directory)
  index = @index_of_features_dir_in_path || is_a_nested_subdirectory_of_features?(directory)
  File.expand_path directories[0,index].join(File::SEPARATOR)
end

#npp_plugin_generated_messageObject



174
175
176
177
178
179
# File 'lib/SimpliTest/helpers/project_setup.rb', line 174

def npp_plugin_generated_message
  "A gherkin.xml file has been placed in the current directory.\n" +
    "Now, within Notepad++ open the User Defined dialogue from the View menu.\n" +
    "Click on import and browse to the generated gherkin.xml file.\n" +
    "If you open a .feature file from Notepad++ now, it should now have some color coding."
end

#problem_creating_directories_messageObject



166
167
168
# File 'lib/SimpliTest/helpers/project_setup.rb', line 166

def problem_creating_directories_message
  "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"
end

#project_exists_in?(directory) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/SimpliTest/helpers/project_setup.rb', line 45

def project_exists_in?(directory)
  # see if current_dir == features
  # see if current_dir.sub_dir.include?(features)
  # see if parent_dir == features
  # see if parent_dir == features/support features/specifications
  # see if parent_dir == features/support/config
  # see if parent_dir == features/support/config/selectors.yml
  # see if sibling_dir == features example: project/documentation and project/features
  @directory ||= directory
  features_sub_dir_exists_in? ||
    is_in_the_same_dir_as_features? ||
    feature_files_exist_in? ||
    is_a_nested_subdirectory_of_features?
end

#project_not_foundObject



62
63
64
65
# File 'lib/SimpliTest/helpers/project_setup.rb', line 62

def project_not_found
  alert "Could not find the project. Try running this from the main project directory that has the features directory in it"
  raise "Project Not Found Error"
end

#project_path_for(directory) ⇒ Object

TODO: Need a massive fix…some of this stuff isn’t even right… We shouldnt just be taking the last features directory in path…this could be a big problem



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/SimpliTest/helpers/project_setup.rb', line 33

def project_path_for(directory)
  project_not_found unless project_exists_in?(directory)
  @project_path = directory if @features_sub_dir_exists
  @project_path = File.expand_path('..', directory) if @is_in_the_same_dir_as_features
  @project_path = last_features_dir_in_path if (@feature_files_exist || @index_of_features_dir_in_path)
  if @project_path
    return @project_path
  else
    project_not_found
  end
end

#relative_path_for(template) ⇒ Object



136
137
138
139
140
141
# File 'lib/SimpliTest/helpers/project_setup.rb', line 136

def relative_path_for(template)
  path = template.gsub("#{@templates_dir}/features", '')
  path = File.join(@features_dir, path)
  path = File.join(Pathname.new(File.expand_path(@features_dir)).parent.to_s, 'cucumber.yml') if template =~ /cucumber.yml/
  path
end

#success_messageObject



170
171
172
# File 'lib/SimpliTest/helpers/project_setup.rb', line 170

def success_message
  "You have successfully initialized a new SimpliTest project!! See sample files in the features directory"
end

#templates_in(directory) ⇒ Object



143
144
145
# File 'lib/SimpliTest/helpers/project_setup.rb', line 143

def templates_in( directory)
  Dir.glob(File.join(@templates_dir, directory, '**/*'))
end

#user_consents?Boolean

Returns:

  • (Boolean)


111
112
113
114
# File 'lib/SimpliTest/helpers/project_setup.rb', line 111

def user_consents?
  question = initialization_message + "\nThis will create new files and folders in the current directory. \nWould you still like to proceed?(Y/n)"
  windows? ? user_consents_via_prompt?(question) : user_consents_via_console?(question)
end

#user_consents_via_console?(question) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
119
120
# File 'lib/SimpliTest/helpers/project_setup.rb', line 116

def user_consents_via_console?(question)
  STDOUT.puts question
  response = STDIN.gets.strip
  %w[y yes].include?(response.downcase)
end

#windows?Boolean

**********************************PLATFORM****************************************************

Returns:

  • (Boolean)


24
25
26
# File 'lib/SimpliTest/helpers/project_setup.rb', line 24

def windows?
  @windows = RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
end