Skip to content

Commit

Permalink
Add tests and address #31 (#32)
Browse files Browse the repository at this point in the history
* 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
davidteren and qodo-merge-pro[bot] authored Oct 30, 2024
1 parent 83fccba commit 9f55c8a
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 104 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ruby-ci.yml
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
107 changes: 4 additions & 103 deletions .gitignore
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
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--require spec_helper
--format documentation
--color
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 3.3.1
4 changes: 4 additions & 0 deletions Gemfile
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
8 changes: 7 additions & 1 deletion lpx_links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ module LpxLinks
end
end.parse!

def run
def run
begin
create_dirs
convert_plist_to_json
print_file(FileHelpers.all_download_links, download_links)
print_file(FileHelpers.mandatory_download_links, download_links(true))
print_file(FileHelpers.json_file, JSON.pretty_generate(packages))
open_lpx_download_links
rescue RuntimeError => e
puts "Error: #{e.message}"
puts "Please ensure that #{$app_name} is installed correctly on your system."
exit 1
end
end

def open_lpx_download_links
`open #{FileHelpers.links_dir}`
Expand Down
59 changes: 59 additions & 0 deletions spec/lib/file_helpers_spec.rb
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
45 changes: 45 additions & 0 deletions spec/lpx_links_spec.rb
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
31 changes: 31 additions & 0 deletions spec/spec_helper.rb
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

0 comments on commit 9f55c8a

Please sign in to comment.