Skip to content
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

Refactor/tidy up post release #567

Merged
merged 16 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
This file is intended to be modified using the [`changelog`](github.com/cucumber/changelog) command-line tool.

## [Unreleased]
### Fixed
* Some of the rails 5.2 tests were installing lots of old conflicting gems ([luke-hill])

## [3.0.0.rc.1] - 2023-09-15
### Removed
Expand All @@ -19,11 +21,30 @@ This file is intended to be modified using the [`changelog`](github.com/cucumber
### Changed
- Automate release process [#554](https://github.com/cucumber/cucumber-rails/pull/554)

## [v2.6.0]
## [2.6.0] - 2022-10-07
### New Features
* Dependabot has now been added to the repo (Alongside this a bunch of gem updates have been done)
([#540](https://github.com/cucumber/cucumber-rails/pull/540) [mattwynne])

### Changed
- New release process. Older releases are in [this changelog](./CHANGELOG.old.md).
* Gem update: allowed cucumber 8 ([#538](https://github.com/cucumber/cucumber-rails/pull/538) / [#541](https://github.com/cucumber/cucumber-rails/pull/541) [mattwynne])

* New release process. Older releases are in [this changelog](./CHANGELOG.old.md)

### Fixed
* Some bugs with dev dependencies have now been fixed externally, so these have been unrestricted
([#552](https://github.com/cucumber/cucumber-rails/pull/552) [BrianHawley])

* Fixed up some rubocop offenses from updated `rubocop-performance`
([#550](https://github.com/cucumber/cucumber-rails/pull/550) [olleolleolle])

[Unreleased]: https://github.com/cucumber/cucumber-rails/compare/v3.0.0.rc.1...main
[3.0.0.rc.1]: https://github.com/cucumber/cucumber-rails/compare/v2.6.1...v3.0.0.rc.1
[2.6.1]: https://github.com/cucumber/cucumber-rails/compare/v2.6.0...v2.6.1
[v2.6.0]: ./CHANGELOG.old.md
[2.6.0]: https://github.com/cucumber/cucumber-rails/compare/v2.5.1...v2.6.0

[olleolleolle]: https://github.com/olleolleolle
[BrianHawley]: https://github.com/BrianHawley
[mattwynne]: https://github.com/mattwynne
[orien]: https://github.com/orien
[luke-hill]: https://github.com/luke-hill
25 changes: 0 additions & 25 deletions CHANGELOG.old.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md)
on how to contribute to Cucumber.

## [main](https://github.com/cucumber/cucumber-rails/compare/v2.5.1...main) (Not yet released)

### New Features

### Changed

### Fixed

## [v2.6.0](https://github.com/cucumber/cucumber-rails/compare/v2.5.1...v2.6.0) (2022-10-07)

### New Features
* Dependabot has now been added to the repo (Alongside this a bunch of gem updates have been done)
([#540](https://github.com/cucumber/cucumber-rails/pull/540) [mattwynne])

### Changed
* Gem update: allowed cucumber 8 ([#538](https://github.com/cucumber/cucumber-rails/pull/538) /
[#541](https://github.com/cucumber/cucumber-rails/pull/541) [mattwynne])

### Fixed
* Some bugs with dev dependencies have now been fixed externally, so these have been unrestricted
([#552](https://github.com/cucumber/cucumber-rails/pull/552) [BrianHawley])

* Fixed up some rubocop offenses from updated `rubocop-performance`
([#550](https://github.com/cucumber/cucumber-rails/pull/550) [olleolleolle])

## [v2.5.1](https://github.com/cucumber/cucumber-rails/compare/v2.5.0...v2.5.1) (2022-04-01)

### Fixed
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Cucumber feature. Let's say you think you have found a bug in the cucumber:insta
Fork this project, clone it to your workstation and check out a branch with a descriptive name:

git clone [email protected]:you/cucumber-rails.git
git checkout -b bugfix/generator-fails-on-ruby-25
git checkout -b bugfix/generator-fails-on-ruby-31

Start by making sure you can run the existing features. Now, create a feature that demonstrates
what's wrong. See the existing features for examples. When you have a failing feature that
Expand Down Expand Up @@ -118,10 +118,8 @@ To support the multiple-gemfile testing, when adding a new dependency the follow

1. If it's a runtime dependency of the gem, add it to the gemspec
2. If it's a primary development dependency, add it to the gemspec
3. If it's a dependency of a generated rails app in a test, add it to [the helper] that
modifies the `Gemfile`.
3. If it's a dependency of a generated rails app in a test, add it to [the helper] that modifies the `Gemfile`

For example, rspec is a primary development dependency, so it lives in the gemspec.

[the helper]: https://github.com/cucumber/cucumber-rails/blob/5e37c530560ae1c1a79521c38a54bae0be94242b/features/step_definitions/cucumber_rails_steps.rb#L15

3 changes: 1 addition & 2 deletions config/cucumber.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ opts = [
"--format #{path == 'features' ? 'progress' : 'pretty'}",
"--format rerun -o #{rerun_file}"
]
rails_version = `bundle exec rails --version`.match(/[\d.]+$/).to_s
optlist = opts.join(' ')
%>
default: <%= path %> <%= optlist %> --tags 'not @broken'
default: <%= path %> <%= optlist %>
1 change: 1 addition & 0 deletions cucumber-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('aruba', ['>= 1.0', '< 3'])
s.add_development_dependency('bundler', '>= 1.17')
s.add_development_dependency('database_cleaner', ['>= 1.8', '< 3.0'])
s.add_development_dependency('rails', ['>= 5.2', '< 8'])
s.add_development_dependency('rake', '>= 12.0')
s.add_development_dependency('rspec', '~> 3.6')
s.add_development_dependency('rubocop', '~> 1.28.2')
Expand Down
6 changes: 3 additions & 3 deletions features/capybara_javascript_drivers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Feature: Capybara Javascript Drivers
Then I should see "Cucumber Trainee"
And I should see "2026-02-20 15:10:00 UTC"
"""
And I write to "features/create_appointment_steps.rb" with:
And I write to "features/step_definitions/create_appointment_steps.rb" with:
"""
Given('I am on the new appointment page') do
visit new_appointment_path
Expand Down Expand Up @@ -63,7 +63,7 @@ Feature: Capybara Javascript Drivers
Then I should see "Cucumber Trainee"
And I should see "2026-02-20 15:10:00 UTC"
"""
And I write to "features/create_appointment_steps.rb" with:
And I write to "features/step_definitions/create_appointment_steps.rb" with:
"""
Given('I am on the new appointment page') do
visit new_appointment_path
Expand Down Expand Up @@ -148,7 +148,7 @@ Feature: Capybara Javascript Drivers
Then I should see "Cucumber Trainee"
And I should see "2026-02-20 15:10:00 UTC"
"""
And I write to "features/create_appointment_steps.rb" with:
And I write to "features/step_definitions/create_appointment_steps.rb" with:
"""
Given('I am on the new appointment page') do
visit new_appointment_path
Expand Down
2 changes: 1 addition & 1 deletion features/raising_errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feature: Raise Errors
Scenario: Tests
When I go to the home page
"""
And I write to "features/home_steps.rb" with:
And I write to "features/step_definitions/home_steps.rb" with:
"""
When('I go to the home page') do
visit('/')
Expand Down
115 changes: 57 additions & 58 deletions features/support/cucumber_rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

module CucumberRailsHelper
def rails_new(options = {})
validate_rails_new_success(run_rails_new_command(options))
# This expectation allows us to wait until the command line monitor has output a README file (i.e. the command has completed)
expect(run_rails_new_command(options)).to have_output(/README/)

cd options[:name]
configure_rails_gems
configure_rails_requires
Expand All @@ -15,44 +17,21 @@ def rails_new(options = {})
end

def install_cucumber_rails(*options)
add_conditional_gems(options)
add_rails_specific_gems

add_gem 'cucumber', Cucumber::VERSION, group: :test
add_gem 'capybara', Capybara::VERSION, group: :test
add_gem 'rspec-expectations', '~> 3.7', group: :test
add_gem 'database_cleaner', '>= 1.8.0', group: :test unless options.include?(:no_database_cleaner)
add_gem 'database_cleaner-active_record', '>= 2.0.0.beta2', group: :test if options.include?(:database_cleaner_active_record)
add_gem 'factory_bot', '>= 3.2', group: :test unless options.include?(:no_factory_bot)

add_cucumber_rails(options)
add_sqlite3
add_remaining_gems(options)
bundle_install
run_command_and_stop 'bundle exec rails generate cucumber:install'
end

private

def add_gem(name, *args)
line = convert_gem_opts_to_string(name, *args)
gem_regexp = /gem ["']#{name}["'].*$/
gemfile_content = File.read(expand_path('Gemfile'))

if gemfile_content.match?(gem_regexp)
updated_gemfile_content = gemfile_content.gsub(gem_regexp, line)
overwrite_file('Gemfile', updated_gemfile_content)
else
append_to_file('Gemfile', line)
end
end

def remove_gem(name)
content = File.read(expand_path('Gemfile')).gsub(/^\s*gem ["']#{name}["'].*$/, '')
overwrite_file('Gemfile', content)
end

def bundle_install
run_command_and_stop 'bundle config set --local without "development"'
run_command_and_stop "bundle config set --local path '#{ENV.fetch('GITHUB_WORKSPACE')}/vendor/bundle'" if ENV.key?('GITHUB_WORKSPACE')
run_command_and_stop 'bundle install --jobs 4'
def run_rails_new_command(options)
options[:name] ||= 'test_app'
flags = %w[--skip-action-cable --skip-action-mailer --skip-active-job --skip-bootsnap --skip-bundle --skip-javascript
--skip-jbuilder --skip-listen --skip-spring --skip-sprockets --skip-test-unit --skip-turbolinks --skip-active-storage]
flags += %w[--skip-action-mailbox --skip-action-text] if rails_equal_or_higher_than?('6.0')
run_command "bundle exec rails new #{options[:name]} #{flags.join(' ')} #{options[:args]}"
end

def configure_rails_gems
Expand All @@ -62,8 +41,8 @@ def configure_rails_gems

def configure_rails_requires
content = File.read(expand_path('config/application.rb'))
%w[ active_job/railtie active_storage/engine action_mailer/railtie action_mailbox/engine
action_text/engine action_cable/engine rails/test_unit/railtie sprockets/railtie ].each do |require|
%w[active_job/railtie active_storage/engine action_mailer/railtie action_mailbox/engine
action_text/engine action_cable/engine rails/test_unit/railtie sprockets/railtie].each do |require|
content = content.gsub(/^.*require ["']#{require}["']\s*$/, '')
end
overwrite_file('config/application.rb', content)
Expand All @@ -75,19 +54,6 @@ def configure_rails_layout
overwrite_file(file, content)
end

def run_rails_new_command(options)
options[:name] ||= 'test_app'
flags = %w[--skip-action-cable --skip-action-mailer --skip-active-job --skip-bootsnap --skip-bundle --skip-javascript
--skip-jbuilder --skip-listen --skip-spring --skip-sprockets --skip-test-unit --skip-turbolinks --skip-active-storage]
flags += %w[--skip-action-mailbox --skip-action-text] if rails_equal_or_higher_than?('6.0')
run_command "bundle exec rails new #{options[:name]} #{flags.join(' ')} #{options[:args]}"
end

def validate_rails_new_success(result)
expect(result).to have_output(/README/)
expect(last_command_started).to be_successfully_executed
end

def clear_bundle_env_vars
unset_bundler_env_vars
delete_environment_variable 'BUNDLE_GEMFILE'
Expand All @@ -97,30 +63,63 @@ def rails_equal_or_higher_than?(version)
Rails.gem_version >= Gem::Version.new(version)
end

def add_conditional_gems(options)
def remove_gem(name)
content = File.read(expand_path('Gemfile')).gsub(/^\s*gem ["']#{name}["'].*$/, '')
overwrite_file('Gemfile', content)
end

def add_gem(name, *args)
line = convert_gem_opts_to_string(name, *args)
gem_regexp = /gem ["']#{name}["'].*$/
gemfile_content = File.read(expand_path('Gemfile'))

if gemfile_content.match?(gem_regexp)
updated_gemfile_content = gemfile_content.gsub(gem_regexp, line)
overwrite_file('Gemfile', updated_gemfile_content)
else
append_to_file('Gemfile', line)
end
end

def convert_gem_opts_to_string(name, *args)
options = args.last.is_a?(Hash) ? args.pop : {}
parts = ["'#{name}'"]
parts << args.map(&:inspect) if args.any?
parts << options.inspect[1..-2] if options.any?
"gem #{parts.flatten.join(', ')}\n"
end

def add_cucumber_rails(options)
if options.include?(:not_in_test_group)
add_gem 'cucumber-rails', path: File.expand_path('.').to_s
else
add_gem 'cucumber-rails', group: :test, require: false, path: File.expand_path('.').to_s
end
end

def add_rails_specific_gems
def add_sqlite3
if rails_equal_or_higher_than?('6.0')
add_gem 'sqlite3', '~> 1.4'
add_gem 'selenium-webdriver', '~> 4.0', group: :test
else
add_gem 'sqlite3', '~> 1.3.13'
add_gem 'selenium-webdriver', '~> 3.11', group: :test
end
end

def convert_gem_opts_to_string(name, *args)
options = args.last.is_a?(Hash) ? args.pop : {}
parts = ["'#{name}'"]
parts << args.map(&:inspect) if args.any?
parts << options.inspect[1..-2] if options.any?
"gem #{parts.flatten.join(', ')}\n"
def add_remaining_gems(options)
add_gem 'cucumber', Cucumber::VERSION, group: :test
add_gem 'capybara', Capybara::VERSION, group: :test
add_gem 'database_cleaner', '>= 2.0.0', group: :test unless options.include?(:no_database_cleaner)
add_gem 'database_cleaner-active_record', '>= 2.0.0', group: :test if options.include?(:database_cleaner_active_record)
add_gem 'factory_bot', '>= 5.0', group: :test unless options.include?(:no_factory_bot)
add_gem 'rspec-expectations', '~> 3.12', group: :test
add_gem 'selenium-webdriver', '~> 4.0', group: :test
%w[chromedriver-helper].each { |gem| remove_gem(gem) } unless rails_equal_or_higher_than?('6.0')
end

def bundle_install
run_command_and_stop 'bundle config set --local without "development"'
run_command_and_stop "bundle config set --local path '#{ENV.fetch('GITHUB_WORKSPACE')}/vendor/bundle'" if ENV.key?('GITHUB_WORKSPACE')
run_command_and_stop 'bundle install --jobs 4'
end
end

Expand Down
Loading