-
-
Notifications
You must be signed in to change notification settings - Fork 62
Fix generator folder structure for install (#201) #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
justin808
wants to merge
5
commits into
master
Choose a base branch
from
justin808/fix-install-folder-path
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+374
−17
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
71d0ed7
Fix generator to create correct folder structure for install
justin808 ec3c140
Add comprehensive tests for install generator
justin808 748d843
Update README VCR cassette path to match generator template
justin808 44d4757
Add comprehensive migration guide and deprecation warnings
justin808 2fb5267
Enhance tests and add backward compatibility for old structure
justin808 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
require 'spec_helper' | ||
require 'rails/generators' | ||
require 'generators/cypress_on_rails/install_generator' | ||
require 'tmpdir' | ||
require 'fileutils' | ||
|
||
RSpec.describe CypressOnRails::InstallGenerator, type: :generator do | ||
let(:destination_root) { Dir.mktmpdir } | ||
|
||
before do | ||
# Set up a minimal Rails app structure | ||
FileUtils.mkdir_p(File.join(destination_root, 'config', 'initializers')) | ||
FileUtils.mkdir_p(File.join(destination_root, 'bin')) | ||
|
||
# Mock the generator's destination_root | ||
allow(Dir).to receive(:pwd).and_return(destination_root) | ||
|
||
# Prevent actual npm/yarn installation in tests | ||
allow_any_instance_of(CypressOnRails::InstallGenerator).to receive(:system).and_return(true) | ||
end | ||
|
||
after do | ||
FileUtils.rm_rf(destination_root) | ||
end | ||
|
||
describe 'with default options (cypress framework, e2e folder)' do | ||
let(:args) { [] } | ||
let(:options) { {} } | ||
|
||
before do | ||
run_generator(args, options) | ||
end | ||
|
||
it 'creates the initializer with correct install_folder path' do | ||
initializer_path = File.join(destination_root, 'config', 'initializers', 'cypress_on_rails.rb') | ||
expect(File).to exist(initializer_path) | ||
|
||
content = File.read(initializer_path) | ||
# Should point to e2e, not e2e/cypress | ||
expect(content).to include('c.install_folder = File.expand_path("#{__dir__}/../../e2e")') | ||
end | ||
|
||
it 'creates cypress config at install_folder root' do | ||
config_path = File.join(destination_root, 'e2e', 'cypress.config.js') | ||
expect(File).to exist(config_path) | ||
end | ||
|
||
it 'creates e2e_helper.rb at install_folder root' do | ||
helper_path = File.join(destination_root, 'e2e', 'e2e_helper.rb') | ||
expect(File).to exist(helper_path) | ||
end | ||
|
||
it 'creates app_commands directory at install_folder root' do | ||
commands_path = File.join(destination_root, 'e2e', 'app_commands') | ||
expect(File).to be_directory(commands_path) | ||
end | ||
|
||
it 'creates cypress support files in framework subdirectory' do | ||
support_path = File.join(destination_root, 'e2e', 'cypress', 'support', 'index.js') | ||
expect(File).to exist(support_path) | ||
end | ||
|
||
it 'creates cypress examples in framework subdirectory' do | ||
examples_path = File.join(destination_root, 'e2e', 'cypress', 'e2e', 'rails_examples') | ||
expect(File).to be_directory(examples_path) | ||
end | ||
end | ||
|
||
describe 'with playwright framework' do | ||
let(:args) { [] } | ||
let(:options) { { framework: 'playwright' } } | ||
|
||
before do | ||
run_generator(args, options) | ||
end | ||
|
||
it 'creates the initializer with correct install_folder path' do | ||
initializer_path = File.join(destination_root, 'config', 'initializers', 'cypress_on_rails.rb') | ||
expect(File).to exist(initializer_path) | ||
|
||
content = File.read(initializer_path) | ||
# Should point to e2e, not e2e/playwright | ||
expect(content).to include('c.install_folder = File.expand_path("#{__dir__}/../../e2e")') | ||
end | ||
|
||
it 'creates playwright config at install_folder root' do | ||
config_path = File.join(destination_root, 'e2e', 'playwright.config.js') | ||
expect(File).to exist(config_path) | ||
end | ||
|
||
it 'creates e2e_helper.rb at install_folder root' do | ||
helper_path = File.join(destination_root, 'e2e', 'e2e_helper.rb') | ||
expect(File).to exist(helper_path) | ||
end | ||
|
||
it 'creates app_commands directory at install_folder root' do | ||
commands_path = File.join(destination_root, 'e2e', 'app_commands') | ||
expect(File).to be_directory(commands_path) | ||
end | ||
|
||
it 'creates playwright support files in framework subdirectory' do | ||
support_path = File.join(destination_root, 'e2e', 'playwright', 'support', 'index.js') | ||
expect(File).to exist(support_path) | ||
end | ||
end | ||
|
||
describe 'with custom install_folder' do | ||
let(:args) { [] } | ||
let(:options) { { install_folder: 'spec/system' } } | ||
|
||
before do | ||
run_generator(args, options) | ||
end | ||
|
||
it 'creates files in the custom folder' do | ||
helper_path = File.join(destination_root, 'spec', 'system', 'e2e_helper.rb') | ||
expect(File).to exist(helper_path) | ||
|
||
commands_path = File.join(destination_root, 'spec', 'system', 'app_commands') | ||
expect(File).to be_directory(commands_path) | ||
end | ||
|
||
it 'sets the correct install_folder in the initializer' do | ||
initializer_path = File.join(destination_root, 'config', 'initializers', 'cypress_on_rails.rb') | ||
content = File.read(initializer_path) | ||
expect(content).to include('c.install_folder = File.expand_path("#{__dir__}/../../spec/system")') | ||
end | ||
end | ||
|
||
describe 'file structure ensures middleware and framework compatibility' do | ||
let(:args) { [] } | ||
let(:options) { {} } | ||
|
||
before do | ||
run_generator(args, options) | ||
end | ||
|
||
it 'places e2e_helper.rb where middleware expects it (install_folder/e2e_helper.rb)' do | ||
# Middleware looks for #{install_folder}/e2e_helper.rb | ||
helper_path = File.join(destination_root, 'e2e', 'e2e_helper.rb') | ||
expect(File).to exist(helper_path) | ||
expect(File.read(helper_path)).to include('CypressOnRails') | ||
end | ||
|
||
it 'places app_commands where middleware expects it (install_folder/app_commands)' do | ||
# Middleware looks for #{install_folder}/app_commands/#{command}.rb | ||
commands_path = File.join(destination_root, 'e2e', 'app_commands') | ||
expect(File).to be_directory(commands_path) | ||
|
||
# Check that command files exist | ||
clean_cmd = File.join(commands_path, 'clean.rb') | ||
expect(File).to exist(clean_cmd) | ||
end | ||
|
||
it 'places cypress.config.js where cypress --project flag expects it' do | ||
# Cypress runs with --project install_folder, expects config at that level | ||
config_path = File.join(destination_root, 'e2e', 'cypress.config.js') | ||
expect(File).to exist(config_path) | ||
|
||
# Verify the config references the correct relative path for support files | ||
content = File.read(config_path) | ||
expect(content).to include('cypress/support/index.js') | ||
end | ||
|
||
it 'creates a valid directory structure' do | ||
# The expected structure: | ||
# e2e/ | ||
# cypress.config.js <- Config at root of install_folder | ||
# e2e_helper.rb <- Helper at root of install_folder | ||
# app_commands/ <- Commands at root of install_folder | ||
# cypress/ <- Framework-specific subdirectory | ||
# support/ | ||
# e2e/ | ||
|
||
expect(File).to exist(File.join(destination_root, 'e2e', 'cypress.config.js')) | ||
expect(File).to exist(File.join(destination_root, 'e2e', 'e2e_helper.rb')) | ||
expect(File).to be_directory(File.join(destination_root, 'e2e', 'app_commands')) | ||
expect(File).to be_directory(File.join(destination_root, 'e2e', 'cypress')) | ||
expect(File).to be_directory(File.join(destination_root, 'e2e', 'cypress', 'support')) | ||
expect(File).to be_directory(File.join(destination_root, 'e2e', 'cypress', 'e2e')) | ||
end | ||
end | ||
|
||
def run_generator(args, options) | ||
generator_options = [] | ||
options.each do |key, value| | ||
generator_options << "--#{key}=#{value}" | ||
end | ||
|
||
CypressOnRails::InstallGenerator.start( | ||
args + generator_options, | ||
{ | ||
destination_root: destination_root, | ||
shell: Thor::Shell::Basic.new, | ||
behavior: :invoke | ||
} | ||
) | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
VCR cassettes now shared across frameworks.
The cassette_library_dir path change moves VCR cassettes from framework-specific directories (e.g.,
e2e/cypress/fixtures/vcr_cassettes
) to a shared location (e2e/fixtures/vcr_cassettes
). Since VCR cassettes record framework-agnostic HTTP interactions, this sharing is logical and reduces duplication.Verify that cassette sharing works correctly across frameworks:
🏁 Script executed:
Length of output: 154
🏁 Script executed:
Length of output: 7365
Update README.md example for cassette_library_dir
Replace the framework-specific path in README.md (line 452)
📝 Committable suggestion
🤖 Prompt for AI Agents