From 20ab5be4108b6c123e716670187b6de33b805e56 Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Fri, 12 Jan 2024 13:00:18 -0600 Subject: [PATCH 1/7] Add testing infrastructure This adds testing infrastructure to test against multiple versions of Rails, including Rails `main` branch. --- .github/workflows/ci.yml | 40 +++++ .gitignore | 3 + Appraisals | 14 ++ Gemfile | 6 +- Gemfile.lock | 213 +++++++++++++++------------ Rakefile | 10 ++ gemfiles/rails_7_0.gemfile | 21 +++ gemfiles/rails_7_0.gemfile.lock | 220 +++++++++++++++++++++++++++ gemfiles/rails_7_1.gemfile | 21 +++ gemfiles/rails_7_1.gemfile.lock | 253 ++++++++++++++++++++++++++++++++ gemfiles/rails_main.gemfile | 21 +++ test/test_helper.rb | 6 + 12 files changed, 728 insertions(+), 100 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 Appraisals create mode 100644 Rakefile create mode 100644 gemfiles/rails_7_0.gemfile create mode 100644 gemfiles/rails_7_0.gemfile.lock create mode 100644 gemfiles/rails_7_1.gemfile create mode 100644 gemfiles/rails_7_1.gemfile.lock create mode 100644 gemfiles/rails_main.gemfile create mode 100644 test/test_helper.rb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2c4a53c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: CI +on: [push, pull_request] +jobs: + tests: + strategy: + fail-fast: false + matrix: + ruby-version: + - "3.1" + - "3.2" + - "3.3" + gemfile: + - gemfiles/rails_7_0.gemfile + - gemfiles/rails_7_1.gemfile + - gemfiles/rails_main.gemfile + continue-on-error: [ false ] + + name: ${{ format('Tests (Ruby {0}, {1})', matrix.ruby-version, matrix.gemfile) }} + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.continue-on-error }} + + env: + BUNDLE_GEMFILE: ${{ matrix.gemfile }} + + steps: + - uses: actions/checkout@v4 + + - name: Remove Gemfile lock + run: | + rm -f $BUNDLE_GEMFILE.lock + + - name: Install Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + + - name: Run tests + run: | + bundle exec rake diff --git a/.gitignore b/.gitignore index 7e1052c..8977c70 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .byebug_history *.gem + +# Ignore Gemfile.lock files for Rails main branch. +/gemfiles/rails_main*.gemfile.lock diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..d6e6ee8 --- /dev/null +++ b/Appraisals @@ -0,0 +1,14 @@ +appraise "rails_7_0" do + gem "rails", "~> 7.0.0" + gem "propshaft" +end + +appraise "rails_7_1" do + gem "rails", "~> 7.1.0" + gem "propshaft" +end + +appraise "rails_main" do + gem "rails", github: "rails/rails", branch: "main" + gem "propshaft" +end diff --git a/Gemfile b/Gemfile index 1487b97..4f13599 100644 --- a/Gemfile +++ b/Gemfile @@ -4,9 +4,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } # Specify your gem's dependencies in importmap-rails.gemspec. gemspec -rails_version = ENV["RAILS_VERSION"] || "6.1.0" -gem "rails", "~> #{rails_version}" - +gem "appraisal" +gem "rails", "~> 6.0.0" +gem "sprockets-rails" gem "sqlite3" group :test do diff --git a/Gemfile.lock b/Gemfile.lock index f44fffc..2c38f5a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,67 +7,67 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (6.1.3.1) - actionpack (= 6.1.3.1) - activesupport (= 6.1.3.1) + actioncable (6.0.6.1) + actionpack (= 6.0.6.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.3.1) - actionpack (= 6.1.3.1) - activejob (= 6.1.3.1) - activerecord (= 6.1.3.1) - activestorage (= 6.1.3.1) - activesupport (= 6.1.3.1) + actionmailbox (6.0.6.1) + actionpack (= 6.0.6.1) + activejob (= 6.0.6.1) + activerecord (= 6.0.6.1) + activestorage (= 6.0.6.1) + activesupport (= 6.0.6.1) mail (>= 2.7.1) - actionmailer (6.1.3.1) - actionpack (= 6.1.3.1) - actionview (= 6.1.3.1) - activejob (= 6.1.3.1) - activesupport (= 6.1.3.1) + actionmailer (6.0.6.1) + actionpack (= 6.0.6.1) + actionview (= 6.0.6.1) + activejob (= 6.0.6.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.1.3.1) - actionview (= 6.1.3.1) - activesupport (= 6.1.3.1) - rack (~> 2.0, >= 2.0.9) + actionpack (6.0.6.1) + actionview (= 6.0.6.1) + activesupport (= 6.0.6.1) + rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.3.1) - actionpack (= 6.1.3.1) - activerecord (= 6.1.3.1) - activestorage (= 6.1.3.1) - activesupport (= 6.1.3.1) + actiontext (6.0.6.1) + actionpack (= 6.0.6.1) + activerecord (= 6.0.6.1) + activestorage (= 6.0.6.1) + activesupport (= 6.0.6.1) nokogiri (>= 1.8.5) - actionview (6.1.3.1) - activesupport (= 6.1.3.1) + actionview (6.0.6.1) + activesupport (= 6.0.6.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.3.1) - activesupport (= 6.1.3.1) + activejob (6.0.6.1) + activesupport (= 6.0.6.1) globalid (>= 0.3.6) - activemodel (6.1.3.1) - activesupport (= 6.1.3.1) - activerecord (6.1.3.1) - activemodel (= 6.1.3.1) - activesupport (= 6.1.3.1) - activestorage (6.1.3.1) - actionpack (= 6.1.3.1) - activejob (= 6.1.3.1) - activerecord (= 6.1.3.1) - activesupport (= 6.1.3.1) - marcel (~> 1.0.0) - mini_mime (~> 1.0.2) - activesupport (6.1.3.1) + activemodel (6.0.6.1) + activesupport (= 6.0.6.1) + activerecord (6.0.6.1) + activemodel (= 6.0.6.1) + activesupport (= 6.0.6.1) + activestorage (6.0.6.1) + actionpack (= 6.0.6.1) + activejob (= 6.0.6.1) + activerecord (= 6.0.6.1) + marcel (~> 1.0) + activesupport (6.0.6.1) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) - zeitwerk (~> 2.3) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + zeitwerk (~> 2.2, >= 2.2.2) addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) builder (3.2.4) byebug (11.1.3) capybara (3.35.3) @@ -79,94 +79,111 @@ GEM regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) childprocess (3.0.0) - concurrent-ruby (1.1.9) + concurrent-ruby (1.2.2) crass (1.0.6) - erubi (1.10.0) - globalid (0.5.1) + date (3.3.4) + erubi (1.12.0) + globalid (1.1.0) activesupport (>= 5.0) - i18n (1.8.10) + i18n (1.14.1) concurrent-ruby (~> 1.0) - loofah (2.10.0) + loofah (2.22.0) crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) + nokogiri (>= 1.12.0) + mail (2.8.1) mini_mime (>= 0.1.1) - marcel (1.0.1) + net-imap + net-pop + net-smtp + marcel (1.0.2) method_source (1.0.0) - mini_mime (1.0.3) - minitest (5.14.4) - nio4r (2.5.7) - nokogiri (1.15.2-aarch64-linux) + mini_mime (1.1.5) + minitest (5.21.1) + net-imap (0.4.9.1) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.4.0.1) + net-protocol + nio4r (2.7.0) + nokogiri (1.16.0-aarch64-linux) racc (~> 1.4) - nokogiri (1.15.2-arm64-darwin) + nokogiri (1.16.0-arm64-darwin) racc (~> 1.4) - nokogiri (1.15.2-x86_64-darwin) + nokogiri (1.16.0-x86_64-darwin) racc (~> 1.4) - nokogiri (1.15.2-x86_64-linux) + nokogiri (1.16.0-x86_64-linux) racc (~> 1.4) public_suffix (4.0.6) - racc (1.7.1) - rack (2.2.3) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (6.1.3.1) - actioncable (= 6.1.3.1) - actionmailbox (= 6.1.3.1) - actionmailer (= 6.1.3.1) - actionpack (= 6.1.3.1) - actiontext (= 6.1.3.1) - actionview (= 6.1.3.1) - activejob (= 6.1.3.1) - activemodel (= 6.1.3.1) - activerecord (= 6.1.3.1) - activestorage (= 6.1.3.1) - activesupport (= 6.1.3.1) - bundler (>= 1.15.0) - railties (= 6.1.3.1) + racc (1.7.3) + rack (2.2.8) + rack-test (2.1.0) + rack (>= 1.3) + rails (6.0.6.1) + actioncable (= 6.0.6.1) + actionmailbox (= 6.0.6.1) + actionmailer (= 6.0.6.1) + actionpack (= 6.0.6.1) + actiontext (= 6.0.6.1) + actionview (= 6.0.6.1) + activejob (= 6.0.6.1) + activemodel (= 6.0.6.1) + activerecord (= 6.0.6.1) + activestorage (= 6.0.6.1) + activesupport (= 6.0.6.1) + bundler (>= 1.3.0) + railties (= 6.0.6.1) sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.3.0) - loofah (~> 2.3) - railties (6.1.3.1) - actionpack (= 6.1.3.1) - activesupport (= 6.1.3.1) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (6.0.6.1) + actionpack (= 6.0.6.1) + activesupport (= 6.0.6.1) method_source rake (>= 0.8.7) - thor (~> 1.0) - rake (13.0.6) + thor (>= 0.20.3, < 2.0) + rake (13.1.0) regexp_parser (2.1.1) rexml (3.2.5) rubyzip (2.3.2) selenium-webdriver (3.142.7) childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) - sprockets (4.0.2) + sprockets (4.2.1) concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.2) - actionpack (>= 4.0) - activesupport (>= 4.0) + rack (>= 2.2.4, < 4) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) sqlite3 (1.4.2) stimulus-rails (0.3.8) rails (>= 6.0.0) - thor (1.1.0) + thor (1.3.0) + thread_safe (0.3.6) + timeout (0.4.1) turbo-rails (0.7.4) rails (>= 6.0.0) - tzinfo (2.0.4) - concurrent-ruby (~> 1.0) + tzinfo (1.2.11) + thread_safe (~> 0.1) webdrivers (4.6.0) nokogiri (~> 1.6) rubyzip (>= 1.3.0) selenium-webdriver (>= 3.0, < 4.0) - websocket-driver (0.7.5) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.4.2) + zeitwerk (2.6.12) PLATFORMS aarch64-linux @@ -178,12 +195,14 @@ PLATFORMS x86_64-linux DEPENDENCIES + appraisal byebug capybara cssbundling-rails! - rails (~> 6.1.0) + rails (~> 6.0.0) rexml selenium-webdriver + sprockets-rails sqlite3 stimulus-rails turbo-rails diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..793ce06 --- /dev/null +++ b/Rakefile @@ -0,0 +1,10 @@ +require "bundler/setup" +require "bundler/gem_tasks" +require "rake/testtask" + +Rake::TestTask.new(:test) do |t| + t.libs << "test" + t.pattern = "test/**/*_test.rb" +end + +task default: :test diff --git a/gemfiles/rails_7_0.gemfile b/gemfiles/rails_7_0.gemfile new file mode 100644 index 0000000..7c6a756 --- /dev/null +++ b/gemfiles/rails_7_0.gemfile @@ -0,0 +1,21 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "rails", "~> 7.0.0" +gem "sprockets-rails" +gem "sqlite3" +gem "propshaft" + +group :test do + gem "turbo-rails" + gem "stimulus-rails" + gem "byebug" + gem "rexml" + gem "capybara" + gem "selenium-webdriver" + gem "webdrivers" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7_0.gemfile.lock b/gemfiles/rails_7_0.gemfile.lock new file mode 100644 index 0000000..9a6e284 --- /dev/null +++ b/gemfiles/rails_7_0.gemfile.lock @@ -0,0 +1,220 @@ +PATH + remote: .. + specs: + cssbundling-rails (1.3.3) + railties (>= 6.0.0) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (7.0.8) + actionpack (= 7.0.8) + activesupport (= 7.0.8) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (7.0.8) + actionpack (= 7.0.8) + activejob (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.0.8) + actionpack (= 7.0.8) + actionview (= 7.0.8) + activejob (= 7.0.8) + activesupport (= 7.0.8) + mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.0) + actionpack (7.0.8) + actionview (= 7.0.8) + activesupport (= 7.0.8) + rack (~> 2.0, >= 2.2.4) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (7.0.8) + actionpack (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.0.8) + activesupport (= 7.0.8) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (7.0.8) + activesupport (= 7.0.8) + globalid (>= 0.3.6) + activemodel (7.0.8) + activesupport (= 7.0.8) + activerecord (7.0.8) + activemodel (= 7.0.8) + activesupport (= 7.0.8) + activestorage (7.0.8) + actionpack (= 7.0.8) + activejob (= 7.0.8) + activerecord (= 7.0.8) + activesupport (= 7.0.8) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (7.0.8) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + addressable (2.8.6) + public_suffix (>= 2.0.2, < 6.0) + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + builder (3.2.4) + byebug (11.1.3) + capybara (3.39.2) + addressable + matrix + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (>= 1.5, < 3.0) + xpath (~> 3.2) + concurrent-ruby (1.2.2) + crass (1.0.6) + date (3.3.4) + erubi (1.12.0) + globalid (1.2.1) + activesupport (>= 6.1) + i18n (1.14.1) + concurrent-ruby (~> 1.0) + loofah (2.22.0) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.2) + matrix (0.4.2) + method_source (1.0.0) + mini_mime (1.1.5) + minitest (5.21.1) + net-imap (0.4.9.1) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.4.0.1) + net-protocol + nio4r (2.7.0) + nokogiri (1.16.0-x86_64-linux) + racc (~> 1.4) + propshaft (0.8.0) + actionpack (>= 7.0.0) + activesupport (>= 7.0.0) + rack + railties (>= 7.0.0) + public_suffix (5.0.4) + racc (1.7.3) + rack (2.2.8) + rack-test (2.1.0) + rack (>= 1.3) + rails (7.0.8) + actioncable (= 7.0.8) + actionmailbox (= 7.0.8) + actionmailer (= 7.0.8) + actionpack (= 7.0.8) + actiontext (= 7.0.8) + actionview (= 7.0.8) + activejob (= 7.0.8) + activemodel (= 7.0.8) + activerecord (= 7.0.8) + activestorage (= 7.0.8) + activesupport (= 7.0.8) + bundler (>= 1.15.0) + railties (= 7.0.8) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.0.8) + actionpack (= 7.0.8) + activesupport (= 7.0.8) + method_source + rake (>= 12.2) + thor (~> 1.0) + zeitwerk (~> 2.5) + rake (13.1.0) + regexp_parser (2.9.0) + rexml (3.2.6) + rubyzip (2.3.2) + selenium-webdriver (4.10.0) + rexml (~> 3.2, >= 3.2.5) + rubyzip (>= 1.2.2, < 3.0) + websocket (~> 1.0) + sprockets (4.2.1) + concurrent-ruby (~> 1.0) + rack (>= 2.2.4, < 4) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + sprockets (>= 3.0.0) + sqlite3 (1.7.0-x86_64-linux) + stimulus-rails (1.3.3) + railties (>= 6.0.0) + thor (1.3.0) + timeout (0.4.1) + turbo-rails (1.5.0) + actionpack (>= 6.0.0) + activejob (>= 6.0.0) + railties (>= 6.0.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + webdrivers (5.3.1) + nokogiri (~> 1.6) + rubyzip (>= 1.3.0) + selenium-webdriver (~> 4.0, < 4.11) + websocket (1.2.10) + websocket-driver (0.7.6) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + xpath (3.2.0) + nokogiri (~> 1.8) + zeitwerk (2.6.12) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + appraisal + byebug + capybara + cssbundling-rails! + propshaft + rails (~> 7.0.0) + rexml + selenium-webdriver + sprockets-rails + sqlite3 + stimulus-rails + turbo-rails + webdrivers + +BUNDLED WITH + 2.2.33 diff --git a/gemfiles/rails_7_1.gemfile b/gemfiles/rails_7_1.gemfile new file mode 100644 index 0000000..44414bb --- /dev/null +++ b/gemfiles/rails_7_1.gemfile @@ -0,0 +1,21 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "rails", "~> 7.1.0" +gem "sprockets-rails" +gem "sqlite3" +gem "propshaft" + +group :test do + gem "turbo-rails" + gem "stimulus-rails" + gem "byebug" + gem "rexml" + gem "capybara" + gem "selenium-webdriver" + gem "webdrivers" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7_1.gemfile.lock b/gemfiles/rails_7_1.gemfile.lock new file mode 100644 index 0000000..17978e8 --- /dev/null +++ b/gemfiles/rails_7_1.gemfile.lock @@ -0,0 +1,253 @@ +PATH + remote: .. + specs: + cssbundling-rails (1.3.3) + railties (>= 6.0.0) + +GEM + remote: https://rubygems.org/ + specs: + actioncable (7.1.2) + actionpack (= 7.1.2) + activesupport (= 7.1.2) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (7.1.2) + actionpack (= 7.1.2) + activejob (= 7.1.2) + activerecord (= 7.1.2) + activestorage (= 7.1.2) + activesupport (= 7.1.2) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.1.2) + actionpack (= 7.1.2) + actionview (= 7.1.2) + activejob (= 7.1.2) + activesupport (= 7.1.2) + mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.2) + actionpack (7.1.2) + actionview (= 7.1.2) + activesupport (= 7.1.2) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.2) + actionpack (= 7.1.2) + activerecord (= 7.1.2) + activestorage (= 7.1.2) + activesupport (= 7.1.2) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.1.2) + activesupport (= 7.1.2) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.2) + activesupport (= 7.1.2) + globalid (>= 0.3.6) + activemodel (7.1.2) + activesupport (= 7.1.2) + activerecord (7.1.2) + activemodel (= 7.1.2) + activesupport (= 7.1.2) + timeout (>= 0.4.0) + activestorage (7.1.2) + actionpack (= 7.1.2) + activejob (= 7.1.2) + activerecord (= 7.1.2) + activesupport (= 7.1.2) + marcel (~> 1.0) + activesupport (7.1.2) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) + addressable (2.8.6) + public_suffix (>= 2.0.2, < 6.0) + appraisal (2.5.0) + bundler + rake + thor (>= 0.14.0) + base64 (0.2.0) + bigdecimal (3.1.5) + builder (3.2.4) + byebug (11.1.3) + capybara (3.39.2) + addressable + matrix + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (>= 1.5, < 3.0) + xpath (~> 3.2) + concurrent-ruby (1.2.2) + connection_pool (2.4.1) + crass (1.0.6) + date (3.3.4) + drb (2.2.0) + ruby2_keywords + erubi (1.12.0) + globalid (1.2.1) + activesupport (>= 6.1) + i18n (1.14.1) + concurrent-ruby (~> 1.0) + io-console (0.7.1) + irb (1.11.1) + rdoc + reline (>= 0.4.2) + loofah (2.22.0) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.2) + matrix (0.4.2) + mini_mime (1.1.5) + minitest (5.21.1) + mutex_m (0.2.0) + net-imap (0.4.9.1) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.4.0.1) + net-protocol + nio4r (2.7.0) + nokogiri (1.16.0-x86_64-linux) + racc (~> 1.4) + propshaft (0.8.0) + actionpack (>= 7.0.0) + activesupport (>= 7.0.0) + rack + railties (>= 7.0.0) + psych (5.1.2) + stringio + public_suffix (5.0.4) + racc (1.7.3) + rack (3.0.8) + rack-session (2.0.0) + rack (>= 3.0.0) + rack-test (2.1.0) + rack (>= 1.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.2) + actioncable (= 7.1.2) + actionmailbox (= 7.1.2) + actionmailer (= 7.1.2) + actionpack (= 7.1.2) + actiontext (= 7.1.2) + actionview (= 7.1.2) + activejob (= 7.1.2) + activemodel (= 7.1.2) + activerecord (= 7.1.2) + activestorage (= 7.1.2) + activesupport (= 7.1.2) + bundler (>= 1.15.0) + railties (= 7.1.2) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.1.2) + actionpack (= 7.1.2) + activesupport (= 7.1.2) + irb + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rake (13.1.0) + rdoc (6.6.2) + psych (>= 4.0.0) + regexp_parser (2.9.0) + reline (0.4.2) + io-console (~> 0.5) + rexml (3.2.6) + ruby2_keywords (0.0.5) + rubyzip (2.3.2) + selenium-webdriver (4.10.0) + rexml (~> 3.2, >= 3.2.5) + rubyzip (>= 1.2.2, < 3.0) + websocket (~> 1.0) + sprockets (4.2.1) + concurrent-ruby (~> 1.0) + rack (>= 2.2.4, < 4) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + sprockets (>= 3.0.0) + sqlite3 (1.7.0-x86_64-linux) + stimulus-rails (1.3.3) + railties (>= 6.0.0) + stringio (3.1.0) + thor (1.3.0) + timeout (0.4.1) + turbo-rails (1.5.0) + actionpack (>= 6.0.0) + activejob (>= 6.0.0) + railties (>= 6.0.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + webdrivers (5.3.1) + nokogiri (~> 1.6) + rubyzip (>= 1.3.0) + selenium-webdriver (~> 4.0, < 4.11) + webrick (1.8.1) + websocket (1.2.10) + websocket-driver (0.7.6) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + xpath (3.2.0) + nokogiri (~> 1.8) + zeitwerk (2.6.12) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + appraisal + byebug + capybara + cssbundling-rails! + propshaft + rails (~> 7.1.0) + rexml + selenium-webdriver + sprockets-rails + sqlite3 + stimulus-rails + turbo-rails + webdrivers + +BUNDLED WITH + 2.2.33 diff --git a/gemfiles/rails_main.gemfile b/gemfiles/rails_main.gemfile new file mode 100644 index 0000000..faf99e7 --- /dev/null +++ b/gemfiles/rails_main.gemfile @@ -0,0 +1,21 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal" +gem "rails", branch: "main", git: "https://github.com/rails/rails.git" +gem "sprockets-rails" +gem "sqlite3" +gem "propshaft" + +group :test do + gem "turbo-rails" + gem "stimulus-rails" + gem "byebug" + gem "rexml" + gem "capybara" + gem "selenium-webdriver" + gem "webdrivers" +end + +gemspec path: "../" diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..b65a5ab --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,6 @@ +# Configure Rails Environment +ENV["RAILS_ENV"] = "test" + +require "fileutils" +require "rails" +require "rails/test_help" From 048b1f1d890a29a6a731892aaeb8d194481c5e7b Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Fri, 12 Jan 2024 18:17:34 -0600 Subject: [PATCH 2/7] Test shared behavior of installer commands This adds test coverage for the shared behavior of the installer commands. The commands are tested against a freshly generated Rails app using the version of Rails that is currently loaded. Thus the installers can be tested with different versions of Rails in CI. --- .gitignore | 1 + test/bootstrap_installer_test.rb | 13 ++++ test/bulma_installer_test.rb | 13 ++++ test/postcss_installer_test.rb | 13 ++++ test/sass_installer_test.rb | 13 ++++ test/shared_installer_tests.rb | 123 +++++++++++++++++++++++++++++++ test/tailwind_installer_test.rb | 13 ++++ test/test_helper.rb | 65 ++++++++++++++++ 8 files changed, 254 insertions(+) create mode 100644 test/bootstrap_installer_test.rb create mode 100644 test/bulma_installer_test.rb create mode 100644 test/postcss_installer_test.rb create mode 100644 test/sass_installer_test.rb create mode 100644 test/shared_installer_tests.rb create mode 100644 test/tailwind_installer_test.rb diff --git a/.gitignore b/.gitignore index 8977c70..34600ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/tmp/ .byebug_history *.gem diff --git a/test/bootstrap_installer_test.rb b/test/bootstrap_installer_test.rb new file mode 100644 index 0000000..36926d1 --- /dev/null +++ b/test/bootstrap_installer_test.rb @@ -0,0 +1,13 @@ +require "test_helper" +require_relative "shared_installer_tests" + +class BootstrapInstallerTest < ActiveSupport::TestCase + include RailsAppHelpers + include SharedInstallerTests + + private + def run_installer + stub_bins("gem", "yarn", "npm") + run_command("bin/rails", "css:install:bootstrap") + end +end diff --git a/test/bulma_installer_test.rb b/test/bulma_installer_test.rb new file mode 100644 index 0000000..2aeee53 --- /dev/null +++ b/test/bulma_installer_test.rb @@ -0,0 +1,13 @@ +require "test_helper" +require_relative "shared_installer_tests" + +class BulmaInstallerTest < ActiveSupport::TestCase + include RailsAppHelpers + include SharedInstallerTests + + private + def run_installer + stub_bins("gem", "yarn", "npm") + run_command("bin/rails", "css:install:bulma") + end +end diff --git a/test/postcss_installer_test.rb b/test/postcss_installer_test.rb new file mode 100644 index 0000000..7468e48 --- /dev/null +++ b/test/postcss_installer_test.rb @@ -0,0 +1,13 @@ +require "test_helper" +require_relative "shared_installer_tests" + +class PostcssInstallerTest < ActiveSupport::TestCase + include RailsAppHelpers + include SharedInstallerTests + + private + def run_installer + stub_bins("gem", "yarn", "npm") + run_command("bin/rails", "css:install:postcss") + end +end diff --git a/test/sass_installer_test.rb b/test/sass_installer_test.rb new file mode 100644 index 0000000..e86fa7e --- /dev/null +++ b/test/sass_installer_test.rb @@ -0,0 +1,13 @@ +require "test_helper" +require_relative "shared_installer_tests" + +class SassInstallerTest < ActiveSupport::TestCase + include RailsAppHelpers + include SharedInstallerTests + + private + def run_installer + stub_bins("gem", "yarn", "npm") + run_command("bin/rails", "css:install:sass") + end +end diff --git a/test/shared_installer_tests.rb b/test/shared_installer_tests.rb new file mode 100644 index 0000000..0983791 --- /dev/null +++ b/test/shared_installer_tests.rb @@ -0,0 +1,123 @@ +require "json" + +module SharedInstallerTests + extend ActiveSupport::Concern + + included do + test "basic installation with pre-existing files" do + with_new_rails_app do + File.write(".gitignore", "# pre-existing\n", mode: "a+") + File.write("package.json", %({ "name": "pre-existing" }\n)) + File.write("Procfile.dev", "pre: existing\n", mode: "a+") + + run_installer + + assert_equal 0, File.size("app/assets/builds/.keep") + + File.read(".gitignore").tap do |gitignore| + assert_match "# pre-existing", gitignore + assert_match "/app/assets/builds/*\n!/app/assets/builds/.keep", gitignore + assert_match "/node_modules", gitignore + end + + JSON.load_file("package.json").tap do |package_json| + assert_equal "pre-existing", package_json["name"] + end + + assert_not File.exist?("app/assets/stylesheets/application.css") + + File.read("Procfile.dev").tap do |procfile| + assert_match "pre: existing", procfile + assert_match "css: yarn", procfile + end + + File.read("bin/dev").tap do |bin_dev| + assert_equal File.read("#{__dir__}/../lib/install/dev"), bin_dev + assert_equal 0700, File.stat("bin/dev").mode & 0700 + end + end + end + + test "basic installation without pre-existing files" do + with_new_rails_app do + FileUtils.rm("app/views/layouts/application.html.erb") + FileUtils.rm(".gitignore") + FileUtils.rm_rf("package.json") + FileUtils.rm_rf("Procfile.dev") + + out, _err = run_installer + + assert_not File.exist?("app/views/layouts/application.html.erb") + assert_match "Add <%= stylesheet_link_tag", out + + assert_not File.exist?(".gitignore") + + assert_instance_of Hash, JSON.load_file("package.json") + + File.read("Procfile.dev").tap do |procfile| + assert_match "css: yarn", procfile + end + + assert_match "STUBBED gem install foreman", out + end + end + + test "basic installation with Sprockets" do + with_new_rails_app(*("--asset-pipeline=sprockets" if Rails::VERSION::MAJOR >= 7)) do + File.write("app/assets/config/manifest.js", "// pre-existing\n", mode: "a+") + + run_installer + + File.read("app/assets/config/manifest.js").tap do |sprockets_manifest| + assert_match "// pre-existing", sprockets_manifest + assert_match "//= link_tree ../builds", sprockets_manifest + assert_no_match "//= link_directory ../stylesheets .css", sprockets_manifest + end + end + end + + if Rails::VERSION::MAJOR == 7 + test "basic installation with Propshaft" do + with_new_rails_app("--asset-pipeline=propshaft") do + run_installer + + assert_not File.exist?("app/assets/config/manifest.js") + end + end + end + + if Rails::VERSION::MAJOR >= 7 + test "basic installation with Turbo" do + with_new_rails_app do + run_installer + + File.read("app/views/layouts/application.html.erb").tap do |layout| + assert_match %(<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>), layout[%r{}m] + end + end + end + end + + test "basic installation without Turbo" do + with_new_rails_app(*("--skip-hotwire" if Rails::VERSION::MAJOR >= 7)) do + run_installer + + File.read("app/views/layouts/application.html.erb").tap do |layout| + assert_match %(<%= stylesheet_link_tag "application" %>), layout[%r{}m] + end + end + end + + test "basic installation with Bun" do + with_new_rails_app do + stub_bins("bun") + + run_installer + + File.read("Procfile.dev").tap do |procfile| + assert_match "css: bun run", procfile + end + end + end + end +end diff --git a/test/tailwind_installer_test.rb b/test/tailwind_installer_test.rb new file mode 100644 index 0000000..76a5ea9 --- /dev/null +++ b/test/tailwind_installer_test.rb @@ -0,0 +1,13 @@ +require "test_helper" +require_relative "shared_installer_tests" + +class TailwindInstallerTest < ActiveSupport::TestCase + include RailsAppHelpers + include SharedInstallerTests + + private + def run_installer + stub_bins("gem", "yarn", "npm") + run_command("bin/rails", "css:install:tailwind") + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index b65a5ab..6135ace 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,3 +4,68 @@ require "fileutils" require "rails" require "rails/test_help" + +module RailsAppHelpers + def self.included(base) + base.include ActiveSupport::Testing::Isolation + end + + private + def create_new_rails_app(app_dir, *cli_options) + require "rails/generators/rails/app/app_generator" + Rails::Generators::AppGenerator.start([app_dir, "--skip-bundle", "--skip-bootsnap", "--quiet", cli_options].flatten) + + Dir.chdir(app_dir) do + gemfile = File.read("Gemfile") + + gemfile.gsub!(/^gem ["']cssbundling-rails["'].*/, "") + gemfile << %(gem "cssbundling-rails", path: #{File.expand_path("..", __dir__).inspect}\n) + + if Rails::VERSION::PRE == "alpha" + gemfile.gsub!(/^gem ["']rails["'].*/, "") + gemfile << %(gem "rails", path: #{Gem.loaded_specs["rails"].full_gem_path.inspect}\n) + end + + File.write("Gemfile", gemfile) + + run_command("bundle", "install") + end + end + + def with_new_rails_app(*cli_options, &block) + require "digest/sha1" + variant = [RUBY_VERSION, Gem.loaded_specs["rails"].full_gem_path, cli_options.flatten.sort] + app_name = "app_#{Digest::SHA1.hexdigest(variant.to_s)}" + cache_dir = "#{__dir__}/../tmp" + FileUtils.mkdir_p(cache_dir) + + Dir.mktmpdir do |tmpdir| + if Dir.exist?("#{cache_dir}/#{app_name}") + FileUtils.cp_r("#{cache_dir}/#{app_name}", tmpdir) + else + create_new_rails_app("#{tmpdir}/#{app_name}", *cli_options) + FileUtils.cp_r("#{tmpdir}/#{app_name}", cache_dir) # Cache app for future runs. + end + + Dir.chdir("#{tmpdir}/#{app_name}", &block) + end + end + + def stub_bins(*names) + names.each do |name| + File.write("bin/#{name}", <<~BASH) + #!/usr/bin/env bash + echo STUBBED #{name} "$@" + BASH + + FileUtils.chmod(0755, "bin/#{name}") + end + end + + def run_command(*command) + Bundler.with_unbundled_env do + env = { "PATH" => "bin:#{ENV["PATH"]}" } + capture_subprocess_io { system(env, *command, exception: true) } + end + end +end From 9c585cfb808038baab1482b852bc9ee81b54d420 Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Sat, 13 Jan 2024 13:04:22 -0600 Subject: [PATCH 3/7] Test specific behavior of css:install:bootstrap This adds test coverage for specific behavior of the `css:install:bootstrap` command. --- test/bootstrap_installer_test.rb | 77 ++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/test/bootstrap_installer_test.rb b/test/bootstrap_installer_test.rb index 36926d1..fb12a02 100644 --- a/test/bootstrap_installer_test.rb +++ b/test/bootstrap_installer_test.rb @@ -5,6 +5,83 @@ class BootstrapInstallerTest < ActiveSupport::TestCase include RailsAppHelpers include SharedInstallerTests + test "bootstrap installer with pre-existing files" do + with_new_rails_app do + FileUtils.mkdir("app/javascript") + File.write("app/javascript/application.js", "// pre-existing\n", mode: "a+") + File.write("Procfile.dev", "pre: existing\n", mode: "a+") + + out, _err = run_installer + + assert File.exist?("app/assets/stylesheets/application.bootstrap.scss") + + assert_match %r{STUBBED yarn add.* bootstrap\s}, out + assert_match %r{STUBBED yarn add.* bootstrap-icons\s}, out + assert_match %r{STUBBED yarn add.* @popperjs/core\s}, out + + File.read("config/initializers/assets.rb") do |initializer| + assert_match %(config.assets.paths << Rails.root.join("node_modules/bootstrap-icons/font")), initializer + end + + File.read("app/javascript/application.js") do |app_js| + assert_match "// pre-existing", app_js + assert_match %(import * as bootstrap from "bootstrap"), app_js + end + + JSON.load_file("package.json").tap do |package_json| + assert_includes package_json, "browserslist" + assert_match %r{STUBBED npm (?:set-script |pkg set scripts.)build:css:compile[= ]}, out + assert_match %r{STUBBED npm (?:set-script |pkg set scripts.)build:css:prefix[= ]}, out + assert_match %r{STUBBED npm (?:set-script |pkg set scripts.)build:css[= ]}, out + assert_match %r{STUBBED npm (?:set-script |pkg set scripts.)watch:css[= ]}, out + end + + File.read("Procfile.dev").tap do |procfile| + assert_match "pre: existing", procfile + assert_match "css: yarn watch:css", procfile + end + end + end + + test "bootstrap installer without pre-existing files" do + with_new_rails_app do + FileUtils.rm_rf("app/javascript/application.js") + FileUtils.rm_rf("Procfile.dev") + + out, _err = run_installer + + assert_not File.exist?("app/javascript/application.js") + assert_match %(import * as bootstrap from "bootstrap"), out + + File.read("Procfile.dev").tap do |procfile| + assert_match "css: yarn watch:css", procfile + end + end + end + + test "bootstrap installer with Bun" do + with_new_rails_app do + stub_bins("bun") + + out, _err = run_installer + + assert_match %r{STUBBED bun add.* bootstrap\s}, out + assert_match %r{STUBBED bun add.* bootstrap-icons\s}, out + assert_match %r{STUBBED bun add.* @popperjs/core\s}, out + + JSON.load_file("package.json").tap do |package_json| + assert_includes package_json["scripts"], "build:css:compile" + assert_includes package_json["scripts"], "build:css:prefix" + assert_includes package_json["scripts"], "build:css" + assert_includes package_json["scripts"], "watch:css" + end + + File.read("Procfile.dev").tap do |procfile| + assert_match "css: bun run watch:css", procfile + end + end + end + private def run_installer stub_bins("gem", "yarn", "npm") From d3a432cc32ad00c2cf35fd213f4100deaa235167 Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Sat, 13 Jan 2024 13:15:54 -0600 Subject: [PATCH 4/7] Test specific behavior of css:install:bulma This adds test coverage for specific behavior of the `css:install:bulma` command. --- test/bulma_installer_test.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/bulma_installer_test.rb b/test/bulma_installer_test.rb index 2aeee53..f7f55b1 100644 --- a/test/bulma_installer_test.rb +++ b/test/bulma_installer_test.rb @@ -5,6 +5,40 @@ class BulmaInstallerTest < ActiveSupport::TestCase include RailsAppHelpers include SharedInstallerTests + test "bulma installer" do + with_new_rails_app do + out, _err = run_installer + + assert File.exist?("app/assets/stylesheets/application.bulma.scss") + + assert_match %r{STUBBED yarn add.* bulma\s}, out + + assert_match %r{STUBBED npm (?:set-script |pkg set scripts.)build:css[= ]}, out + + File.read("Procfile.dev").tap do |procfile| + assert_match "css: yarn build:css --watch", procfile + end + end + end + + test "bulma installer with Bun" do + with_new_rails_app do + stub_bins("bun") + + out, _err = run_installer + + assert_match %r{STUBBED bun add.* bulma\s}, out + + JSON.load_file("package.json").tap do |package_json| + assert_includes package_json["scripts"], "build:css" + end + + File.read("Procfile.dev").tap do |procfile| + assert_match "css: bun run build:css --watch", procfile + end + end + end + private def run_installer stub_bins("gem", "yarn", "npm") From 1c790d071a975e404e4d45a8bfcd21520b215e8a Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Sat, 13 Jan 2024 13:26:45 -0600 Subject: [PATCH 5/7] Test specific behavior of css:install:postcss This adds test coverage for specific behavior of the `css:install:postcss` command. --- test/postcss_installer_test.rb | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/postcss_installer_test.rb b/test/postcss_installer_test.rb index 7468e48..8e64040 100644 --- a/test/postcss_installer_test.rb +++ b/test/postcss_installer_test.rb @@ -5,6 +5,44 @@ class PostcssInstallerTest < ActiveSupport::TestCase include RailsAppHelpers include SharedInstallerTests + test "postcss installer" do + with_new_rails_app do + out, _err = run_installer + + assert File.exist?("postcss.config.js") + + assert File.exist?("app/assets/stylesheets/application.postcss.css") + + assert_match %r{STUBBED yarn add.* postcss\s}, out + assert_match %r{STUBBED yarn add.* postcss-cli\s}, out + + assert_match %r{STUBBED npm (?:set-script |pkg set scripts.)build:css[= ]}, out + + File.read("Procfile.dev").tap do |procfile| + assert_match "css: yarn build:css --watch", procfile + end + end + end + + test "postcss installer with Bun" do + with_new_rails_app do + stub_bins("bun") + + out, _err = run_installer + + assert_match %r{STUBBED bun add.* postcss\s}, out + assert_match %r{STUBBED bun add.* postcss-cli\s}, out + + JSON.load_file("package.json").tap do |package_json| + assert_includes package_json["scripts"], "build:css" + end + + File.read("Procfile.dev").tap do |procfile| + assert_match "css: bun run build:css --watch", procfile + end + end + end + private def run_installer stub_bins("gem", "yarn", "npm") From 27bcdd1dd75a531b2102e916c4d8c818957cb2d0 Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Sat, 13 Jan 2024 13:31:04 -0600 Subject: [PATCH 6/7] Test specific behavior of css:install:sass This adds test coverage for specific behavior of the `css:install:sass` command. --- test/sass_installer_test.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/sass_installer_test.rb b/test/sass_installer_test.rb index e86fa7e..fead27e 100644 --- a/test/sass_installer_test.rb +++ b/test/sass_installer_test.rb @@ -5,6 +5,40 @@ class SassInstallerTest < ActiveSupport::TestCase include RailsAppHelpers include SharedInstallerTests + test "sass installer" do + with_new_rails_app do + out, _err = run_installer + + assert File.exist?("app/assets/stylesheets/application.sass.scss") + + assert_match %r{STUBBED yarn add.* sass\s}, out + + assert_match %r{STUBBED npm (?:set-script |pkg set scripts.)build:css[= ]}, out + + File.read("Procfile.dev").tap do |procfile| + assert_match "css: yarn build:css --watch", procfile + end + end + end + + test "sass installer with Bun" do + with_new_rails_app do + stub_bins("bun") + + out, _err = run_installer + + assert_match %r{STUBBED bun add.* sass\s}, out + + JSON.load_file("package.json").tap do |package_json| + assert_includes package_json["scripts"], "build:css" + end + + File.read("Procfile.dev").tap do |procfile| + assert_match "css: bun run build:css --watch", procfile + end + end + end + private def run_installer stub_bins("gem", "yarn", "npm") From 59ac500cfd36378cad666b1924f13f2b59b0a376 Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Sat, 13 Jan 2024 13:33:28 -0600 Subject: [PATCH 7/7] Test specific behavior of css:install:tailwind This adds test coverage for specific behavior of the `css:install:tailwind` command. --- test/tailwind_installer_test.rb | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/tailwind_installer_test.rb b/test/tailwind_installer_test.rb index 76a5ea9..02cff10 100644 --- a/test/tailwind_installer_test.rb +++ b/test/tailwind_installer_test.rb @@ -5,6 +5,42 @@ class TailwindInstallerTest < ActiveSupport::TestCase include RailsAppHelpers include SharedInstallerTests + test "tailwind installer" do + with_new_rails_app do + out, _err = run_installer + + assert File.exist?("tailwind.config.js") + + assert File.exist?("app/assets/stylesheets/application.tailwind.css") + + assert_match %r{STUBBED yarn add.* tailwindcss@latest\s}, out + + assert_match %r{STUBBED npm (?:set-script |pkg set scripts.)build:css[= ]}, out + + File.read("Procfile.dev").tap do |procfile| + assert_match "css: yarn build:css --watch", procfile + end + end + end + + test "tailwind installer with Bun" do + with_new_rails_app do + stub_bins("bun") + + out, _err = run_installer + + assert_match %r{STUBBED bun add.* tailwindcss@latest\s}, out + + JSON.load_file("package.json").tap do |package_json| + assert_includes package_json["scripts"], "build:css" + end + + File.read("Procfile.dev").tap do |procfile| + assert_match "css: bun run build:css --watch", procfile + end + end + end + private def run_installer stub_bins("gem", "yarn", "npm")