From a6aa903adf9dc7e7e9a922772a14d60bcc708adc Mon Sep 17 00:00:00 2001 From: aguspe Date: Thu, 25 Jul 2024 17:14:29 +0200 Subject: [PATCH] Start adding RBS support --- lib/commands/utility_commands.rb | 121 ++++++++-------- lib/generators/actions/actions_generator.rb | 10 +- .../automation/automation_generator.rb | 122 ++++++++-------- lib/generators/common_generator.rb | 52 +++---- lib/generators/cucumber/cucumber_generator.rb | 56 ++++---- lib/generators/generator.rb | 116 +++++++-------- lib/generators/helper_generator.rb | 80 ++++++----- lib/generators/invoke_generators.rb | 58 ++++---- lib/generators/menu_generator.rb | 136 +++++++++--------- lib/generators/rspec/rspec_generator.rb | 26 ++-- lib/scaffolding/scaffolding.rb | 94 ++++++------ lib/utilities/utilities.rb | 18 +-- ruby_raider.gemspec | 1 + sig/gems/tty.rbs | 4 + sig/lib/commands/scaffolding_commands.rbs | 19 +++ sig/lib/commands/utility_commands.rbs | 17 +++ .../generators/actions/actions_generator.rbs | 5 + .../automation/automation_generator.rbs | 35 +++++ sig/lib/generators/common_generator.rbs | 19 +++ .../cucumber/cucumber_generator.rbs | 19 +++ sig/lib/generators/generator.rbs | 43 ++++++ sig/lib/generators/helper_generator.rbs | 21 +++ sig/lib/generators/invoke_generators.rbs | 11 ++ sig/lib/generators/menu_generator.rbs | 37 +++++ sig/lib/generators/rspec/rspec_generator.rbs | 9 ++ sig/lib/ruby_raider.rbs | 11 ++ sig/lib/scaffolding/scaffolding.rbs | 33 +++++ sig/lib/utilities/logger.rbs | 9 ++ sig/lib/utilities/utilities.rbs | 35 +++++ 29 files changed, 785 insertions(+), 432 deletions(-) create mode 100644 sig/gems/tty.rbs create mode 100644 sig/lib/commands/scaffolding_commands.rbs create mode 100644 sig/lib/commands/utility_commands.rbs create mode 100644 sig/lib/generators/actions/actions_generator.rbs create mode 100644 sig/lib/generators/automation/automation_generator.rbs create mode 100644 sig/lib/generators/common_generator.rbs create mode 100644 sig/lib/generators/cucumber/cucumber_generator.rbs create mode 100644 sig/lib/generators/generator.rbs create mode 100644 sig/lib/generators/helper_generator.rbs create mode 100644 sig/lib/generators/invoke_generators.rbs create mode 100644 sig/lib/generators/menu_generator.rbs create mode 100644 sig/lib/generators/rspec/rspec_generator.rbs create mode 100644 sig/lib/ruby_raider.rbs create mode 100644 sig/lib/scaffolding/scaffolding.rbs create mode 100644 sig/lib/utilities/logger.rbs create mode 100644 sig/lib/utilities/utilities.rbs diff --git a/lib/commands/utility_commands.rb b/lib/commands/utility_commands.rb index d9a3f71..159565b 100644 --- a/lib/commands/utility_commands.rb +++ b/lib/commands/utility_commands.rb @@ -5,76 +5,79 @@ # :reek:FeatureEnvy { enabled: false } # :reek:UtilityFunction { enabled: false } -class UtilityCommands < Thor - desc 'path [PATH]', 'Sets the default path for scaffolding' - option :feature, - type: :boolean, required: false, desc: 'The default path for your features', aliases: '-f' - option :helper, - type: :boolean, required: false, desc: 'The default path for your helpers', aliases: '-h' - option :spec, - type: :boolean, required: false, desc: 'The default path for your specs', aliases: '-s' - - def path(default_path) - type = options.empty? ? 'page' : options.keys.first - Utilities.send("#{type}_path=", default_path) - end +module RubyRaider + class UtilityCommands < Thor + desc 'path [PATH]', 'Sets the default path for scaffolding' + option :feature, + type: :boolean, required: false, desc: 'The default path for your features', aliases: '-f' + option :helper, + type: :boolean, required: false, desc: 'The default path for your helpers', aliases: '-h' + option :spec, + type: :boolean, required: false, desc: 'The default path for your specs', aliases: '-s' - desc 'url [URL]', 'Sets the default url for a project' + def path(default_path) + type = options.empty? ? 'page' : options.keys.first + Utilities.send("#{type}_path=", default_path) + end - def url(default_url) - Utilities.url = default_url - end + desc 'url [URL]', 'Sets the default url for a project' - desc 'browser [BROWSER]', 'Sets the default browser for a project' - option :opts, - type: :array, required: false, desc: 'The options you want your browser to run with', aliases: '-o' - option :delete, - type: :boolean, required: false, desc: 'This will delete your browser options', aliases: '-d' + def url(default_url) + Utilities.url = default_url + end - def browser(default_browser = nil) - Utilities.browser = default_browser if default_browser - selected_options = options[:opts] - browser_options(selected_options) if selected_options || options[:delete] - end + desc 'browser [BROWSER]', 'Sets the default browser for a project' + option :opts, + type: :array, required: false, desc: 'The options you want your browser to run with', aliases: '-o' + option :delete, + type: :boolean, required: false, desc: 'This will delete your browser options', aliases: '-d' - desc 'browser_options [OPTIONS]', 'Sets the browser options for the project' - option :delete, - type: :boolean, required: false, desc: 'This will delete your browser options', aliases: '-d' + def browser(default_browser = nil) + Utilities.browser = default_browser if default_browser + selected_options = options[:opts] + browser_options(selected_options) if selected_options || options[:delete] + end - def browser_options(*opts) - Utilities.browser_options = opts unless opts.empty? - Utilities.delete_browser_options if options[:delete] - end + desc 'browser_options [OPTIONS]', 'Sets the browser options for the project' + option :delete, + type: :boolean, required: false, desc: 'This will delete your browser options', aliases: '-d' - desc 'raid', 'It runs all the tests in a project' - option :parallel, - type: :boolean, required: false, desc: 'It runs the tests in parallel', aliases: '-p' - option :opts, - type: :array, required: false, desc: 'The options that your run will run with', aliases: '-o' - - def raid - selected_options = options[:opts] - if options[:parallel] - Utilities.parallel_run(selected_options) - else - Utilities.run(selected_options) + def browser_options(*opts) + Utilities.browser_options = opts unless opts.empty? + Utilities.delete_browser_options if options[:delete] end - end - desc 'config', 'Creates a new config file' - option :path, - type: :string, required: false, desc: 'The path where your config file will be created', aliases: '-p' - option :delete, - type: :boolean, required: false, desc: 'This will delete the selected config file', aliases: '-d' + desc 'raid', 'It runs all the tests in a project' + option :parallel, + type: :boolean, required: false, desc: 'It runs the tests in parallel', aliases: '-p' + option :opts, + type: :array, required: false, desc: 'The options that your run will run with', aliases: '-o' - desc 'platform [PLATFORM]', 'Sets the default platform for a cross-platform project' + def raid + selected_options = options[:opts] + if options[:parallel] + Utilities.parallel_run(selected_options) + else + Utilities.run(selected_options) + end + end - def platform(platform) - Utilities.platform = platform - end + desc 'config', 'Creates a new config file' + option :path, + type: :string, required: false, desc: 'The path where your config file will be created', aliases: '-p' + option :delete, + type: :boolean, required: false, desc: 'This will delete the selected config file', aliases: '-d' - desc 'start_appium', 'It starts the appium server' - def start_appium - system 'appium --base-path /wd/hub' + desc 'platform [PLATFORM]', 'Sets the default platform for a cross-platform project' + + def platform(platform) + Utilities.platform = platform + end + + desc 'start_appium', 'It starts the appium server' + + def start_appium + system 'appium --base-path /wd/hub' + end end end diff --git a/lib/generators/actions/actions_generator.rb b/lib/generators/actions/actions_generator.rb index c70e808..7438704 100644 --- a/lib/generators/actions/actions_generator.rb +++ b/lib/generators/actions/actions_generator.rb @@ -2,10 +2,12 @@ require_relative '../generator' -class ActionsGenerator < Generator - def generate_actions_file - return unless web? +module RubyRaider + class ActionsGenerator < Generator + def generate_actions_file + return unless web? - template('actions.tt', "#{name}/.github/workflows/test_pipeline.yml") + template('actions.tt', "#{name}/.github/workflows/test_pipeline.yml") + end end end diff --git a/lib/generators/automation/automation_generator.rb b/lib/generators/automation/automation_generator.rb index 522dec8..c7a2bf7 100644 --- a/lib/generators/automation/automation_generator.rb +++ b/lib/generators/automation/automation_generator.rb @@ -2,82 +2,84 @@ require_relative '../generator' -class AutomationGenerator < Generator - def generate_automation_files - if mobile? - generate_appium_settings - generate_home_page - generate_pdp_page - else - generate_visual_options - generate_components - generate_model_files - generate_pages +module RubyRaider + class AutomationGenerator < Generator + def generate_automation_files + if mobile? + generate_appium_settings + generate_home_page + generate_pdp_page + else + generate_visual_options + generate_components + generate_model_files + generate_pages + end + + generate_abstract_page end - generate_abstract_page - end - - private + private - def generate_pages - generate_login_page - generate_account_page - end + def generate_pages + generate_login_page + generate_account_page + end - def generate_components - generate_abstract_component - generate_header_component - end + def generate_components + generate_abstract_component + generate_header_component + end - def generate_model_files - generate_model_factory - generate_model_data - end + def generate_model_files + generate_model_factory + generate_model_data + end - def generate_abstract_page - template('page.tt', "#{name}/page_objects/abstract/page.rb") - end + def generate_abstract_page + template('page.tt', "#{name}/page_objects/abstract/page.rb") + end - def generate_abstract_component - template('component.tt', "#{name}/page_objects/abstract/component.rb") - end + def generate_abstract_component + template('component.tt', "#{name}/page_objects/abstract/component.rb") + end - def generate_appium_settings - template('appium_caps.tt', "#{name}/config/capabilities.yml") - end + def generate_appium_settings + template('appium_caps.tt', "#{name}/config/capabilities.yml") + end - def generate_visual_options - return unless visual? + def generate_visual_options + return unless visual? - template('visual_options.tt', "#{name}/config/options.yml") - end + template('visual_options.tt', "#{name}/config/options.yml") + end - def generate_login_page - template('login.tt', "#{name}/page_objects/pages/login.rb") - end + def generate_login_page + template('login.tt', "#{name}/page_objects/pages/login.rb") + end - def generate_account_page - template('account.tt', "#{name}/page_objects/pages/account.rb") - end + def generate_account_page + template('account.tt', "#{name}/page_objects/pages/account.rb") + end - def generate_home_page - template('home.tt', "#{name}/page_objects/pages/home.rb") - end + def generate_home_page + template('home.tt', "#{name}/page_objects/pages/home.rb") + end - def generate_pdp_page - template('pdp.tt', "#{name}/page_objects/pages/pdp.rb") - end + def generate_pdp_page + template('pdp.tt', "#{name}/page_objects/pages/pdp.rb") + end - def generate_header_component - template('header.tt', "#{name}/page_objects/components/header.rb") - end + def generate_header_component + template('header.tt', "#{name}/page_objects/components/header.rb") + end - def generate_model_factory - template('factory.tt', "#{name}/models/model_factory.rb") - end + def generate_model_factory + template('factory.tt', "#{name}/models/model_factory.rb") + end - def generate_model_data - template('data.tt', "#{name}/models/data/users.yml") + def generate_model_data + template('data.tt', "#{name}/models/data/users.yml") + end end end diff --git a/lib/generators/common_generator.rb b/lib/generators/common_generator.rb index ff6f81d..936b739 100644 --- a/lib/generators/common_generator.rb +++ b/lib/generators/common_generator.rb @@ -2,38 +2,40 @@ require_relative 'generator' -class CommonGenerator < Generator - def generate_readme_file - template('common/read_me.tt', "#{name}/Readme.md") - end +module RubyRaider + class CommonGenerator < Generator + def generate_readme_file + template('common/read_me.tt', "#{name}/Readme.md") + end - def generate_config_file - return if single_platform? + def generate_config_file + return if single_platform? - template('common/config.tt', "#{name}/config/config.yml") - end + template('common/config.tt', "#{name}/config/config.yml") + end - def generate_rake_file - template('common/rakefile.tt', "#{name}/Rakefile") - end + def generate_rake_file + template('common/rakefile.tt', "#{name}/Rakefile") + end - def generate_gemfile - template('common/gemfile.tt', "#{name}/Gemfile") - end + def generate_gemfile + template('common/gemfile.tt', "#{name}/Gemfile") + end - def generate_reek_file - template('common/reek.tt', "#{name}/.reek.yml") - end + def generate_reek_file + template('common/reek.tt', "#{name}/.reek.yml") + end - def generate_rubocop_file - template('common/rubocop.tt', "#{name}/.rubocop.yml") - end + def generate_rubocop_file + template('common/rubocop.tt', "#{name}/.rubocop.yml") + end - def generate_gitignore_file - template('common/git_ignore.tt', "#{name}/.gitignore") - end + def generate_gitignore_file + template('common/git_ignore.tt', "#{name}/.gitignore") + end - def create_allure_folder - empty_directory "#{name}/allure-results" + def create_allure_folder + empty_directory "#{name}/allure-results" + end end end diff --git a/lib/generators/cucumber/cucumber_generator.rb b/lib/generators/cucumber/cucumber_generator.rb index 4be1818..8772984 100644 --- a/lib/generators/cucumber/cucumber_generator.rb +++ b/lib/generators/cucumber/cucumber_generator.rb @@ -2,32 +2,34 @@ require_relative '../generator' -class CucumberGenerator < Generator - def generate_feature - template('feature.tt', "#{name}/features/#{template_name}.feature") - end - - def generate_steps - template('steps.tt', "#{name}/features/step_definitions/#{template_name}_steps.rb") - end - - def generate_user_factory - template('user_factory.tt', "#{name}/models/user_factory.rb") - end - - def generate_env_file - template('env.tt', "#{name}/features/support/env.rb") - end - - def generate_world - template('world.tt', "#{name}/features/support/world.rb") - end - - def generate_cucumber_file - template('cucumber.tt', "#{name}/cucumber.yml") - end - - def template_name - @template_name ||= (@_initializer.first & %w[android ios cross_platform]).empty? ? 'login' : 'home' +module RubyRaider + class CucumberGenerator < Generator + def generate_feature + template('feature.tt', "#{name}/features/#{template_name}.feature") + end + + def generate_steps + template('steps.tt', "#{name}/features/step_definitions/#{template_name}_steps.rb") + end + + def generate_user_factory + template('user_factory.tt', "#{name}/models/user_factory.rb") + end + + def generate_env_file + template('env.tt', "#{name}/features/support/env.rb") + end + + def generate_world + template('world.tt', "#{name}/features/support/world.rb") + end + + def generate_cucumber_file + template('cucumber.tt', "#{name}/cucumber.yml") + end + + def template_name + @template_name ||= (@_initializer.first & %w[android ios cross_platform]).empty? ? 'login' : 'home' + end end end diff --git a/lib/generators/generator.rb b/lib/generators/generator.rb index 3fd4b4d..040bf0f 100644 --- a/lib/generators/generator.rb +++ b/lib/generators/generator.rb @@ -2,81 +2,83 @@ require 'thor' -class Generator < Thor::Group - include Thor::Actions +module RubyRaider + class Generator < Thor::Group + include Thor::Actions - argument :automation - argument :framework - argument :name + argument :automation + argument :framework + argument :name - def self.source_paths - base_path = File.dirname(__FILE__) - %W[#{base_path}/automation/templates #{base_path}/cucumber/templates + def self.source_paths + base_path = File.dirname(__FILE__) + %W[#{base_path}/automation/templates #{base_path}/cucumber/templates #{base_path}/rspec/templates #{base_path}/templates #{base_path}/actions/templates ] - end + end - def args - initializer.first - end + def args + initializer.first + end - def cucumber? - args.include?('cucumber') - end + def cucumber? + args.& include?('cucumber') + end - # The framework is cross platform when it supports Android and iOS - def cross_platform? - args.include?('cross_platform') - end + # The framework is cross platform when it supports Android and iOS + def cross_platform? + args.& include?('cross_platform') + end - def mobile? - (args & %w[android ios cross_platform]).count.positive? - end + def mobile? + (args & %w[android ios cross_platform]).count.positive? + end - def single_platform? - (args & %w[android ios]).count.positive? - end + def single_platform? + (args & %w[android ios]).count.positive? + end - def ios? - args.include?('ios') - end + def ios? + args.& include?('ios') + end - def android? - args.include?('android') - end + def android? + args.& include?('android') + end - def rspec? - args.include?('rspec') - end + def rspec? + args.& include?('rspec') + end - def selenium? - args.include?('selenium') - end + def selenium? + args.& include?('selenium') + end - def visual? - args.include?('applitools') - end + def visual? + args.& include?('applitools') + end - def watir? - args.include?('watir') - end + def watir? + args.& include?('watir') + end - def web? - (args & (%w[selenium watir axe applitools])).count.positive? - end + def web? + (args & (%w[selenium watir axe applitools])).count.positive? + end - def axe? - args.include?('axe') - end + def axe? + args.& include?('axe') + end - def selenium_based? - (args & %w[selenium axe applitools]).count.positive? - end + def selenium_based? + (args & %w[selenium axe applitools]).count.positive? + end - private + private - def _initializer - @_initializer ||= super - end + def _initializer + @_initializer ||= super + end - alias initializer _initializer + alias initializer _initializer + end end diff --git a/lib/generators/helper_generator.rb b/lib/generators/helper_generator.rb index 7b1a96d..114f74d 100644 --- a/lib/generators/helper_generator.rb +++ b/lib/generators/helper_generator.rb @@ -2,58 +2,60 @@ require_relative 'generator' -class HelpersGenerator < Generator - def generate_helpers - generate_browser_helper - generate_driver_helper - generate_appium_helper - generate_allure_helper - - if visual? - generate_visual_helper - generate_visual_spec_helper - else - generate_spec_helper +module RubyRaider + class HelpersGenerator < Generator + def generate_helpers + generate_browser_helper + generate_driver_helper + generate_appium_helper + generate_allure_helper + + if visual? + generate_visual_helper + generate_visual_spec_helper + else + generate_spec_helper + end end - end - private + private - def generate_allure_helper - template('helpers/allure_helper.tt', "#{name}/helpers/allure_helper.rb") - end + def generate_allure_helper + template('helpers/allure_helper.tt', "#{name}/helpers/allure_helper.rb") + end - def generate_browser_helper - return if selenium_based? || mobile? + def generate_browser_helper + return if selenium_based? || mobile? - template('helpers/browser_helper.tt', "#{name}/helpers/browser_helper.rb") - end + template('helpers/browser_helper.tt', "#{name}/helpers/browser_helper.rb") + end - def generate_spec_helper - return if cucumber? + def generate_spec_helper + return if cucumber? - template('helpers/spec_helper.tt', "#{name}/helpers/spec_helper.rb") - end + template('helpers/spec_helper.tt', "#{name}/helpers/spec_helper.rb") + end - def generate_driver_helper - return if watir? + def generate_driver_helper + return if watir? - template('helpers/driver_helper.tt', "#{name}/helpers/driver_helper.rb") - end + template('helpers/driver_helper.tt', "#{name}/helpers/driver_helper.rb") + end - def generate_appium_helper - return unless cross_platform? + def generate_appium_helper + return unless cross_platform? - template('helpers/appium_helper.tt', "#{name}/helpers/appium_helper.rb") - end + template('helpers/appium_helper.tt', "#{name}/helpers/appium_helper.rb") + end - def generate_visual_helper - template('helpers/visual_helper.tt', "#{name}/helpers/visual_helper.rb") - end + def generate_visual_helper + template('helpers/visual_helper.tt', "#{name}/helpers/visual_helper.rb") + end - def generate_visual_spec_helper - return if cucumber? + def generate_visual_spec_helper + return if cucumber? - template('helpers/visual_spec_helper.tt', "#{name}/helpers/spec_helper.rb") + template('helpers/visual_spec_helper.tt', "#{name}/helpers/spec_helper.rb") + end end end diff --git a/lib/generators/invoke_generators.rb b/lib/generators/invoke_generators.rb index a4f5e3a..4312fcb 100644 --- a/lib/generators/invoke_generators.rb +++ b/lib/generators/invoke_generators.rb @@ -5,39 +5,41 @@ require_relative 'helper_generator' require_relative 'rspec/rspec_generator' -# :reek:FeatureEnvy { enabled: false } -# :reek:UtilityFunction { enabled: false } -module InvokeGenerators - module_function +module RubyRaider + # :reek:FeatureEnvy { enabled: false } + # :reek:UtilityFunction { enabled: false } + module InvokeGenerators + module_function - def generate_framework(structure = {}) - generators = %w[Automation Actions Common Helpers] - framework = structure[:framework] - add_generator(generators, framework.capitalize) - generators.each do |generator| - invoke_generator({ - automation: structure[:automation], - framework:, - generator:, - name: structure[:name] - }) + def generate_framework(structure = {}) + generators = %w[Automation Actions Common Helpers] + framework = structure[:framework] + add_generator(generators, framework.capitalize) + generators.each do |generator| + invoke_generator({ + automation: structure[:automation], + framework:, + generator:, + name: structure[:name] + }) + end end - end - def add_generator(generators, *gens) - gens.each { |generator| generators.push generator } - end + def add_generator(generators, *gens) + gens.each { |generator| generators.push generator } + end - def invoke_generator(structure = {}) - Object.const_get("#{structure[:generator]}Generator") - .new([structure[:automation], - structure[:framework], - structure[:name]]).invoke_all - end + def invoke_generator(structure = {}) + Object.const_get("#{structure[:generator]}Generator") + .new([structure[:automation], + structure[:framework], + structure[:name]]).invoke_all + end - def to_bool(string) - return unless string.is_a? String + def to_bool(string) + return unless string.is_a? String - string.downcase == 'true' + string.downcase == 'true' + end end end diff --git a/lib/generators/menu_generator.rb b/lib/generators/menu_generator.rb index 984fadd..ba915d9 100644 --- a/lib/generators/menu_generator.rb +++ b/lib/generators/menu_generator.rb @@ -5,90 +5,92 @@ # :reek:FeatureEnvy { enabled: false } # :reek:UtilityFunction { enabled: false } -class MenuGenerator - attr_reader :prompt, :name +module RubyRaider + class MenuGenerator + attr_reader :prompt, :name - include InvokeGenerators + include InvokeGenerators - def initialize(project_name) - @prompt = TTY::Prompt.new - @name = project_name - end + def initialize(project_name) + @prompt = TTY::Prompt.new + @name = project_name + end - def generate_choice_menu - prompt.select('Please select your automation framework') do |menu| - select_automation_framework(menu) + def generate_choice_menu + prompt.select('Please select your automation framework') do |menu| + select_automation_framework(menu) + end end - end - def choose_test_framework(automation) - return choose_mobile_platform if automation == 'appium' + def choose_test_framework(automation) + return choose_mobile_platform if automation == 'appium' - select_test_framework(automation) - end + select_test_framework(automation) + end - def set_up_framework(options) - structure = { - automation: options[:automation], - framework: options[:framework], - name: @name - } - generate_framework(structure) - system "cd #{name} && gem install bundler && bundle install" - end + def set_up_framework(options) + structure = { + automation: options[:automation], + framework: options[:framework], + name: @name + } + generate_framework(structure) + system "cd #{name} && gem install bundler && bundle install" + end - def choose_mobile_platform - prompt.select('Please select your mobile platform') do |menu| - menu.choice :iOS, -> { choose_test_framework 'ios' } - menu.choice :Android, -> { choose_test_framework 'android' } - menu.choice :Cross_Platform, -> { choose_test_framework 'cross_platform' } - menu.choice :Quit, -> { exit } + def choose_mobile_platform + prompt.select('Please select your mobile platform') do |menu| + menu.choice :iOS, -> { choose_test_framework 'ios' } + menu.choice :Android, -> { choose_test_framework 'android' } + menu.choice :Cross_Platform, -> { choose_test_framework 'cross_platform' } + menu.choice :Quit, -> { exit } + end end - end - private + private - def select_test_framework(automation) - prompt.select('Please select your test framework') do |menu| - menu.choice :Cucumber, -> { create_framework('Cucumber', automation) } - menu.choice :Rspec, -> { create_framework('Rspec', automation) } - menu.choice :Quit, -> { exit } + def select_test_framework(automation) + prompt.select('Please select your test framework') do |menu| + menu.choice :Cucumber, -> { create_framework('Cucumber', automation) } + menu.choice :Rspec, -> { create_framework('Rspec', automation) } + menu.choice :Quit, -> { exit } + end end - end - FrameworkOptions = Struct.new(:automation, :framework) + FrameworkOptions = Struct.new(:automation, :framework) - def create_framework_options(params) - FrameworkOptions.new(params[:automation], params[:framework]) - end + def create_framework_options(params) + FrameworkOptions.new(params[:automation], params[:framework]) + end - def create_framework(framework, automation_type) - options = create_framework_options(automation: automation_type, - framework: framework.downcase) + def create_framework(framework, automation_type) + options = create_framework_options(automation: automation_type, + framework: framework.downcase) - # Print the chosen options - puts 'Chosen Options:' - puts " Automation Type: #{options[:automation]}" - puts " Framework: #{options[:framework]}" + # Print the chosen options + puts 'Chosen Options:' + puts " Automation Type: #{options[:automation]}" + puts " Framework: #{options[:framework]}" - set_up_framework(options) - prompt.say("You have chosen to use #{framework} with #{automation_type}") - end + set_up_framework(options) + prompt.say("You have chosen to use #{framework} with #{automation_type}") + end - def yes_no_menu_choices - { - Yes: -> { true }, - No: -> { false }, - Quit: -> { exit } - } - end + def yes_no_menu_choices + { + Yes: -> { true }, + No: -> { false }, + Quit: -> { exit } + } + end - def select_automation_framework(menu) - menu.choice :Selenium, -> { choose_test_framework('selenium') } - menu.choice :Appium, -> { choose_test_framework('appium') } - menu.choice :Watir, -> { choose_test_framework('watir') } - menu.choice :Applitools, -> { choose_test_framework('applitools') } - menu.choice :Axe, -> { choose_test_framework('axe') } - menu.choice :Quit, -> { exit } + def select_automation_framework(menu) + menu.choice :Selenium, -> { choose_test_framework('selenium') } + menu.choice :Appium, -> { choose_test_framework('appium') } + menu.choice :Watir, -> { choose_test_framework('watir') } + menu.choice :Applitools, -> { choose_test_framework('applitools') } + menu.choice :Axe, -> { choose_test_framework('axe') } + menu.choice :Quit, -> { exit } + end end -end +end \ No newline at end of file diff --git a/lib/generators/rspec/rspec_generator.rb b/lib/generators/rspec/rspec_generator.rb index a88bd1c..accf458 100644 --- a/lib/generators/rspec/rspec_generator.rb +++ b/lib/generators/rspec/rspec_generator.rb @@ -2,22 +2,24 @@ require_relative '../generator' -class RspecGenerator < Generator - def generate_login_spec - return unless web? && !visual? +module RubyRaider + class RspecGenerator < Generator + def generate_login_spec + return unless web? && !visual? - template('spec.tt', "#{name}/spec/login_page_spec.rb") - end + template('spec.tt', "#{name}/spec/login_page_spec.rb") + end - def generate_pdp_spec - return unless mobile? + def generate_pdp_spec + return unless mobile? - template('spec.tt', "#{name}/spec/pdp_page_spec.rb") - end + template('spec.tt', "#{name}/spec/pdp_page_spec.rb") + end - def generate_account_spec - return unless visual? + def generate_account_spec + return unless visual? - template('spec.tt', "#{name}/spec/account_page_spec.rb") + template('spec.tt', "#{name}/spec/account_page_spec.rb") + end end end diff --git a/lib/scaffolding/scaffolding.rb b/lib/scaffolding/scaffolding.rb index 9179e62..3be950d 100644 --- a/lib/scaffolding/scaffolding.rb +++ b/lib/scaffolding/scaffolding.rb @@ -2,66 +2,68 @@ require 'thor' -class Scaffolding < Thor::Group - include Thor::Actions +module RubyRaider + class Scaffolding < Thor::Group + include Thor::Actions - argument :name, optional: true - argument :path, optional: true + argument :name, optional: true + argument :path, optional: true - def self.source_root - "#{File.dirname(__FILE__)}/templates" - end + def self.source_root + "#{File.dirname(__FILE__)}/templates" + end - def generate_page - template('page_object.tt', default_path("page_objects/pages/#{name}.rb", '_page.rb')) - end + def generate_page + template('page_object.tt', default_path("page_objects/pages/#{name}.rb", '_page.rb')) + end - def generate_feature - template('feature.tt', default_path("features/#{name}.feature", '.feature')) - end + def generate_feature + template('feature.tt', default_path("features/#{name}.feature", '.feature')) + end - def generate_spec - template('spec.tt', default_path("spec/#{name}_page_spec.rb", '_spec.rb')) - end + def generate_spec + template('spec.tt', default_path("spec/#{name}_page_spec.rb", '_spec.rb')) + end - def generate_helper - template('helper.tt', default_path("helpers/#{name}_helper.rb", '_helper.rb')) - end + def generate_helper + template('helper.tt', default_path("helpers/#{name}_helper.rb", '_helper.rb')) + end - def generate_steps - template('steps.tt', default_path("features/step_definitions/#{name}_steps.rb", '_steps.rb')) - end + def generate_steps + template('steps.tt', default_path("features/step_definitions/#{name}_steps.rb", '_steps.rb')) + end - def generate_config - template('../../generators/templates/common/config.tt', - default_path('config/config.yml', '.yml')) - end + def generate_config + template('../../generators/templates/common/config.tt', + default_path('config/config.yml', '.yml')) + end - def delete_page - remove_file(default_path("page_objects/pages/#{name}.rb", '_page.rb')) - end + def delete_page + remove_file(default_path("page_objects/pages/#{name}.rb", '_page.rb')) + end - def delete_feature - remove_file(default_path("features/#{name}.feature", '.feature')) - end + def delete_feature + remove_file(default_path("features/#{name}.feature", '.feature')) + end - def delete_spec - remove_file(default_path("spec/#{name}_page_spec.rb", '_spec.rb')) - end + def delete_spec + remove_file(default_path("spec/#{name}_page_spec.rb", '_spec.rb')) + end - def delete_helper - remove_file(default_path("helpers/#{name}_helper.rb", '_helper.rb')) - end + def delete_helper + remove_file(default_path("helpers/#{name}_helper.rb", '_helper.rb')) + end - def delete_steps - remove_file(default_path("features/step_definitions/#{name}_steps.rb", '_steps.rb')) - end + def delete_steps + remove_file(default_path("features/step_definitions/#{name}_steps.rb", '_steps.rb')) + end - def delete_config - remove_file(default_path('config/config.yml', '.yml')) - end + def delete_config + remove_file(default_path('config/config.yml', '.yml')) + end - def default_path(standard_path, file_type) - path ? "#{path}/#{name}#{file_type}" : standard_path + def default_path(standard_path, file_type) + path ? "#{path}/#{name}#{file_type}" : standard_path + end end end diff --git a/lib/utilities/utilities.rb b/lib/utilities/utilities.rb index 45257a0..65d547e 100644 --- a/lib/utilities/utilities.rb +++ b/lib/utilities/utilities.rb @@ -2,10 +2,10 @@ require 'yaml' -module Utilities - @path = 'config/config.yml' +module RubyRaider + module Utilities + module_function - class << self def browser=(browser) config['browser'] = browser overwrite_yaml @@ -45,12 +45,12 @@ def browser_options=(*opts) args = opts.flatten browser_args = config['browser_arguments'] browser = args.first&.to_sym - browser_args[browser] = browser_args[browser] + args[1..] if browser_args.key?(browser) + browser_args[browser] = browser_args[browser] + args[1..] if browser_args.&key?(browser) overwrite_yaml end def delete_browser_options - config.delete('browser_options') + config&.delete('browser_options') overwrite_yaml end @@ -59,19 +59,21 @@ def run(opts = nil) system "#{command} #{opts}" end - def parallel_run(opts = nil, _settings = nil) + def parallel_run(opts = nil) command = File.directory?('spec') ? 'parallel_rspec spec/' : 'parallel_cucumber features' system "#{command} #{opts}" end private + PATH = 'config/config.yml' + def overwrite_yaml - File.open(@path, 'w') { |file| YAML.dump(config, file) } + File.open(PATH, 'w') { |file| YAML.dump(config, file) } end def config - @config ||= File.exist?(@path) ? YAML.load_file(@path) : nil + @config ||= File.exist?(PATH) ? YAML.load_file(PATH) : nil end end end diff --git a/ruby_raider.gemspec b/ruby_raider.gemspec index bdef667..711d043 100644 --- a/ruby_raider.gemspec +++ b/ruby_raider.gemspec @@ -19,6 +19,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'rubocop', '~> 1.27' s.add_development_dependency 'rubocop-performance', '~> 1.15.0' s.add_development_dependency 'rubocop-rspec', '~> 2.9.0' + s.add_development_dependency 'steep', '~> 1.7.0' s.add_runtime_dependency 'thor', '~> 1.2.1' s.add_runtime_dependency 'tty-prompt', '~> 0.23.1' diff --git a/sig/gems/tty.rbs b/sig/gems/tty.rbs new file mode 100644 index 0000000..4c2ed19 --- /dev/null +++ b/sig/gems/tty.rbs @@ -0,0 +1,4 @@ +module TTY + class Prompt + end +end \ No newline at end of file diff --git a/sig/lib/commands/scaffolding_commands.rbs b/sig/lib/commands/scaffolding_commands.rbs new file mode 100644 index 0000000..edd6fd1 --- /dev/null +++ b/sig/lib/commands/scaffolding_commands.rbs @@ -0,0 +1,19 @@ +class ScaffoldingCommands < Thor + def delete_scaffolding: -> File + + def generate_scaffolding: -> File + + def load_config_path: -> String? + + def page: (String name) -> File + + def feature: (String name) -> File + + def spec: (String name) -> File + + def helper: (String name) -> File + + def steps: (String name) -> File + + def scaffold: (String name) -> File +end diff --git a/sig/lib/commands/utility_commands.rbs b/sig/lib/commands/utility_commands.rbs new file mode 100644 index 0000000..0335a4e --- /dev/null +++ b/sig/lib/commands/utility_commands.rbs @@ -0,0 +1,17 @@ +module RubyRaider + class UtilityCommands < Thor + def path: (String default_path) -> String + + def url: (String default_url) -> String + + def browser: (String default_browser) -> File + + def browser_options: (*String opts) -> File + + def raid: () -> bool? + + def platform: (String platform) -> String + + def start_appium: () -> bool? + end +end diff --git a/sig/lib/generators/actions/actions_generator.rbs b/sig/lib/generators/actions/actions_generator.rbs new file mode 100644 index 0000000..24351d6 --- /dev/null +++ b/sig/lib/generators/actions/actions_generator.rbs @@ -0,0 +1,5 @@ +module RubyRaider + class ActionsGenerator < Generator + def generate_actions_file: () -> File + end +end diff --git a/sig/lib/generators/automation/automation_generator.rbs b/sig/lib/generators/automation/automation_generator.rbs new file mode 100644 index 0000000..506c394 --- /dev/null +++ b/sig/lib/generators/automation/automation_generator.rbs @@ -0,0 +1,35 @@ +module RubyRaider + class AutomationGenerator < Generator + def generate_automation_files: () -> File + + private + + def generate_pages: () -> File + + def generate_components: () -> File + + def generate_model_files: () -> File + + def generate_abstract_page: () -> File + + def generate_abstract_component: () -> File + + def generate_appium_settings: () -> File + + def generate_visual_options: () -> File + + def generate_login_page: () -> File + + def generate_account_page: () -> File + + def generate_home_page: () -> File + + def generate_pdp_page: () -> File + + def generate_header_component: () -> File + + def generate_model_factory: () -> File + + def generate_model_data: () -> File + end +end diff --git a/sig/lib/generators/common_generator.rbs b/sig/lib/generators/common_generator.rbs new file mode 100644 index 0000000..d8ef91b --- /dev/null +++ b/sig/lib/generators/common_generator.rbs @@ -0,0 +1,19 @@ +module RubyRaider + class CommonGenerator < Generator + def generate_readme_file: () -> File + + def generate_config_file: () -> File + + def generate_rake_file: () -> File + + def generate_gemfile: () -> File + + def generate_reek_file: () -> File + + def generate_rubocop_file: () -> File + + def generate_gitignore_file: () -> File + + def create_allure_folder: () -> File + end +end diff --git a/sig/lib/generators/cucumber/cucumber_generator.rbs b/sig/lib/generators/cucumber/cucumber_generator.rbs new file mode 100644 index 0000000..4de5585 --- /dev/null +++ b/sig/lib/generators/cucumber/cucumber_generator.rbs @@ -0,0 +1,19 @@ +module RubyRaider + class CucumberGenerator < Generator + @template_name: String + + def generate_feature: () -> File + + def generate_steps: () -> File + + def generate_user_factory: () -> File + + def generate_env_file: () -> File + + def generate_world: () -> File + + def generate_cucumber_file: () -> File + + def template_name: () -> String + end +end diff --git a/sig/lib/generators/generator.rbs b/sig/lib/generators/generator.rbs new file mode 100644 index 0000000..0b835fd --- /dev/null +++ b/sig/lib/generators/generator.rbs @@ -0,0 +1,43 @@ +module RubyRaider + class Generator < Thor::Group + @_initializer: Array[String] + + include Thor::Actions + + def self.source_paths: () -> Array[String] + + def args: () -> String? + + def cucumber?: () -> bool + + def cross_platform?: () -> bool + + def mobile?: () -> bool + + def single_platform?: () -> bool + + def ios?: () -> bool + + def android?: () -> bool + + def rspec?: () -> bool + + def selenium?: () -> bool + + def visual?: () -> bool + + def watir?: () -> bool + + def web?: () -> bool + + def axe?: () -> bool + + def selenium_based?: () -> bool + + private + + def _initializer: () -> Array[String] + + alias initializer _initializer + end +end diff --git a/sig/lib/generators/helper_generator.rbs b/sig/lib/generators/helper_generator.rbs new file mode 100644 index 0000000..72f7e8e --- /dev/null +++ b/sig/lib/generators/helper_generator.rbs @@ -0,0 +1,21 @@ +module RubyRaider + class HelpersGenerator < Generator + def generate_helpers: () -> File + + private + + def generate_allure_helper: () -> File + + def generate_browser_helper: () -> File + + def generate_spec_helper: () -> File + + def generate_driver_helper: () -> File + + def generate_appium_helper: () -> File + + def generate_visual_helper: () -> File + + def generate_visual_spec_helper: () -> File + end +end diff --git a/sig/lib/generators/invoke_generators.rbs b/sig/lib/generators/invoke_generators.rbs new file mode 100644 index 0000000..7753cc1 --- /dev/null +++ b/sig/lib/generators/invoke_generators.rbs @@ -0,0 +1,11 @@ +module RubyRaider + module InvokeGenerators + def self?.generate_framework: (Hash[Symbol, String] structure) -> void + + def self?.add_generator: (Array[String] generators, *String gens) -> untyped + + def self?.invoke_generator: (Hash[Symbol, String] structure) -> void + + def self?.to_bool: (String string) -> bool + end +end diff --git a/sig/lib/generators/menu_generator.rbs b/sig/lib/generators/menu_generator.rbs new file mode 100644 index 0000000..5d45bda --- /dev/null +++ b/sig/lib/generators/menu_generator.rbs @@ -0,0 +1,37 @@ +module RubyRaider + class MenuGenerator + @prompt: TTY::Prompt + + @name: String + + attr_reader prompt: TTY::Prompt + + attr_reader name: String + + include InvokeGenerators + + def initialize: (String project_name) -> void + + def generate_choice_menu: () -> Array[String] + + def choose_test_framework: (String automation) -> Array[String] + + def set_up_framework: (Hash[Symbol, String] options) -> bool? + + def choose_mobile_platform: () -> Array[String] + + private + + def select_test_framework: (String automation) -> Array[String] + + FrameworkOptions: untyped + + def create_framework_options: (Hash[Symbol, String] params) -> untyped + + def create_framework: (untyped framework, untyped automation_type) -> untyped + + def yes_no_menu_choices: () -> { Yes: bool, No: bool, Quit: bool } + + def select_automation_framework: (Symbol menu) -> Array[String] + end +end diff --git a/sig/lib/generators/rspec/rspec_generator.rbs b/sig/lib/generators/rspec/rspec_generator.rbs new file mode 100644 index 0000000..688c433 --- /dev/null +++ b/sig/lib/generators/rspec/rspec_generator.rbs @@ -0,0 +1,9 @@ +module RubyRaider + class RspecGenerator < Generator + def generate_login_spec: () -> File + + def generate_pdp_spec: () -> File + + def generate_account_spec: () -> File + end +end diff --git a/sig/lib/ruby_raider.rbs b/sig/lib/ruby_raider.rbs new file mode 100644 index 0000000..8082032 --- /dev/null +++ b/sig/lib/ruby_raider.rbs @@ -0,0 +1,11 @@ +# :reek:FeatureEnvy { enabled: false } +# :reek:UtilityFunction { enabled: false } +module RubyRaider + class Raider < Thor + def current_version: -> String + + def new: (String project_name) -> void + + def version: () -> String? + end +end diff --git a/sig/lib/scaffolding/scaffolding.rbs b/sig/lib/scaffolding/scaffolding.rbs new file mode 100644 index 0000000..cd28906 --- /dev/null +++ b/sig/lib/scaffolding/scaffolding.rbs @@ -0,0 +1,33 @@ +module RubyRaider + class Scaffolding < Thor::Group + include Thor::Actions + + def self.source_root: () -> String + + def generate_page: () -> File + + def generate_feature: () -> File + + def generate_spec: () -> File + + def generate_helper: () -> File + + def generate_steps: () -> File + + def generate_config: () -> File + + def delete_page: () -> void + + def delete_feature: () -> void + + def delete_spec: () -> void + + def delete_helper: () -> void + + def delete_steps: () -> void + + def delete_config: () -> void + + def default_path: (String standard_path, String file_type) -> String + end +end diff --git a/sig/lib/utilities/logger.rbs b/sig/lib/utilities/logger.rbs new file mode 100644 index 0000000..281a53d --- /dev/null +++ b/sig/lib/utilities/logger.rbs @@ -0,0 +1,9 @@ +module RubyRaider + module Logger + self.@logger: Logger + + extend Forwardable + + def self.logger: () -> Logger + end +end diff --git a/sig/lib/utilities/utilities.rbs b/sig/lib/utilities/utilities.rbs new file mode 100644 index 0000000..c5e1b7d --- /dev/null +++ b/sig/lib/utilities/utilities.rbs @@ -0,0 +1,35 @@ +module RubyRaider + module Utilities + @config: String? + + def self?.browser=: (String browser) -> File + + def self?.page_path=: (String path) -> File + + def self?.spec_path=: (String path) -> File + + def self?.feature_path=: (String path) -> File + + def self?.helper_path=: (String path) -> File + + def self?.url=: (String url) -> File + + def self?.platform=: (String platform) -> File + + def self?.browser_options=: (*String opts) -> File + + def self?.delete_browser_options: () -> File + + def self?.run: (Array[String]? opts) -> bool? + + def self?.parallel_run: (Array[String]? opts) -> bool? + + private + + PATH: String + + def self?.overwrite_yaml: () -> File + + def self?.config: () -> String? + end +end