From 698fef9aaacdf6d093e32e0dde3b1cc95a142c59 Mon Sep 17 00:00:00 2001 From: "Marcos G. Zimmermann" Date: Thu, 21 Nov 2024 14:39:54 -0300 Subject: [PATCH] chore: add linter and tests to the github actions --- .github/workflows/main.yml | 45 ++++++++++++++++++++++++++++++++++ .rubocop.yml | 1 + .tool-versions | 2 +- Gemfile | 3 --- Gemfile.lock | 22 +---------------- spec/site_maps/cli_spec.rb | 10 ++++---- spec/site_maps/railtie_spec.rb | 2 +- 7 files changed, 54 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..05d0fd1 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,45 @@ +name: Build + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + rubocop: + name: "Rubocop" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.0" + bundler-cache: true + - name: Run rubocop + run: | + bundle exec rubocop --parallel + tests: + name: Tests + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby-version: + - "3.0" + - "3.1" + - "3.2" + - "3.3" + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Ruby and install gems + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + - name: Install dependencies + run: bundle install --jobs 4 --retry 3 + - name: Run tests + run: bundle exec rspec + diff --git a/.rubocop.yml b/.rubocop.yml index b8c12ef..f51e2b9 100755 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -17,6 +17,7 @@ AllCops: - "db/**/*" - "tmp/**/*" - "vendor/**/*" + - "spec/support/hooks/notification.rb" # I'll refactor this rspec matcher to allow use things like an_instance_of NewCops: enable RSpec/MultipleExpectations: diff --git a/.tool-versions b/.tool-versions index 59511e1..1dd1998 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -ruby 2.7.8 +ruby 3.3.5 diff --git a/Gemfile b/Gemfile index 50622ad..7295599 100644 --- a/Gemfile +++ b/Gemfile @@ -2,9 +2,6 @@ source "https://rubygems.org" -gem "puma" -gem "sqlite3" -gem "activesupport", "~> 6.0" gem "nokogiri" gem "webmock" gem "aws-sdk-s3" diff --git a/Gemfile.lock b/Gemfile.lock index f46cb07..c66b991 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,12 +11,6 @@ PATH GEM remote: https://rubygems.org/ specs: - activesupport (6.1.7.10) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) - zeitwerk (~> 2.3) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) ast (2.4.2) @@ -46,17 +40,12 @@ GEM diff-lcs (1.5.1) dotenv (2.8.1) hashdiff (1.1.1) - i18n (1.14.6) - concurrent-ruby (~> 1.0) jmespath (1.6.2) json (2.8.1) language_server-protocol (3.17.0.3) lint_roller (1.1.0) method_source (1.1.0) - mini_portile2 (2.8.7) - minitest (5.25.1) - nio4r (2.7.4) - nokogiri (1.15.6-x86_64-linux) + nokogiri (1.16.7-x86_64-linux) racc (~> 1.4) parallel (1.26.3) parser (3.3.6.0) @@ -66,8 +55,6 @@ GEM coderay (~> 1.1) method_source (~> 1.0) public_suffix (5.1.1) - puma (6.4.3) - nio4r (~> 2.0) racc (1.8.1) rack (3.1.8) rainbow (3.1.1) @@ -105,8 +92,6 @@ GEM rubocop-rspec (3.2.0) rubocop (~> 1.61) ruby-progressbar (1.13.0) - sqlite3 (1.7.3) - mini_portile2 (~> 2.8.0) standard (1.37.0) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.0) @@ -121,8 +106,6 @@ GEM rubocop-performance (~> 1.21.0) thor (1.3.2) timecop (0.9.10) - tzinfo (2.0.6) - concurrent-ruby (~> 1.0) unicode-display_width (2.6.0) webmock (3.24.0) addressable (>= 2.8.0) @@ -134,18 +117,15 @@ PLATFORMS x86_64-linux DEPENDENCIES - activesupport (~> 6.0) aws-sdk-s3 dotenv nokogiri pry - puma rspec rubocop rubocop-performance rubocop-rspec site_maps! - sqlite3 standard timecop webmock diff --git a/spec/site_maps/cli_spec.rb b/spec/site_maps/cli_spec.rb index 781b700..481d3aa 100644 --- a/spec/site_maps/cli_spec.rb +++ b/spec/site_maps/cli_spec.rb @@ -19,7 +19,7 @@ subject(:generate!) { cli.generate } it "enqueues all processes" do - runner = double("runner", enqueue_all: nil, run: nil) + runner = instance_double(SiteMaps::Runner, enqueue_all: nil, run: nil) allow(SiteMaps).to receive(:generate).and_return(runner) generate! @@ -35,13 +35,13 @@ let(:processes) { "default,categories" } it "enqueues the given processes" do - runner = double("runner", enqueue: nil, run: nil) + runner = instance_double(SiteMaps::Runner, enqueue: nil, run: nil) allow(SiteMaps).to receive(:generate).and_return(runner) generate! - expect(runner).to have_received(:enqueue).with(:default, {}) - expect(runner).to have_received(:enqueue).with(:categories, {}) + expect(runner).to have_received(:enqueue).with(:default, **{}) + expect(runner).to have_received(:enqueue).with(:categories, **{}) expect(runner).to have_received(:run) end end @@ -64,7 +64,7 @@ end it "passes the options to the runner" do - runner = double("runner", enqueue: nil, run: nil) + runner = instance_double(SiteMaps::Runner, enqueue: nil, run: nil) allow(SiteMaps).to receive(:generate).and_return(runner) generate! diff --git a/spec/site_maps/railtie_spec.rb b/spec/site_maps/railtie_spec.rb index 4b99814..2e8ee6f 100644 --- a/spec/site_maps/railtie_spec.rb +++ b/spec/site_maps/railtie_spec.rb @@ -30,7 +30,7 @@ def application end end -RSpec.describe SiteMaps::Runner do +RSpec.describe "SiteMaps::Railtie" do before do stub_const("Rails", DummyRails) allow(Kernel).to receive(:require).with("rails/railtie").and_return(true)