Skip to content

Commit

Permalink
[Ruby] Dependency update (#322)
Browse files Browse the repository at this point in the history
* Update specs to be slightly more performant

* Fix up all outstanding rubocop offenses

* Interim rubocop update - all still passing

* Update ruby workflows

* Update CCK to latest version

* Permit latest (and upcoming major), release for messages

* Fix assetsloader to create less objects

* Tidy up specs

* WIP fix up shared context in tests

* Tidy up rubocop offenses and make tests flow better

* Add changelog

* Remove private method now assets loader tests are working
  • Loading branch information
luke-hill authored Aug 12, 2024
1 parent 8252f13 commit 0338ebf
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 146 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/release-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ jobs:

steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/prepare

- uses: actions/setup-java@v4
with:
distribution: "temurin"
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/release-javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@ jobs:

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 18
cache: "npm"
cache-dependency-path: javascript/package-lock.json

- run: npm install-ci-test
working-directory: javascript

- uses: cucumber/[email protected]
with:
npm-token: ${{ secrets.NPM_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: ./.github/actions/prepare
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
ruby-version: '3.3'
bundler-cache: true
working-directory: ruby
- name: Publish ruby gem
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/test-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@ jobs:

steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/prepare

- uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: ${{ matrix.java }}
cache: "maven"

- run: mvn install
working-directory: java

- run: mvn test
working-directory: java
6 changes: 0 additions & 6 deletions .github/workflows/test-javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,19 @@ jobs:
steps:
- name: set git core.autocrlf to 'input'
run: git config --global core.autocrlf input

- uses: actions/checkout@v4

- name: with Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache-dependency-path: javascript/package-lock.json

- run: npm install-ci-test
working-directory: javascript

- run: npm run build
working-directory: javascript

- run: npm run eslint
working-directory: javascript

- name: Acceptance tests
working-directory: javascript
run: npm run validate
4 changes: 2 additions & 2 deletions .github/workflows/test-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
matrix:
os:
- ubuntu-latest
ruby: ['2.7', '3.0', '3.1', '3.2']
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3']
include:
- os: macos-latest
ruby: '3.2'
ruby: '3.3'
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- [Ruby] Updated dependencies to support latest messages & reduced object creation ([#322](https://github.com/cucumber/html-formatter/pull/322))

## [21.6.0] - 2024-08-05
### Added
Expand Down
4 changes: 4 additions & 0 deletions ruby/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ AllCops:
Exclude:
- 'vendor/**/*'

# Stylistic preference for cucumber
Gemspec/DevelopmentDependencies:
Enabled: false

# Disabled on our repo's to enable polyglot-release
Gemspec/RequireMFA:
Enabled: false
Expand Down
12 changes: 6 additions & 6 deletions ruby/cucumber-html-formatter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Gem::Specification.new do |s|
'source_code_uri' => 'https://github.com/cucumber/html-formatter'
}

s.add_runtime_dependency 'cucumber-messages', '> 19', '< 25'
s.add_runtime_dependency 'cucumber-messages', '> 19', '< 27'

s.add_development_dependency 'cucumber-compatibility-kit', '~> 14.1'
s.add_development_dependency 'rake', '~> 13.1'
s.add_development_dependency 'rspec', '~> 3.12'
s.add_development_dependency 'rubocop', '~> 1.41.0'
s.add_development_dependency 'cucumber-compatibility-kit', '~> 15.2'
s.add_development_dependency 'rake', '~> 13.2'
s.add_development_dependency 'rspec', '~> 3.13'
s.add_development_dependency 'rubocop', '~> 1.61.0'
s.add_development_dependency 'rubocop-rake', '~> 0.6.0'
s.add_development_dependency 'rubocop-rspec', '~> 2.15.0'
s.add_development_dependency 'rubocop-rspec', '~> 2.25.0'

s.executables = ['cucumber-html-formatter']
s.files = Dir['README.md', 'LICENSE', 'lib/**/*', 'assets/*']
Expand Down
42 changes: 22 additions & 20 deletions ruby/lib/cucumber/html_formatter/assets_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,34 @@
module Cucumber
module HTMLFormatter
class AssetsLoader
def template
read_asset('index.mustache.html')
end
class << self
def template
read_asset('index.mustache.html')
end

def css
read_asset('main.css')
end
def css
read_asset('main.css')
end

def script
read_asset('main.js')
end
def script
read_asset('main.js')
end

private
private

def read_asset(name)
File.read(File.join(assets_path, name))
end
def read_asset(name)
File.read(File.join(assets_path, name))
end

def assets_path
"#{html_formatter_path}/assets"
end
def assets_path
"#{html_formatter_path}/assets"
end

def html_formatter_path
Gem.loaded_specs['cucumber-html-formatter'].full_gem_path
rescue StandardError
'.'
def html_formatter_path
Gem.loaded_specs['cucumber-html-formatter'].full_gem_path
rescue StandardError
'.'
end
end
end
end
Expand Down
10 changes: 3 additions & 7 deletions ruby/lib/cucumber/html_formatter/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,24 @@ def write_post_message

private

def assets_loader
@assets_loader ||= AssetsLoader.new
end

def pre_message
[
template_writer.write_between(nil, '{{css}}'),
assets_loader.css,
AssetsLoader.css,
template_writer.write_between('{{css}}', '{{messages}}')
].join("\n")
end

def post_message
[
template_writer.write_between('{{messages}}', '{{script}}'),
assets_loader.script,
AssetsLoader.script,
template_writer.write_between('{{script}}', nil)
].join("\n")
end

def template_writer
@template_writer ||= TemplateWriter.new(assets_loader.template)
@template_writer ||= TemplateWriter.new(AssetsLoader.template)
end
end
end
Expand Down
18 changes: 6 additions & 12 deletions ruby/spec/cucumber/html_formatter/assets_loader_spec.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
# frozen_string_literal: true

describe Cucumber::HTMLFormatter::AssetsLoader do
subject(:assets_loader) { described_class.new }

before do
allow(File).to receive(:read).and_return('whatever content')
end

describe '#template' do
it 'reads the content of assets/index.mustache.html' do
expect(File).to receive(:read).with(/.*\/assets\/index\.mustache\.html$/)
expect(File).to receive(:read).with(a_string_ending_with('assets/index.mustache.html'))

assets_loader.template
described_class.template
end
end

describe '#css' do
it 'reads the content of assets/main.css' do
expect(File).to receive(:read).with(/.*\/assets\/main\.css$/)
expect(File).to receive(:read).with(a_string_ending_with('assets/main.css'))

assets_loader.css
described_class.css
end
end

describe '#script' do
it 'reads the content of assets/main.js' do
expect(File).to receive(:read).with(/.*\/assets\/main\.js$/)
expect(File).to receive(:read).with(a_string_ending_with('assets/main.js'))

assets_loader.script
described_class.script
end
end
end
Loading

0 comments on commit 0338ebf

Please sign in to comment.