ruby_raider 1.1.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/e2e_tests.yml +58 -0
- data/.github/workflows/integration.yml +4 -6
- data/.github/workflows/reek.yml +6 -5
- data/.github/workflows/release.yml +175 -0
- data/.github/workflows/rubocop.yml +7 -6
- data/.github/workflows/steep.yml +21 -0
- data/.github/workflows/system_tests.yml +83 -0
- data/.gitignore +1 -1
- data/.reek.yml +46 -4
- data/.rubocop.yml +24 -0
- data/.ruby-version +1 -1
- data/README.md +140 -77
- data/RELEASE.md +412 -0
- data/RELEASE_QUICK_GUIDE.md +77 -0
- data/Steepfile +22 -0
- data/assets/ruby_raider_logo.svg +51 -0
- data/bin/release +186 -0
- data/lib/adopter/adopt_menu.rb +146 -0
- data/lib/adopter/converters/base_converter.rb +84 -0
- data/lib/adopter/converters/identity_converter.rb +53 -0
- data/lib/adopter/migration_plan.rb +74 -0
- data/lib/adopter/migrator.rb +96 -0
- data/lib/adopter/plan_builder.rb +275 -0
- data/lib/adopter/project_analyzer.rb +252 -0
- data/lib/adopter/project_detector.rb +157 -0
- data/lib/commands/adopt_commands.rb +42 -0
- data/lib/commands/plugin_commands.rb +0 -2
- data/lib/commands/scaffolding_commands.rb +220 -37
- data/lib/commands/utility_commands.rb +82 -2
- data/lib/generators/automation/automation_generator.rb +0 -7
- data/lib/generators/automation/templates/account.tt +9 -5
- data/lib/generators/automation/templates/appium_caps.tt +60 -6
- data/lib/generators/automation/templates/home.tt +4 -4
- data/lib/generators/automation/templates/login.tt +61 -4
- data/lib/generators/automation/templates/page.tt +13 -7
- data/lib/generators/automation/templates/partials/element.tt +1 -1
- data/lib/generators/automation/templates/partials/home_page_selector.tt +4 -4
- data/lib/generators/automation/templates/partials/initialize_selector.tt +3 -8
- data/lib/generators/automation/templates/partials/pdp_page_selector.tt +4 -4
- data/lib/generators/automation/templates/partials/url_methods.tt +0 -1
- data/lib/generators/automation/templates/partials/visit_method.tt +11 -1
- data/lib/generators/automation/templates/pdp.tt +1 -1
- data/lib/generators/common_generator.rb +12 -0
- data/lib/generators/cucumber/cucumber_generator.rb +36 -0
- data/lib/generators/cucumber/templates/accessibility_feature.tt +5 -0
- data/lib/generators/cucumber/templates/accessibility_steps.tt +21 -0
- data/lib/generators/cucumber/templates/cucumber.tt +8 -1
- data/lib/generators/cucumber/templates/env.tt +6 -4
- data/lib/generators/cucumber/templates/feature.tt +0 -4
- data/lib/generators/cucumber/templates/partials/appium_env.tt +5 -0
- data/lib/generators/cucumber/templates/partials/capybara_env.tt +38 -0
- data/lib/generators/cucumber/templates/partials/capybara_world.tt +6 -0
- data/lib/generators/cucumber/templates/partials/driver_world.tt +1 -4
- data/lib/generators/cucumber/templates/partials/mobile_steps.tt +2 -2
- data/lib/generators/cucumber/templates/partials/selenium_env.tt +22 -35
- data/lib/generators/cucumber/templates/partials/watir_env.tt +20 -1
- data/lib/generators/cucumber/templates/partials/web_steps.tt +10 -15
- data/lib/generators/cucumber/templates/performance_feature.tt +5 -0
- data/lib/generators/cucumber/templates/performance_steps.tt +17 -0
- data/lib/generators/cucumber/templates/steps.tt +2 -2
- data/lib/generators/cucumber/templates/visual_feature.tt +5 -0
- data/lib/generators/cucumber/templates/visual_steps.tt +19 -0
- data/lib/generators/cucumber/templates/world.tt +5 -3
- data/lib/generators/generator.rb +50 -7
- data/lib/generators/helper_generator.rb +39 -9
- data/lib/generators/infrastructure/github_generator.rb +6 -0
- data/lib/generators/infrastructure/templates/github.tt +12 -8
- data/lib/generators/infrastructure/templates/github_appium.tt +108 -0
- data/lib/generators/infrastructure/templates/gitlab.tt +6 -3
- data/lib/generators/invoke_generators.rb +43 -9
- data/lib/generators/menu_generator.rb +122 -11
- data/lib/generators/minitest/minitest_generator.rb +35 -0
- data/lib/generators/minitest/templates/accessibility_test.tt +26 -0
- data/lib/generators/minitest/templates/performance_test.tt +18 -0
- data/lib/generators/minitest/templates/test.tt +64 -0
- data/lib/generators/minitest/templates/visual_test.tt +23 -0
- data/lib/generators/rspec/rspec_generator.rb +16 -4
- data/lib/generators/rspec/templates/accessibility_spec.tt +25 -0
- data/lib/generators/rspec/templates/performance_spec.tt +18 -0
- data/lib/generators/rspec/templates/spec.tt +13 -41
- data/lib/generators/rspec/templates/visual_spec.tt +20 -0
- data/lib/generators/template_renderer/partial_cache.rb +126 -0
- data/lib/generators/template_renderer/partial_resolver.rb +110 -0
- data/lib/generators/template_renderer/template_error.rb +50 -0
- data/lib/generators/template_renderer.rb +106 -0
- data/lib/generators/templates/common/config.tt +2 -2
- data/lib/generators/templates/common/gemfile.tt +36 -9
- data/lib/generators/templates/common/git_ignore.tt +6 -1
- data/lib/generators/templates/common/partials/mobile_config.tt +5 -1
- data/lib/generators/templates/common/partials/web_config.tt +17 -8
- data/lib/generators/templates/common/rakefile.tt +36 -0
- data/lib/generators/templates/common/read_me.tt +43 -91
- data/lib/generators/templates/common/rspec.tt +3 -0
- data/lib/generators/templates/common/ruby_version.tt +1 -0
- data/lib/generators/templates/helpers/allure_helper.tt +13 -2
- data/lib/generators/templates/helpers/browser_helper.tt +13 -2
- data/lib/generators/templates/helpers/capybara_helper.tt +32 -0
- data/lib/generators/templates/helpers/debug_helper.tt +190 -0
- data/lib/generators/templates/helpers/driver_helper.tt +3 -11
- data/lib/generators/templates/helpers/partials/allure_imports.tt +3 -1
- data/lib/generators/templates/helpers/partials/allure_requirements.tt +3 -1
- data/lib/generators/templates/helpers/partials/appium_driver.tt +44 -0
- data/lib/generators/templates/helpers/partials/browserstack_config.tt +13 -0
- data/lib/generators/templates/helpers/partials/debug_diagnostics.tt +7 -0
- data/lib/generators/templates/helpers/partials/debug_start.tt +7 -0
- data/lib/generators/templates/helpers/partials/driver_and_options.tt +5 -115
- data/lib/generators/templates/helpers/partials/quit_driver.tt +3 -1
- data/lib/generators/templates/helpers/partials/screenshot.tt +3 -1
- data/lib/generators/templates/helpers/partials/selenium_driver.tt +26 -0
- data/lib/generators/templates/helpers/partials/video_start.tt +9 -0
- data/lib/generators/templates/helpers/partials/video_stop.tt +4 -0
- data/lib/generators/templates/helpers/performance_helper.tt +57 -0
- data/lib/generators/templates/helpers/spec_helper.tt +72 -10
- data/lib/generators/templates/helpers/test_helper.tt +94 -0
- data/lib/generators/templates/helpers/video_helper.tt +270 -0
- data/lib/generators/templates/helpers/visual_helper.tt +39 -46
- data/lib/llm/client.rb +79 -0
- data/lib/llm/config.rb +57 -0
- data/lib/llm/prompts.rb +84 -0
- data/lib/llm/provider.rb +27 -0
- data/lib/llm/providers/anthropic_provider.rb +43 -0
- data/lib/llm/providers/ollama_provider.rb +56 -0
- data/lib/llm/providers/openai_provider.rb +42 -0
- data/lib/llm/response_parser.rb +67 -0
- data/lib/plugin/plugin.rb +22 -20
- data/lib/plugin/plugin_exposer.rb +16 -38
- data/lib/ruby_raider.rb +51 -11
- data/lib/scaffolding/crud_generator.rb +94 -0
- data/lib/scaffolding/dry_run_presenter.rb +16 -0
- data/lib/scaffolding/name_normalizer.rb +63 -0
- data/lib/scaffolding/page_introspector.rb +45 -0
- data/lib/scaffolding/project_detector.rb +72 -0
- data/lib/scaffolding/scaffold_menu.rb +103 -0
- data/lib/scaffolding/scaffolding.rb +158 -11
- data/lib/scaffolding/templates/component.tt +30 -0
- data/lib/scaffolding/templates/feature.tt +4 -4
- data/lib/scaffolding/templates/helper.tt +15 -1
- data/lib/scaffolding/templates/page_from_url.tt +75 -0
- data/lib/scaffolding/templates/page_object.tt +50 -1
- data/lib/scaffolding/templates/spec.tt +33 -2
- data/lib/scaffolding/templates/spec_from_page.tt +31 -0
- data/lib/scaffolding/templates/spec_from_url.tt +46 -0
- data/lib/scaffolding/templates/steps.tt +17 -5
- data/lib/scaffolding/url_analyzer.rb +179 -0
- data/lib/utilities/desktop_downloader.rb +177 -0
- data/lib/utilities/logo.rb +83 -0
- data/lib/utilities/utilities.rb +53 -20
- data/lib/version +1 -1
- data/ruby_raider.gemspec +1 -0
- data/sig/adopter/adopt_menu.rbs +25 -0
- data/sig/adopter/converters/base_converter.rbs +23 -0
- data/sig/adopter/converters/identity_converter.rbs +16 -0
- data/sig/adopter/migration_plan.rbs +34 -0
- data/sig/adopter/migrator.rbs +21 -0
- data/sig/adopter/plan_builder.rbs +38 -0
- data/sig/adopter/project_analyzer.rbs +39 -0
- data/sig/adopter/project_detector.rbs +26 -0
- data/sig/commands/adopt_commands.rbs +8 -0
- data/sig/commands/loaded_commands.rbs +5 -0
- data/sig/commands/plugin_commands.rbs +9 -0
- data/sig/commands/scaffolding_commands.rbs +28 -0
- data/sig/commands/utility_commands.rbs +21 -0
- data/sig/generators/automation/automation_generator.rbs +20 -0
- data/sig/generators/common_generator.rbs +12 -0
- data/sig/generators/cucumber/cucumber_generator.rbs +16 -0
- data/sig/generators/generator.rbs +40 -0
- data/sig/generators/helper_generator.rbs +18 -0
- data/sig/generators/infrastructure/github_generator.rbs +5 -0
- data/sig/generators/infrastructure/gitlab_generator.rbs +4 -0
- data/sig/generators/invoke_generators.rbs +10 -0
- data/sig/generators/menu_generator.rbs +29 -0
- data/sig/generators/minitest/minitest_generator.rbs +8 -0
- data/sig/generators/rspec/rspec_generator.rbs +8 -0
- data/sig/generators/template_renderer/partial_cache.rbs +20 -0
- data/sig/generators/template_renderer/partial_resolver.rbs +20 -0
- data/sig/generators/template_renderer/template_error.rbs +19 -0
- data/sig/generators/template_renderer.rbs +10 -0
- data/sig/llm/client.rbs +15 -0
- data/sig/llm/config.rbs +20 -0
- data/sig/llm/prompts.rbs +8 -0
- data/sig/llm/provider.rbs +12 -0
- data/sig/llm/providers/anthropic_provider.rbs +16 -0
- data/sig/llm/providers/ollama_provider.rbs +18 -0
- data/sig/llm/providers/openai_provider.rbs +16 -0
- data/sig/llm/response_parser.rbs +13 -0
- data/sig/plugin/plugin.rbs +24 -0
- data/sig/plugin/plugin_exposer.rbs +20 -0
- data/sig/ruby_raider.rbs +15 -0
- data/sig/scaffolding/crud_generator.rbs +16 -0
- data/sig/scaffolding/dry_run_presenter.rbs +4 -0
- data/sig/scaffolding/name_normalizer.rbs +17 -0
- data/sig/scaffolding/page_introspector.rbs +14 -0
- data/sig/scaffolding/project_detector.rbs +14 -0
- data/sig/scaffolding/scaffold_menu.rbs +18 -0
- data/sig/scaffolding/scaffolding.rbs +55 -0
- data/sig/scaffolding/url_analyzer.rbs +28 -0
- data/sig/utilities/desktop_downloader.rbs +23 -0
- data/sig/utilities/logger.rbs +13 -0
- data/sig/utilities/logo.rbs +16 -0
- data/sig/utilities/utilities.rbs +30 -0
- data/sig/vendor/thor.rbs +34 -0
- data/sig/vendor/tty_prompt.rbs +15 -0
- data/spec/adopter/adopt_menu_spec.rb +176 -0
- data/spec/adopter/converters/identity_converter_spec.rb +145 -0
- data/spec/adopter/migration_plan_spec.rb +113 -0
- data/spec/adopter/migrator_spec.rb +277 -0
- data/spec/adopter/plan_builder_spec.rb +298 -0
- data/spec/adopter/project_analyzer_spec.rb +337 -0
- data/spec/adopter/project_detector_spec.rb +295 -0
- data/spec/commands/raider_commands_spec.rb +129 -0
- data/spec/generators/fixtures/templates/test.tt +1 -0
- data/spec/generators/fixtures/templates/test_partial.tt +1 -0
- data/spec/generators/generator_spec.rb +23 -0
- data/spec/generators/template_renderer_spec.rb +298 -0
- data/spec/integration/commands/scaffolding_commands_spec.rb +2 -2
- data/spec/integration/commands/utility_commands_spec.rb +24 -4
- data/spec/integration/content/ci_content_spec.rb +119 -0
- data/spec/integration/content/common_content_spec.rb +288 -0
- data/spec/integration/content/config_content_spec.rb +175 -0
- data/spec/integration/content/content_helper.rb +32 -0
- data/spec/integration/content/gemfile_content_spec.rb +209 -0
- data/spec/integration/content/helper_content_spec.rb +485 -0
- data/spec/integration/content/page_content_spec.rb +259 -0
- data/spec/integration/content/reporter_content_spec.rb +236 -0
- data/spec/integration/content/skip_flags_content_spec.rb +206 -0
- data/spec/integration/content/syntax_validation_spec.rb +30 -0
- data/spec/integration/content/test_content_spec.rb +266 -0
- data/spec/integration/end_to_end_features_spec.rb +690 -0
- data/spec/integration/end_to_end_spec.rb +361 -0
- data/spec/integration/generators/automation_generator_spec.rb +9 -21
- data/spec/integration/generators/axe_addon_spec.rb +150 -0
- data/spec/integration/generators/common_generator_spec.rb +48 -49
- data/spec/integration/generators/config_features_spec.rb +155 -0
- data/spec/integration/generators/cucumber_generator_spec.rb +7 -7
- data/spec/integration/generators/debug_helper_spec.rb +68 -0
- data/spec/integration/generators/github_generator_spec.rb +8 -8
- data/spec/integration/generators/gitlab_generator_spec.rb +8 -8
- data/spec/integration/generators/helpers_generator_spec.rb +70 -44
- data/spec/integration/generators/lighthouse_addon_spec.rb +132 -0
- data/spec/integration/generators/minitest_generator_spec.rb +64 -0
- data/spec/integration/generators/reporter_spec.rb +159 -0
- data/spec/integration/generators/rspec_generator_spec.rb +7 -7
- data/spec/integration/generators/skip_flags_spec.rb +134 -0
- data/spec/integration/generators/visual_addon_spec.rb +148 -0
- data/spec/integration/settings_helper.rb +1 -4
- data/spec/integration/spec_helper.rb +46 -11
- data/spec/llm/client_spec.rb +79 -0
- data/spec/llm/config_spec.rb +92 -0
- data/spec/llm/prompts_spec.rb +49 -0
- data/spec/llm/response_parser_spec.rb +92 -0
- data/spec/menus/adopter_adopt_menu_spec.rb +97 -0
- data/spec/menus/menu_generator_spec.rb +263 -0
- data/spec/scaffolding/name_normalizer_spec.rb +113 -0
- data/spec/scaffolding/page_introspector_spec.rb +82 -0
- data/spec/scaffolding/scaffold_project_detector_spec.rb +104 -0
- data/spec/scaffolding/scaffolding_features_spec.rb +311 -0
- data/spec/scaffolding/url_analyzer_spec.rb +110 -0
- data/spec/system/adopt_matrix_spec.rb +537 -0
- data/spec/system/adopt_spec.rb +225 -0
- data/spec/system/capybara_spec.rb +42 -0
- data/spec/system/selenium_spec.rb +19 -17
- data/spec/system/support/system_test_helper.rb +33 -0
- data/spec/system/watir_spec.rb +19 -17
- data/spec/utilities/desktop_downloader_spec.rb +92 -0
- metadata +193 -18
- data/.github/workflows/push_gem.yml +0 -37
- data/.github/workflows/selenium.yml +0 -22
- data/.github/workflows/watir.yml +0 -22
- data/lib/generators/automation/templates/partials/android_caps.tt +0 -17
- data/lib/generators/automation/templates/partials/cross_platform_caps.tt +0 -25
- data/lib/generators/automation/templates/partials/ios_caps.tt +0 -18
- data/lib/generators/automation/templates/partials/selenium_account.tt +0 -9
- data/lib/generators/automation/templates/partials/selenium_login.tt +0 -34
- data/lib/generators/automation/templates/partials/watir_account.tt +0 -7
- data/lib/generators/automation/templates/partials/watir_login.tt +0 -32
- data/lib/generators/automation/templates/visual_options.tt +0 -16
- data/lib/generators/templates/helpers/visual_spec_helper.tt +0 -35
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'rspec'
|
|
5
|
+
require_relative '../../lib/adopter/adopt_menu'
|
|
6
|
+
|
|
7
|
+
RSpec.describe Adopter::AdoptMenu do
|
|
8
|
+
let(:source_dir) { 'tmp_adopt_menu_source' }
|
|
9
|
+
let(:output_dir) { 'tmp_adopt_menu_output' }
|
|
10
|
+
|
|
11
|
+
before do
|
|
12
|
+
FileUtils.mkdir_p(source_dir)
|
|
13
|
+
File.write("#{source_dir}/Gemfile", "gem 'rspec'\ngem 'selenium-webdriver'\ngem 'faker'\n")
|
|
14
|
+
FileUtils.mkdir_p("#{source_dir}/pages")
|
|
15
|
+
FileUtils.mkdir_p("#{source_dir}/spec")
|
|
16
|
+
|
|
17
|
+
File.write("#{source_dir}/pages/login_page.rb", <<~RUBY)
|
|
18
|
+
class LoginPage < BasePage
|
|
19
|
+
def login(user, pass)
|
|
20
|
+
driver.find_element(id: 'user').send_keys user
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
RUBY
|
|
24
|
+
|
|
25
|
+
File.write("#{source_dir}/spec/login_spec.rb", <<~RUBY)
|
|
26
|
+
describe 'Login' do
|
|
27
|
+
it 'can log in' do
|
|
28
|
+
expect(result).to eq 'ok'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
RUBY
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
after do
|
|
35
|
+
FileUtils.rm_rf(source_dir)
|
|
36
|
+
FileUtils.rm_rf(output_dir)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe '.adopt' do
|
|
40
|
+
let(:params) do
|
|
41
|
+
{
|
|
42
|
+
source_path: source_dir,
|
|
43
|
+
output_path: output_dir,
|
|
44
|
+
target_automation: 'selenium',
|
|
45
|
+
target_framework: 'rspec'
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'runs the full adoption pipeline' do
|
|
50
|
+
result = described_class.adopt(params)
|
|
51
|
+
|
|
52
|
+
expect(result[:plan]).to be_a(Adopter::MigrationPlan)
|
|
53
|
+
expect(result[:results][:pages]).to eq(1)
|
|
54
|
+
expect(result[:results][:tests]).to eq(1)
|
|
55
|
+
expect(File).to exist("#{output_dir}/Gemfile")
|
|
56
|
+
expect(File).to exist("#{output_dir}/page_objects/pages/login.rb")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'merges custom gems into the generated Gemfile' do
|
|
60
|
+
described_class.adopt(params)
|
|
61
|
+
|
|
62
|
+
gemfile = File.read("#{output_dir}/Gemfile")
|
|
63
|
+
expect(gemfile).to include("gem 'faker'")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'converts page content with raider conventions' do
|
|
67
|
+
described_class.adopt(params)
|
|
68
|
+
|
|
69
|
+
page = File.read("#{output_dir}/page_objects/pages/login.rb")
|
|
70
|
+
expect(page).to include('frozen_string_literal: true')
|
|
71
|
+
expect(page).to include('class LoginPage < Page')
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
context 'with capybara target' do
|
|
75
|
+
let(:params) do
|
|
76
|
+
{
|
|
77
|
+
source_path: source_dir,
|
|
78
|
+
output_path: output_dir,
|
|
79
|
+
target_automation: 'capybara',
|
|
80
|
+
target_framework: 'rspec'
|
|
81
|
+
}
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'removes driver arguments from page instantiation' do
|
|
85
|
+
File.write("#{source_dir}/spec/login_spec.rb", <<~RUBY)
|
|
86
|
+
describe 'Login' do
|
|
87
|
+
it 'can log in' do
|
|
88
|
+
@page = LoginPage.new(driver)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
RUBY
|
|
92
|
+
|
|
93
|
+
result = described_class.adopt(params)
|
|
94
|
+
test_content = result[:plan].converted_tests.first.content
|
|
95
|
+
expect(test_content).to include('LoginPage.new')
|
|
96
|
+
expect(test_content).not_to include('LoginPage.new(driver)')
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context 'with ci_platform' do
|
|
101
|
+
let(:params) do
|
|
102
|
+
{
|
|
103
|
+
source_path: source_dir,
|
|
104
|
+
output_path: output_dir,
|
|
105
|
+
target_automation: 'selenium',
|
|
106
|
+
target_framework: 'rspec',
|
|
107
|
+
ci_platform: 'github'
|
|
108
|
+
}
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it 'generates CI configuration' do
|
|
112
|
+
described_class.adopt(params)
|
|
113
|
+
|
|
114
|
+
expect(File).to exist("#{output_dir}/.github")
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe '.validate_params!' do
|
|
120
|
+
it 'raises on missing source_path' do
|
|
121
|
+
expect { described_class.validate_params!({}) }.to raise_error(ArgumentError, /source_path/)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it 'raises on missing output_path' do
|
|
125
|
+
expect { described_class.validate_params!(source_path: 'x') }.to raise_error(ArgumentError, /output_path/)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it 'raises on missing target_automation' do
|
|
129
|
+
expect do
|
|
130
|
+
described_class.validate_params!(source_path: 'x', output_path: 'y')
|
|
131
|
+
end.to raise_error(ArgumentError, /target_automation/)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it 'raises on missing target_framework' do
|
|
135
|
+
expect do
|
|
136
|
+
described_class.validate_params!(source_path: 'x', output_path: 'y', target_automation: 'selenium')
|
|
137
|
+
end.to raise_error(ArgumentError, /target_framework/)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it 'raises on invalid target_automation' do
|
|
141
|
+
expect do
|
|
142
|
+
described_class.validate_params!(
|
|
143
|
+
source_path: 'x', output_path: 'y',
|
|
144
|
+
target_automation: 'appium', target_framework: 'rspec'
|
|
145
|
+
)
|
|
146
|
+
end.to raise_error(ArgumentError, /target_automation must be/)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'raises on invalid target_framework' do
|
|
150
|
+
expect do
|
|
151
|
+
described_class.validate_params!(
|
|
152
|
+
source_path: 'x', output_path: 'y',
|
|
153
|
+
target_automation: 'selenium', target_framework: 'junit'
|
|
154
|
+
)
|
|
155
|
+
end.to raise_error(ArgumentError, /target_framework must be/)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it 'accepts valid params without raising' do
|
|
159
|
+
expect do
|
|
160
|
+
described_class.validate_params!(
|
|
161
|
+
source_path: 'x', output_path: 'y',
|
|
162
|
+
target_automation: 'selenium', target_framework: 'rspec'
|
|
163
|
+
)
|
|
164
|
+
end.not_to raise_error
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it 'accepts capybara as valid automation' do
|
|
168
|
+
expect do
|
|
169
|
+
described_class.validate_params!(
|
|
170
|
+
source_path: 'x', output_path: 'y',
|
|
171
|
+
target_automation: 'capybara', target_framework: 'minitest'
|
|
172
|
+
)
|
|
173
|
+
end.not_to raise_error
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rspec'
|
|
4
|
+
require_relative '../../../lib/adopter/converters/identity_converter'
|
|
5
|
+
|
|
6
|
+
RSpec.describe Adopter::Converters::IdentityConverter do
|
|
7
|
+
describe '#convert_page' do
|
|
8
|
+
context 'targeting selenium' do
|
|
9
|
+
let(:converter) { described_class.new('selenium') }
|
|
10
|
+
|
|
11
|
+
it 'adds frozen_string_literal if missing' do
|
|
12
|
+
input = "class LoginPage < BasePage\nend\n"
|
|
13
|
+
result = converter.convert_page(input, {})
|
|
14
|
+
expect(result).to start_with('# frozen_string_literal: true')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'does not duplicate frozen_string_literal' do
|
|
18
|
+
input = "# frozen_string_literal: true\n\nclass LoginPage < Page\nend\n"
|
|
19
|
+
result = converter.convert_page(input, {})
|
|
20
|
+
expect(result.scan('frozen_string_literal').length).to eq(1)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'updates base class to Page' do
|
|
24
|
+
input = "class LoginPage < BasePage\nend\n"
|
|
25
|
+
result = converter.convert_page(input, {})
|
|
26
|
+
expect(result).to include('class LoginPage < Page')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'preserves non-page base classes' do
|
|
30
|
+
input = "class UserFactory < ModelFactory\nend\n"
|
|
31
|
+
result = converter.convert_page(input, {})
|
|
32
|
+
expect(result).to include('class UserFactory < ModelFactory')
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'adds require_relative for abstract page' do
|
|
36
|
+
input = "class LoginPage < BasePage\nend\n"
|
|
37
|
+
result = converter.convert_page(input, {})
|
|
38
|
+
expect(result).to include("require_relative '../abstract/page'")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'does not duplicate page require' do
|
|
42
|
+
input = "require_relative '../abstract/page'\n\nclass LoginPage < Page\nend\n"
|
|
43
|
+
result = converter.convert_page(input, {})
|
|
44
|
+
expect(result.scan("require_relative '../abstract/page'").length).to eq(1)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'swaps browser to driver in page instantiation' do
|
|
48
|
+
input = "class Test\n @page = LoginPage.new(browser)\nend\n"
|
|
49
|
+
result = converter.convert_page(input, {})
|
|
50
|
+
expect(result).to include('LoginPage.new(driver)')
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context 'targeting capybara' do
|
|
55
|
+
let(:converter) { described_class.new('capybara') }
|
|
56
|
+
|
|
57
|
+
it 'removes driver argument from page instantiation' do
|
|
58
|
+
input = "class Test\n @page = LoginPage.new(driver)\nend\n"
|
|
59
|
+
result = converter.convert_page(input, {})
|
|
60
|
+
expect(result).to include('LoginPage.new')
|
|
61
|
+
expect(result).not_to include('LoginPage.new(driver)')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'removes browser argument from page instantiation' do
|
|
65
|
+
input = " @page = LoginPage.new(browser)\n"
|
|
66
|
+
result = converter.convert_page(input, {})
|
|
67
|
+
expect(result).to include('LoginPage.new')
|
|
68
|
+
expect(result).not_to include('LoginPage.new(browser)')
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context 'targeting watir' do
|
|
73
|
+
let(:converter) { described_class.new('watir') }
|
|
74
|
+
|
|
75
|
+
it 'swaps driver to browser in page instantiation' do
|
|
76
|
+
input = "class Test\n @page = LoginPage.new(driver)\nend\n"
|
|
77
|
+
result = converter.convert_page(input, {})
|
|
78
|
+
expect(result).to include('LoginPage.new(browser)')
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
describe '#convert_test' do
|
|
84
|
+
let(:converter) { described_class.new('selenium') }
|
|
85
|
+
|
|
86
|
+
it 'adds frozen_string_literal if missing' do
|
|
87
|
+
input = "describe 'Login' do\nend\n"
|
|
88
|
+
result = converter.convert_test(input, {})
|
|
89
|
+
expect(result).to start_with('# frozen_string_literal: true')
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'updates helper require paths for selenium' do
|
|
93
|
+
input = "require_relative '../support/browser_setup'\n\ndescribe 'x' do; end\n"
|
|
94
|
+
result = converter.convert_test(input, {})
|
|
95
|
+
expect(result).to include("require_relative '../helpers/driver_helper'")
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
context 'targeting capybara' do
|
|
99
|
+
let(:converter) { described_class.new('capybara') }
|
|
100
|
+
|
|
101
|
+
it 'updates helper require paths for capybara' do
|
|
102
|
+
input = "require_relative '../support/driver_helper'\n\ndescribe 'x' do; end\n"
|
|
103
|
+
result = converter.convert_test(input, {})
|
|
104
|
+
expect(result).to include("require_relative '../helpers/capybara_helper'")
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context 'targeting watir' do
|
|
109
|
+
let(:converter) { described_class.new('watir') }
|
|
110
|
+
|
|
111
|
+
it 'updates helper require paths for watir' do
|
|
112
|
+
input = "require_relative '../support/driver_setup'\n\ndescribe 'x' do; end\n"
|
|
113
|
+
result = converter.convert_test(input, {})
|
|
114
|
+
expect(result).to include("require_relative '../helpers/browser_helper'")
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
describe '#convert_step' do
|
|
120
|
+
context 'targeting capybara' do
|
|
121
|
+
let(:converter) { described_class.new('capybara') }
|
|
122
|
+
|
|
123
|
+
it 'removes driver argument from page instantiation in steps' do
|
|
124
|
+
input = <<~RUBY
|
|
125
|
+
Given('I am on the login page') do
|
|
126
|
+
@page = LoginPage.new(driver)
|
|
127
|
+
end
|
|
128
|
+
RUBY
|
|
129
|
+
result = converter.convert_step(input)
|
|
130
|
+
expect(result).to include('LoginPage.new')
|
|
131
|
+
expect(result).not_to include('LoginPage.new(driver)')
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
context 'targeting selenium' do
|
|
136
|
+
let(:converter) { described_class.new('selenium') }
|
|
137
|
+
|
|
138
|
+
it 'swaps browser to driver in step page instantiation' do
|
|
139
|
+
input = " @page = LoginPage.new(browser)\n"
|
|
140
|
+
result = converter.convert_step(input)
|
|
141
|
+
expect(result).to include('LoginPage.new(driver)')
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'rspec'
|
|
5
|
+
require_relative '../../lib/adopter/migration_plan'
|
|
6
|
+
|
|
7
|
+
RSpec.describe Adopter::MigrationPlan do
|
|
8
|
+
let(:converted_page) do
|
|
9
|
+
Adopter::ConvertedFile.new(
|
|
10
|
+
output_path: 'my_project/page_objects/pages/login.rb',
|
|
11
|
+
content: 'class Login < Page; end',
|
|
12
|
+
source_file: 'pages/login_page.rb',
|
|
13
|
+
conversion_notes: 'Converted from capybara to selenium'
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
let(:plan) do
|
|
18
|
+
described_class.new(
|
|
19
|
+
source_path: '/source',
|
|
20
|
+
output_path: '/output',
|
|
21
|
+
target_automation: 'selenium',
|
|
22
|
+
target_framework: 'rspec',
|
|
23
|
+
ci_platform: 'github',
|
|
24
|
+
skeleton_structure: { automation: 'selenium', framework: 'rspec', name: '/output' },
|
|
25
|
+
converted_pages: [converted_page],
|
|
26
|
+
converted_tests: [],
|
|
27
|
+
gemfile_additions: %w[faker httparty],
|
|
28
|
+
config_overrides: { browser: 'chrome', url: 'https://example.com' },
|
|
29
|
+
warnings: ['Complex matcher needs review'],
|
|
30
|
+
manual_actions: []
|
|
31
|
+
)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe '#to_h' do
|
|
35
|
+
it 'serializes all fields' do # rubocop:disable RSpec/MultipleExpectations
|
|
36
|
+
hash = plan.to_h
|
|
37
|
+
expect(hash[:source_path]).to eq('/source')
|
|
38
|
+
expect(hash[:output_path]).to eq('/output')
|
|
39
|
+
expect(hash[:target_automation]).to eq('selenium')
|
|
40
|
+
expect(hash[:target_framework]).to eq('rspec')
|
|
41
|
+
expect(hash[:converted_pages].length).to eq(1)
|
|
42
|
+
expect(hash[:gemfile_additions]).to eq(%w[faker httparty])
|
|
43
|
+
expect(hash[:config_overrides]).to eq(browser: 'chrome', url: 'https://example.com')
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'serializes converted files as hashes' do
|
|
47
|
+
page_hash = plan.to_h[:converted_pages].first
|
|
48
|
+
expect(page_hash[:output_path]).to eq('my_project/page_objects/pages/login.rb')
|
|
49
|
+
expect(page_hash[:source_file]).to eq('pages/login_page.rb')
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe '#to_json' do
|
|
54
|
+
it 'produces valid JSON' do
|
|
55
|
+
parsed = JSON.parse(plan.to_json)
|
|
56
|
+
expect(parsed['source_path']).to eq('/source')
|
|
57
|
+
expect(parsed['converted_pages'].length).to eq(1)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe '#summary' do
|
|
62
|
+
it 'returns counts' do
|
|
63
|
+
expect(plan.summary).to eq(
|
|
64
|
+
pages: 1,
|
|
65
|
+
tests: 0,
|
|
66
|
+
features: 0,
|
|
67
|
+
steps: 0,
|
|
68
|
+
custom_gems: 2,
|
|
69
|
+
warnings: 1,
|
|
70
|
+
manual_actions: 0
|
|
71
|
+
)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe 'defaults' do
|
|
76
|
+
it 'initializes with empty arrays and hashes' do
|
|
77
|
+
empty_plan = described_class.new
|
|
78
|
+
expect(empty_plan.converted_pages).to eq([])
|
|
79
|
+
expect(empty_plan.converted_tests).to eq([])
|
|
80
|
+
expect(empty_plan.gemfile_additions).to eq([])
|
|
81
|
+
expect(empty_plan.config_overrides).to eq({})
|
|
82
|
+
expect(empty_plan.warnings).to eq([])
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
RSpec.describe Adopter::ConvertedFile do
|
|
88
|
+
it 'stores file conversion data' do
|
|
89
|
+
file = described_class.new(
|
|
90
|
+
output_path: 'project/spec/login_spec.rb',
|
|
91
|
+
content: 'describe "Login" do; end',
|
|
92
|
+
source_file: 'spec/login_spec.rb',
|
|
93
|
+
conversion_notes: 'Restructured'
|
|
94
|
+
)
|
|
95
|
+
expect(file.output_path).to eq('project/spec/login_spec.rb')
|
|
96
|
+
expect(file.content).to eq('describe "Login" do; end')
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'serializes to hash' do
|
|
100
|
+
file = described_class.new(
|
|
101
|
+
output_path: 'out.rb',
|
|
102
|
+
content: 'code',
|
|
103
|
+
source_file: 'in.rb',
|
|
104
|
+
conversion_notes: 'notes'
|
|
105
|
+
)
|
|
106
|
+
expect(file.to_h).to eq(
|
|
107
|
+
output_path: 'out.rb',
|
|
108
|
+
content: 'code',
|
|
109
|
+
source_file: 'in.rb',
|
|
110
|
+
conversion_notes: 'notes'
|
|
111
|
+
)
|
|
112
|
+
end
|
|
113
|
+
end
|