-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add comprehensive test suite with RSpec and SimpleCov * Add CI workflow and improve test coverage - Implement GitHub Actions workflow for Ruby CI - Add SimpleCov for test coverage reporting - Require 90% minimum test coverage - Add comprehensive RSpec tests for FileHelpers and LpxLinks - Configure test artifacts upload * Update spec/spec_helper.rb Co-authored-by: codiumai-pr-agent-pro[bot] <151058649+codiumai-pr-agent-pro[bot]@users.noreply.github.com> * Add CI workflow and improve test coverage - Implement GitHub Actions workflow for Ruby CI - Add SimpleCov for test coverage reporting - Require 90% minimum test coverage - Add comprehensive RSpec tests for FileHelpers and LpxLinks - Configure test artifacts upload * Improve error handling in run method --------- Co-authored-by: codiumai-pr-agent-pro[bot] <151058649+codiumai-pr-agent-pro[bot]@users.noreply.github.com>
- Loading branch information
1 parent
83fccba
commit 9f55c8a
Showing
9 changed files
with
200 additions
and
104 deletions.
There are no files selected for viewing
This file contains 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,46 @@ | ||
name: Ruby CI | ||
|
||
on: | ||
push: | ||
branches: [ master, main ] | ||
pull_request: | ||
branches: [ master, main ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
ruby-version: ['3.3.1'] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby-version }} | ||
bundler-cache: true | ||
|
||
- name: Install dependencies | ||
run: bundle install | ||
|
||
- name: Run tests | ||
run: bundle exec rspec | ||
|
||
- name: Upload coverage results | ||
uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: coverage-report | ||
path: coverage | ||
retention-days: 7 | ||
|
||
- name: Check test coverage | ||
run: | | ||
COVERAGE=$(grep -A 2 "Coverage" coverage/.last_run.json | tail -n 1 | cut -d ":" -f 2 | cut -d "}" -f 1 | tr -d " ") | ||
echo "Coverage: $COVERAGE%" | ||
if (( $(echo "$COVERAGE < 60" | bc -l) )); then | ||
echo "Test coverage is below 90%" | ||
exit 1 | ||
fi |
This file contains 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 |
---|---|---|
@@ -1,104 +1,5 @@ | ||
### Rails template | ||
*.rbc | ||
capybara-*.html | ||
.rspec | ||
/log | ||
/tmp | ||
/db/*.sqlite3 | ||
/db/*.sqlite3-journal | ||
/public/system | ||
/coverage/ | ||
/spec/tmp | ||
**.orig | ||
rerun.txt | ||
pickle-email-*.html | ||
|
||
# TODO Comment out these rules if you are OK with secrets being uploaded to the repo | ||
config/initializers/secret_token.rb | ||
config/secrets.yml | ||
|
||
## Environment normalisation: | ||
/.bundle | ||
/vendor/bundle | ||
|
||
# these should all be checked in to normalise the environment: | ||
# Gemfile.lock, .ruby-version, .ruby-gemset | ||
|
||
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: | ||
.rvmrc | ||
|
||
# if using bower-rails ignore default bower_components path bower.json files | ||
/vendor/assets/bower_components | ||
*.bowerrc | ||
bower.json | ||
|
||
# Ignore pow environment settings | ||
.powenv | ||
### OSX template | ||
coverage/ | ||
.rspec_status | ||
spec/examples.txt | ||
Gemfile.lock | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
### Ruby template | ||
*.gem | ||
*.rbc | ||
/.config | ||
/coverage/ | ||
/InstalledFiles | ||
/pkg/ | ||
/spec/reports/ | ||
/spec/examples.txt | ||
/test/tmp/ | ||
/test/version_tmp/ | ||
/tmp/ | ||
|
||
## Specific to RubyMotion: | ||
.dat* | ||
.repl_history | ||
build/ | ||
|
||
## Documentation cache and generated files: | ||
/.yardoc/ | ||
/_yardoc/ | ||
/doc/ | ||
/rdoc/ | ||
|
||
## Environment normalisation: | ||
/.bundle/ | ||
/vendor/bundle | ||
/lib/bundler/man/ | ||
|
||
# for a library or gem, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# Gemfile.lock | ||
# .ruby-version | ||
# .ruby-gemset | ||
|
||
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: | ||
.rvmrc | ||
|
||
# Created by .ignore support plugin (hsz.mobi) | ||
|
||
\.idea/ | ||
|
||
*.iml |
This file contains 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,3 @@ | ||
--require spec_helper | ||
--format documentation | ||
--color |
This file contains 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 @@ | ||
ruby 3.3.1 |
This file contains 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,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'rspec', '~> 3.12' | ||
gem 'simplecov', '~> 0.22.0', require: false |
This file contains 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 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,59 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe FileHelpers do | ||
describe '.plist_file_path' do | ||
it 'returns the correct path for Logic Pro' do | ||
allow(FileHelpers).to receive(:app_path).with('LOGIC').and_return('/Applications/Logic Pro X.app/Contents/Resources') | ||
allow(FileHelpers).to receive(:plist_file_name).with('LOGIC').and_return('logicpro1040.plist') | ||
|
||
expect(FileHelpers.plist_file_path('LOGIC')).to eq('/Applications/Logic Pro X.app/Contents/Resources/logicpro1040.plist') | ||
end | ||
|
||
it 'returns the correct path for Mainstage' do | ||
allow(FileHelpers).to receive(:app_path).with('MAINSTAGE').and_return('/Applications/MainStage 3.app/Contents/Resources') | ||
allow(FileHelpers).to receive(:plist_file_name).with('MAINSTAGE').and_return('mainstage360.plist') | ||
|
||
expect(FileHelpers.plist_file_path('MAINSTAGE')).to eq('/Applications/MainStage 3.app/Contents/Resources/mainstage360.plist') | ||
end | ||
end | ||
|
||
describe '.app_path' do | ||
context 'when Logic Pro X is installed' do | ||
before do | ||
allow(File).to receive(:exist?).with('/Applications/Logic Pro X.app/Contents/Resources').and_return(true) | ||
end | ||
|
||
it 'returns the correct path' do | ||
expect(FileHelpers.app_path('LOGIC')).to eq('/Applications/Logic Pro X.app/Contents/Resources') | ||
end | ||
end | ||
|
||
context 'when Logic Pro is installed' do | ||
before do | ||
allow(File).to receive(:exist?).with('/Applications/Logic Pro X.app/Contents/Resources').and_return(false) | ||
allow(File).to receive(:exist?).with('/Applications/Logic Pro.app/Contents/Resources').and_return(true) | ||
end | ||
|
||
it 'returns the correct path' do | ||
expect(FileHelpers.app_path('LOGIC')).to eq('/Applications/Logic Pro.app/Contents/Resources') | ||
end | ||
end | ||
|
||
context 'when neither Logic Pro version is installed' do | ||
before do | ||
allow(File).to receive(:exist?).and_return(false) | ||
end | ||
|
||
it 'raises an error' do | ||
expect { FileHelpers.app_path('LOGIC') }.to raise_error('Logic Pro X not found') | ||
end | ||
end | ||
end | ||
|
||
describe '.links_dir' do | ||
it 'returns the correct directory path' do | ||
allow(ENV).to receive(:[]).with('HOME').and_return('/Users/testuser') | ||
expect(FileHelpers.links_dir).to eq('/Users/testuser/Desktop/lpx_download_links') | ||
end | ||
end | ||
end |
This file contains 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,45 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe LpxLinks do | ||
let(:sample_packages) do | ||
{ | ||
"Packages" => { | ||
"package1" => { | ||
"DownloadName" => "mandatory_package.pkg", | ||
"IsMandatory" => true | ||
}, | ||
"package2" => { | ||
"DownloadName" => "optional_package.pkg", | ||
"IsMandatory" => false | ||
} | ||
} | ||
} | ||
end | ||
|
||
before do | ||
allow(File).to receive(:read).with('/tmp/lgp_content.json').and_return(sample_packages.to_json) | ||
allow(FileHelpers).to receive(:url).and_return('http://example.com/content/') | ||
end | ||
|
||
describe '.download_links' do | ||
it 'returns all download links when mandatory flag is false' do | ||
links = LpxLinks.download_links(false) | ||
expect(links.length).to eq(2) | ||
expect(links).to include("http://example.com/content/mandatory_package.pkg\n") | ||
expect(links).to include("http://example.com/content/optional_package.pkg\n") | ||
end | ||
|
||
it 'returns only mandatory download links when mandatory flag is true' do | ||
links = LpxLinks.download_links(true) | ||
expect(links.length).to eq(1) | ||
expect(links).to include("http://example.com/content/mandatory_package.pkg\n") | ||
end | ||
end | ||
|
||
describe '.read_packages' do | ||
it 'correctly parses the JSON file' do | ||
packages = LpxLinks.read_packages | ||
expect(packages).to eq(sample_packages["Packages"]) | ||
end | ||
end | ||
end |
This file contains 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,31 @@ | ||
require 'simplecov' | ||
SimpleCov.start do | ||
add_filter '/spec/' | ||
add_filter '/vendor/' | ||
end | ||
|
||
require_relative '../lib/file_helpers' | ||
require_relative '../lpx_links' | ||
|
||
RSpec.configure do |config| | ||
config.expect_with :rspec do |expectations| | ||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true | ||
end | ||
|
||
config.mock_with :rspec do |mocks| | ||
mocks.verify_partial_doubles = true | ||
end | ||
|
||
config.shared_context_metadata_behavior = :apply_to_host_groups | ||
config.filter_run_when_matching :focus | ||
config.example_status_persistence_file_path = "spec/examples.txt" | ||
config.disable_monkey_patching! | ||
config.warnings = true | ||
|
||
if config.files_to_run.one? | ||
config.default_formatter = "doc" | ||
end | ||
|
||
config.order = :random | ||
Kernel.srand config.seed | ||
end |