diff --git a/.autotest b/.autotest deleted file mode 100644 index 66c83c2..0000000 --- a/.autotest +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -require 'autotest/restart' - -Autotest.add_hook :initialize do |at| - # .minitest.rb ensures that the gem version of minitest is used. - at.testlib = '.minitest.rb' -end diff --git a/.gemtest b/.gemtest deleted file mode 100644 index 8b13789..0000000 --- a/.gemtest +++ /dev/null @@ -1 +0,0 @@ - diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 0000000..6b8f1c4 --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,70 @@ +name: Ruby CI + +on: + pull_request: + branches: + - main + push: + branches: + - main + workflow_dispatch: + +jobs: + ruby-ci: + name: Ruby ${{ matrix.ruby }} - ${{ matrix.gemfile }} - ${{ matrix.os }} + + strategy: + fail-fast: true + matrix: + gemfile: + - rack_1 + - rack_2 + - rack_3 + os: + - ubuntu-20.04 + ruby: + - '2.7' + - '3.0' + - '3.1' + - head + - jruby + - jruby-head + - truffleruby + - truffleruby-head + - truffleruby+graalvm + - truffleruby+graalvm-head + include: + - ruby: head + continue-on-error: true + - ruby: jruby-head + continue-on-error: true + - os: ubuntu-22.04 + ruby: head + gemfile: rack_2 + - os: ubuntu-22.04 + ruby: head + gemfile: rack_3 + - os: ubuntu-22.04 + ruby: '3.1' + gemfile: rack_2 + - os: ubuntu-22.04 + ruby: '3.1' + gemfile: rack_3 + + runs-on: ${{ matrix.os }} + + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile + + continue-on-error: ${{ matrix.continue-on-error || false }} + + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + + - run: bundle exec ruby -S rake test --trace + + - run: bundle exec standardrb diff --git a/.gitignore b/.gitignore index 6b7c738..c971875 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,6 @@ -*.swp -*~ .bundle/ .byebug_history .rake_tasks~ -.source_index -.vagrant Gemfile.lock gemfiles/*.lock coverage/ diff --git a/.hoerc b/.hoerc index 5603749..e4c7895 100644 --- a/.hoerc +++ b/.hoerc @@ -1,50 +1,50 @@ --- exclude: !ruby/regexp '/ \.(?: - tmp | - swp - ) - $ + tmp | + swp + )$ | \.(?: - autotest | - gemtest | - gitignore | - workenv | - hoerc | - minitest.rb | - simplecov-prelude.rb - ) - $ - | - CVS\/ - | - ^(?i:TAGS) - | - \.(?: - DS_Store | - bundle | - git | - hg | - idea | - svn | + bundle| + git| + github| + hg| + idea| + svn| vagrant )\/ | - Appraisals - | - vendor\/ + [Aa]ppraisals | [gG]emfile(?:\.lock)? | \.(?: - coveralls | - pullreview | - travis | - rubocop.* - )\.yml$ - | - \.byebug_history + appveyor | + coveralls | + fasterer | + pullreview | + rubocop.* | + standard.* | + travis | + unused + )\.yml$ + | + (?i:TAGS)$ | - \.gemspec + \.(?: + DS_Store | + autotest | + byebug_history | + gemtest | + gitattributes | + gitignore | + hoerc | + minitest.rb | + simplecov-prelude.rb + )$ + | + \.gemspec$ + | + Vagrantfile$ /x' diff --git a/.minitest.rb b/.minitest.rb deleted file mode 100644 index 271fe9a..0000000 --- a/.minitest.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true -gem 'minitest' -require 'minitest/autorun' diff --git a/.rdoc_options b/.rdoc_options new file mode 100644 index 0000000..a25e883 --- /dev/null +++ b/.rdoc_options @@ -0,0 +1,28 @@ +--- !ruby/object:RDoc::Options +encoding: UTF-8 +static_path: [] +rdoc_include: +- "." +charset: UTF-8 +exclude: +- Manifest.txt\z +- ~\z +- \.orig\z +- \.rej\z +- \.bak\z +- \.gemspec\z +hyperlink_all: false +line_numbers: false +locale: +locale_dir: locale +locale_name: +main_page: +markup: markdown +output_decoration: true +page_dir: +show_hash: false +tab_width: 8 +template_stylesheets: [] +title: +visibility: :protected +webcvs: diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index 4ebaa2f..0000000 --- a/.rubocop.yml +++ /dev/null @@ -1,227 +0,0 @@ ---- -AllCops: - Include: - - '**/config.rb' - Exclude: - - 'bin/**/*' - - 'config/**/*' - - 'script/**/*' - - 'tmp/**/*' - DisplayCopNames: true - DisplayStyleGuide: true - ExtraDetails: true - TargetRubyVersion: 2.3 - -# { Lint cops - -Lint/UnusedMethodArgument: - Exclude: [] - -# } Lint cops - -# { Metrics cops -# These are mostly disabled because they should be advisory, not build -# failures. - -Metrics/AbcSize: - Enabled: false - -Metrics/ClassLength: - Enabled: false - -Metrics/ModuleLength: - Enabled: false - -Metrics/CyclomaticComplexity: - Enabled: false - -Metrics/LineLength: - Max: 90 - Exclude: - - test/**/* - - db/migrate/**/* - - Gemfile - -Metrics/MethodLength: - Enabled: false - -Metrics/PerceivedComplexity: - Enabled: false -# } Metrics cops - -# { Performance cops -# Performance/FixedSize: -# Enabled: false -# } Performance cops - -# { Rails cops -Rails: - Enabled: true - -# Rails delegation should never be used in lib/, and only in app/. -Rails/Delegate: - Include: - - app/**/*.rb - Exclude: - - lib/**/*.rb -# } Rails cops - -# { Style cops -Style/AlignHash: - EnforcedHashRocketStyle: key - EnforcedColonStyle: key - -Style/AlignParameters: - EnforcedStyle: with_fixed_indentation - -Style/AndOr: - EnforcedStyle: conditionals - -Style/AsciiComments: - Enabled: false - -Style/BarePercentLiterals: - EnforcedStyle: percent_q - -# Don't allow by default, but permit on a file-by-file basis by exclusion. -Style/BlockComments: - Exclude: [] - -Style/BlockDelimiters: - EnforcedStyle: semantic - ProceduralMethods: - - assert_raises - - spec - - tap - FunctionalMethods: - - reject! - - delete_if - - let - -Style/BracesAroundHashParameters: - EnforcedStyle: context_dependent - -# This is purely a readability issue. -Style/ClassAndModuleChildren: - Enabled: false - -# I prefer #kind_of? to #is_a? -Style/ClassCheck: - EnforcedStyle: kind_of? - -Style/CommandLiteral: - EnforcedStyle: percent_x - -# Many of the support modules follow Seattle style because minitest. -Style/DefWithParentheses: - Exclude: - - 'test/support/**/*' - -Style/Documentation: - Exclude: - - '**/Rakefile' - - 'app/**/*' - - 'test/**/*' - -Style/DotPosition: - EnforcedStyle: trailing - -Style/DoubleNegation: - Enabled: false - -# Don't enable by default, but permit on a file-by-file basis by exclusion. -Style/EmptyElse: - EnforcedStyle: empty - -# Don't allow by default, but permit on a file-by-file basis by exclusion. -Style/FileName: - Exclude: - - Appraisals - - Gemfile - - Rakefile # WTF? This should be excluded by default. - -# I prefer `str % args`; the style guide suggests `str.format(args)`. -Style/FormatString: - Enabled: false - -Style/GlobalVars: - AllowedVariables: [] - -Style/SpecialGlobalVars: - Enabled: false - -# Make this match Metrics/LineLength -Style/IfUnlessModifier: - MaxLineLength: 90 - -# I prefer `->(){}` to `lambda{||}` -Style/Lambda: - Enabled: false - -# Allow any of callable.call(), callable.(), or callable[]. -Style/LambdaCall: - Enabled: false - -# Many of the support modules follow Seattle style because minitest. -Style/MethodDefParentheses: - Exclude: - - 'test/support/**/*' - - 'test/minitest_config.rb' - -Style/MultilineMethodCallIndentation: - EnforcedStyle: indented - -Style/MultilineOperationIndentation: - EnforcedStyle: indented - -Style/RegexpLiteral: - EnforcedStyle: mixed - -# I prefer spaces in brackets for array declarations, unless empty. -Style/SpaceInsideBrackets: - Enabled: false - -Style/SignalException: - EnforcedStyle: semantic - -Style/SymbolArray: - Enabled: true - -# Make this match Metrics/LineLength -Style/WhileUntilModifier: - MaxLineLength: 90 - -Style/MethodName: - Exclude: - - lib/cartage/rack.rb - - lib/cartage/rack/simple.rb - -Style/ParallelAssignment: - Enabled: false - -# { 20160419 Trying some cops that are disabled by default. - -# Favour File.open { ... } over f = File.open; f.close -Style/AutoResourceCleanup: - Enabled: true - -# Prefer map over collect, etc. -Style/CollectionMethods: - Enabled: true - -# If an array is a multi-line array, it should start that way, too. -Style/FirstArrayElementLineBreak: - Enabled: true - -# If a hash is a multi-line hash, it should start that way, too. -Style/FirstHashElementLineBreak: - Enabled: true - -# If a method call is broken over multiple lines, it should start that way, too. -Style/FirstMethodArgumentLineBreak: - Enabled: true - -Style/StringMethods: - Enabled: true -# } 20160419 Trying some cops that are disabled by default. -# } Style cops diff --git a/.simplecov-prelude.rb b/.simplecov-prelude.rb deleted file mode 100644 index f652c7b..0000000 --- a/.simplecov-prelude.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true -require 'simplecov' - -SimpleCov.start do - command_name 'Minitest' - add_filter '/lib/cartage/backport.rb' - add_filter '/test/' -end - -gem 'minitest' diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..d6e14e4 --- /dev/null +++ b/.standard.yml @@ -0,0 +1,5 @@ +--- +parallel: true +ruby_version: '3.1' +ignore: + - 'cartage-rack.gemspec' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 768128b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,52 +0,0 @@ -language: ruby - -rvm: - - 2.5.0 - - 2.4.3 - - 2.3.6 - - 2.2.9 - - 2.1.10 - - 2.0.0-p648 - - jruby-9.1.9.0 - - jruby-9.0.5.0 - - ruby-head - - jruby-head - -gemfile: - - Gemfile - -bundler_args: --path vendor/bundle - -sudo: false - -before_script: - - bundle exec rake travis:before -t - -script: bundle exec rake travis - -after_script: - - bundle exec rake travis:after -t - -env: - - - RUBYOPT=-W0 - - BUNDLE_WITHOUT=local_development - -before_install: - - bundle config --local without local_development - -matrix: - allow_failures: - - rvm: jruby-head - - rvm: ruby-head - fast_finish: true - -notifications: - email: - on_success: change - on_failure: always - hipchat: - on_success: change - on_failure: always - notify: true - rooms: - secure: CbG+RlNoPO4KWPLNcrJ/5j/hjlNcQD/XSnM7ebFA1WmajZOvkfArb/4Z9rcwfLMFAvZKHM+2l4J4+natvrfgQ9aTq9dQXQeF5AEFJlbbHrD6q7neAw/ER2xpoQ1I6SwbBTW81YIKXzXjK4eA83QxDRzT14x8hOeAFlMEUfCoRoyr+X6Y/TMii9CcRSf4AIumi4C7TFMV/rvggbTjuXXk3RjS+YYe/YQmFOcinHHJMf1A2s5aoOOPPKhL0i37Do15WgvhexOCj92CDfGfLEL5bM0SuBSuFTGQX7BCaemUcS9amKJgzTeULexgfZ0YD0BRAJV7p2CEVIwrhEei1EHG/3vF6ReiFkMTJN35PSDnpzGgb8jhYpvQx9xm3x1iwTFpiWhD83Q5sC6BlEZXkH1LaU8SSgQNYcgcUKWJ2Tgkf4Y16JCW6sEruyAxg0SiZNrHJKjhpdeKHzEPcngLLXAxpBMaYiZsZm2MTU85bZodhvuBY5vcvo/BpNmPPY5k+B96yrUXsmPOgHtXls2POOVCYKRsbdjDYi0/s/KvHNPeSO+caQ8HnQVlxBs2uZRy/hryiDQWJVKX5MyvTnf7oWUmln5a2VWSXZUtokHyqnCYT9BST3IBVEKRDrP0vtcXAVBgQj1BLrdzsEEVE7w6Nxr3zRxDIH6WDn44cCMvWscXLi4= diff --git a/Appraisals b/Appraisals new file mode 100644 index 0000000..59a86f7 --- /dev/null +++ b/Appraisals @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +appraise "rack-1" do + gem "rack", "~> 1.6" + gem "rack-test", "~> 1.0" +end + +appraise "rack-2" do + gem "rack", "~> 2.0" + gem "rack-test", "~> 1.0" +end + +appraise "rack-3" do + gem "rack", "~> 3.0" +end + +# As of 2022-12-15, Psych 5.0 does not install on macOS Ventura. Lock to the +# latest known working version. +# +# Although Appraisal is supposed to have `#install_if` support for when it +# parses the Gemfile, it isn’t working, so we are using this workaround: +# https://github.com/thoughtbot/appraisal/issues/131#issuecomment-511075918 +if RUBY_PLATFORM.match?(/darwin/) + each do |spec| + spec.gem "psych", "~> 4.0" + end +end diff --git a/Gemfile b/Gemfile index 0a381c9..47c9ee6 100644 --- a/Gemfile +++ b/Gemfile @@ -3,12 +3,14 @@ # NOTE: This file is not the canonical source of dependencies. Edit the # Rakefile, instead. -source 'https://rubygems.org/' +source "https://rubygems.org/" # Specify your gem's dependencies in cartage-rack.gemspec gemspec -group :local_development, :test do - gem 'byebug', platforms: :mri - gem 'pry' -end if ENV['LOCAL_DEV'] +if ENV["LOCAL_DEV"] + group :local_development, :test do + gem "byebug", platforms: :mri + gem "pry" + end +end diff --git a/History.md b/History.md index d73e487..b272a96 100644 --- a/History.md +++ b/History.md @@ -1,55 +1,81 @@ -### 2.2 / 2018-03-23 +# Change History -* Add support for ENV['APP_ENV'] per Sinatra documentation recommendations. +## 2.3 / 2022-12-16 -### 2.1 / 2016-06-28 +This is primarily a (mostly-mechanical) modernization of the codebase, +bringing it up to Kinetic Commerce 2022 standards. -* Fix default env issue where ENV['RAILS_ENV'] nor ENV['RACK_ENV'] is set - by adding default string. +- Remove dead development files: `.autotest`, `.gemtest`, `.minitest.rb`, + `.rubocop.yml`, `.simplecov-prelude.rb`, `.travis.yml` -### 2.0 / 2016-05-31 +- Add new development files: `.github/workflows/ruby.yml`, `.rdoc_options`, + `.standard.yml`, `Appraisals`, `gemfiles/*.gemfile` -* Rewrote for compatibility with cartage 2.0. +- Clean up configuration: `.gitignore`, `.hoerc`, `Rakefile` - * Renamed Cartage::Rack to Cartage::Rack::Simple and created a *new* - Cartage::Rack that returns more information. +- Updated generated files: `Manifest.txt`, `cartage-rack.gemspec` - * Extracted metadata gathering out of Cartage::Rack and into - Cartage::Rack::Metadata. +- Renamed `test/minitest_config.rb` to `test/minitest_helper.rb` to reflect + consistent naming. - * Deprecated Cartage::Rack.mount in favour of Cartage::Rack() and - Cartage::Rack::Simple() methods. +- Removed `context` alias for `describe`. -* 1 governance change +- Apply formatting from `standardrb` after dropping raw rubocop. - * cartage-rack is now under the Kinetic Cafe Open Source [Code of - Conduct][kccoc]. +- Sunset cartage-rack as of this version. -### 1.1 / 2015-04-11 +## 2.2 / 2018-03-23 -* 2 minor enhancements +- Add support for ENV['APP_ENV'] per Sinatra documentation recommendations. - * Implemented Cartage::Rack#inspect to prevent `rake routes` from - presenting badly. +## 2.1 / 2016-06-28 - * Preparing for a future Cartage change to the contents of the - `release_hashref` file. The future `release_hashref` will be two lines: +- Fix default env issue where ENV['RAILS_ENV'] nor ENV['RACK_ENV'] is set + by adding default string. - hashref - timestamp +## 2.0 / 2016-05-31 - If `release_hashref` has two lines, the timestamp will be included in - the response. A timestamp will not be included if there is no - `release_hashref` file. +- Rewrote for compatibility with cartage 2.0. -* 1 development change + - Renamed Cartage::Rack to Cartage::Rack::Simple and created a _new_ + Cartage::Rack that returns more information. - * Implemented tests for Cartage::Rack. + - Extracted metadata gathering out of Cartage::Rack and into + Cartage::Rack::Metadata. -### 1.0 / 2015-03-20 + - Deprecated Cartage::Rack.mount in favour of Cartage::Rack() and + Cartage::Rack::Simple() methods. -* 1 major enhancement +- 1 governance change - * Birthday! + - cartage-rack is now under the Kinetic Cafe Open Source [Code of + Conduct][kccoc]. + +## 1.1 / 2015-04-11 + +- 2 minor enhancements + + - Implemented Cartage::Rack#inspect to prevent `rake routes` from + presenting badly. + + - Preparing for a future Cartage change to the contents of the + `release_hashref` file. The future `release_hashref` will be two lines: + + hashref + timestamp + + If `release_hashref` has two lines, the timestamp will be included in + the response. A timestamp will not be included if there is no + `release_hashref` file. + +- 1 development change + + - Implemented tests for Cartage::Rack. + +## 1.0 / 2015-03-20 + +- 1 major enhancement + + - Birthday! [kccoc]: https://github.com/KineticCafe/code-of-conduct diff --git a/Manifest.txt b/Manifest.txt index ef1f06e..0342cc5 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -7,7 +7,7 @@ Rakefile lib/cartage/rack.rb lib/cartage/rack/metadata.rb lib/cartage/rack/simple.rb -test/minitest_config.rb +test/minitest_helper.rb test/test_cartage_rack.rb test/test_cartage_rack_metadata.rb test/test_cartage_rack_simple.rb diff --git a/README.rdoc b/README.rdoc index d593a02..e0b2342 100644 --- a/README.rdoc +++ b/README.rdoc @@ -6,14 +6,19 @@ continuous integration :: {= 10.0'] - extra_dev_deps << ['rdoc', '~> 4.2'] - extra_dev_deps << ['rack-test', '~> 0.6'] - extra_dev_deps << ['hoe-doofus', '~> 1.0'] - extra_dev_deps << ['hoe-gemspec2', '~> 1.1'] - extra_dev_deps << ['hoe-git', '~> 1.5'] - extra_dev_deps << ['hoe-travis', '~> 1.2'] - extra_dev_deps << ['minitest', '~> 5.4'] - extra_dev_deps << ['minitest-autotest', '~> 1.0'] - extra_dev_deps << ['minitest-bisect', '~> 1.2'] - extra_dev_deps << ['minitest-bonus-assertions', '~> 2.0'] - extra_dev_deps << ['minitest-focus', '~> 1.1'] - extra_dev_deps << ['minitest-hooks', '~> 1.4'] - extra_dev_deps << ['minitest-moar', '~> 0.0'] - extra_dev_deps << ['minitest-pretty_diff', '~> 0.1'] - extra_dev_deps << ['timecop', '~> 0.8'] - extra_dev_deps << ['simplecov', '~> 0.7'] -end + license "MIT" -ENV['RUBYOPT'] = '-W0' + require_ruby_version ">= 2.7", "< 4" -module Hoe::Publish #:nodoc: - alias __make_rdoc_cmd__cartage__ make_rdoc_cmd + spec_extras[:metadata] = ->(val) { val["rubygems_mfa_required"] = "true" } - def make_rdoc_cmd(*extra_args) # :nodoc: - spec.extra_rdoc_files.delete_if { |f| f == 'Manifest.txt' } - __make_rdoc_cmd__cartage__(*extra_args) - end -end - -if File.exist?('.simplecov-prelude.rb') - namespace :test do - task :coverage do - spec.test_prelude = 'load ".simplecov-prelude.rb"' - Rake::Task['test'].execute - end + # This gem *explicitly* does not have a hard link to cartage. - CLOBBER << 'coverage' - end + extra_dev_deps << ["appraisal", "~> 2.4"] + extra_dev_deps << ["hoe-doofus", "~> 1.0"] + extra_dev_deps << ["hoe-gemspec2", "~> 1.1"] + extra_dev_deps << ["hoe-git2", "~> 1.7"] + extra_dev_deps << ["hoe-rubygems", "~> 1.0"] + extra_dev_deps << ["minitest", "~> 5.16"] + extra_dev_deps << ["minitest-autotest", "~> 1.0"] + extra_dev_deps << ["minitest-bisect", "~> 1.2"] + extra_dev_deps << ["minitest-focus", "~> 1.1"] + extra_dev_deps << ["minitest-hooks", "~> 1.4"] + extra_dev_deps << ["minitest-moar", "~> 0.0"] + extra_dev_deps << ["minitest-pretty_diff", "~> 0.1"] + extra_dev_deps << ["rack-test", "~> 2.0"] + extra_dev_deps << ["rake", ">= 10.0", "< 14"] + extra_dev_deps << ["rdoc", "~> 6.4"] + extra_dev_deps << ["simplecov", "~> 0.7"] + extra_dev_deps << ["standard", "~> 1.0"] + extra_dev_deps << ["timecop", "~> 0.8"] end - -CLOBBER << 'tmp' diff --git a/cartage-rack.gemspec b/cartage-rack.gemspec index fb8fe16..59fa49d 100644 --- a/cartage-rack.gemspec +++ b/cartage-rack.gemspec @@ -1,85 +1,69 @@ # -*- encoding: utf-8 -*- -# stub: cartage-rack 2.2 ruby lib +# stub: cartage-rack 2.3 ruby lib Gem::Specification.new do |s| s.name = "cartage-rack".freeze - s.version = "2.2" + s.version = "2.3" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= + s.metadata = { "rubygems_mfa_required" => "true", "source_code_uri" => "https://github.com/KineticCafe/cartage-rack/" } if s.respond_to? :metadata= s.require_paths = ["lib".freeze] - s.authors = ["Austin Ziegler".freeze] - s.date = "2018-03-22" - s.description = "cartage-rack is a plug-in for {cartage}[https://github.com/KineticCafe/cartage]\nto provide a Rack application that reports on release metadata.\n\nCartage provides a repeatable means to create a package for a Rails application\nthat can be used in deployment with a configuration tool like Ansible, Chef,\nPuppet, or Salt. The package is created with its dependencies bundled in\n+vendor/bundle+, so it can be deployed in environments with strict access\ncontrol rules and without requiring development tool access.".freeze - s.email = ["aziegler@kineticcafe.com".freeze] + s.authors = ["Austin Ziegler".freeze, "Kinetic Commerce".freeze] + s.date = "2022-12-16" + s.description = "This release is the *last* version of cartage-rack. It will be replaced with\na different tool in the future, but this release will allow installation in\nmodern Ruby versions.\n\ncartage-rack is a plug-in for\n{cartage}[https://github.com/KineticCafe/cartage] to provide a Rack\napplication that reports on release metadata.\n\nCartage provides a repeatable means to create a package for a Rails\napplication that can be used in deployment with a configuration tool like\nAnsible, Chef, Puppet, or Salt. The package is created with its dependencies\nbundled in +vendor/bundle+, so it can be deployed in environments with strict\naccess control rules and without requiring development tool access.".freeze + s.email = ["aziegler@kineticcommerce.com".freeze, "dev@kineticcommerce.com".freeze] s.extra_rdoc_files = ["Contributing.md".freeze, "History.md".freeze, "Licence.md".freeze, "Manifest.txt".freeze, "README.rdoc".freeze] - s.files = ["Contributing.md".freeze, "History.md".freeze, "Licence.md".freeze, "Manifest.txt".freeze, "README.rdoc".freeze, "Rakefile".freeze, "lib/cartage/rack.rb".freeze, "lib/cartage/rack/metadata.rb".freeze, "lib/cartage/rack/simple.rb".freeze, "test/minitest_config.rb".freeze, "test/test_cartage_rack.rb".freeze, "test/test_cartage_rack_metadata.rb".freeze, "test/test_cartage_rack_simple.rb".freeze] + s.files = ["Contributing.md".freeze, "History.md".freeze, "Licence.md".freeze, "Manifest.txt".freeze, "README.rdoc".freeze, "Rakefile".freeze, "lib/cartage/rack.rb".freeze, "lib/cartage/rack/metadata.rb".freeze, "lib/cartage/rack/simple.rb".freeze, "test/minitest_helper.rb".freeze, "test/test_cartage_rack.rb".freeze, "test/test_cartage_rack_metadata.rb".freeze, "test/test_cartage_rack_simple.rb".freeze] s.homepage = "https://github.com/KineticCafe/cartage-rack/".freeze s.licenses = ["MIT".freeze] s.rdoc_options = ["--main".freeze, "README.rdoc".freeze] - s.required_ruby_version = Gem::Requirement.new("~> 2.0".freeze) - s.rubygems_version = "2.7.6".freeze - s.summary = "cartage-rack is a plug-in for {cartage}[https://github.com/KineticCafe/cartage] to provide a Rack application that reports on release metadata".freeze + s.required_ruby_version = Gem::Requirement.new([">= 2.7".freeze, "< 4".freeze]) + s.rubygems_version = "3.3.26".freeze + s.summary = "This release is the *last* version of cartage-rack".freeze if s.respond_to? :specification_version then s.specification_version = 4 + end - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_development_dependency(%q.freeze, ["~> 5.11"]) - s.add_development_dependency(%q.freeze, [">= 10.0"]) - s.add_development_dependency(%q.freeze, ["~> 4.2"]) - s.add_development_dependency(%q.freeze, ["~> 0.6"]) - s.add_development_dependency(%q.freeze, ["~> 1.0"]) - s.add_development_dependency(%q.freeze, ["~> 1.1"]) - s.add_development_dependency(%q.freeze, ["~> 1.5"]) - s.add_development_dependency(%q.freeze, ["~> 1.2"]) - s.add_development_dependency(%q.freeze, ["~> 1.0"]) - s.add_development_dependency(%q.freeze, ["~> 1.2"]) - s.add_development_dependency(%q.freeze, ["~> 2.0"]) - s.add_development_dependency(%q.freeze, ["~> 1.1"]) - s.add_development_dependency(%q.freeze, ["~> 1.4"]) - s.add_development_dependency(%q.freeze, ["~> 0.0"]) - s.add_development_dependency(%q.freeze, ["~> 0.1"]) - s.add_development_dependency(%q.freeze, ["~> 0.8"]) - s.add_development_dependency(%q.freeze, ["~> 0.7"]) - s.add_development_dependency(%q.freeze, ["~> 3.17"]) - else - s.add_dependency(%q.freeze, ["~> 5.11"]) - s.add_dependency(%q.freeze, [">= 10.0"]) - s.add_dependency(%q.freeze, ["~> 4.2"]) - s.add_dependency(%q.freeze, ["~> 0.6"]) - s.add_dependency(%q.freeze, ["~> 1.0"]) - s.add_dependency(%q.freeze, ["~> 1.1"]) - s.add_dependency(%q.freeze, ["~> 1.5"]) - s.add_dependency(%q.freeze, ["~> 1.2"]) - s.add_dependency(%q.freeze, ["~> 1.0"]) - s.add_dependency(%q.freeze, ["~> 1.2"]) - s.add_dependency(%q.freeze, ["~> 2.0"]) - s.add_dependency(%q.freeze, ["~> 1.1"]) - s.add_dependency(%q.freeze, ["~> 1.4"]) - s.add_dependency(%q.freeze, ["~> 0.0"]) - s.add_dependency(%q.freeze, ["~> 0.1"]) - s.add_dependency(%q.freeze, ["~> 0.8"]) - s.add_dependency(%q.freeze, ["~> 0.7"]) - s.add_dependency(%q.freeze, ["~> 3.17"]) - end + if s.respond_to? :add_runtime_dependency then + s.add_development_dependency(%q.freeze, ["~> 2.4"]) + s.add_development_dependency(%q.freeze, ["~> 1.0"]) + s.add_development_dependency(%q.freeze, ["~> 1.1"]) + s.add_development_dependency(%q.freeze, ["~> 1.7"]) + s.add_development_dependency(%q.freeze, ["~> 1.0"]) + s.add_development_dependency(%q.freeze, ["~> 5.16"]) + s.add_development_dependency(%q.freeze, ["~> 1.0"]) + s.add_development_dependency(%q.freeze, ["~> 1.2"]) + s.add_development_dependency(%q.freeze, ["~> 1.1"]) + s.add_development_dependency(%q.freeze, ["~> 1.4"]) + s.add_development_dependency(%q.freeze, ["~> 0.0"]) + s.add_development_dependency(%q.freeze, ["~> 0.1"]) + s.add_development_dependency(%q.freeze, ["~> 2.0"]) + s.add_development_dependency(%q.freeze, [">= 10.0", "< 14"]) + s.add_development_dependency(%q.freeze, ["~> 6.4"]) + s.add_development_dependency(%q.freeze, ["~> 0.7"]) + s.add_development_dependency(%q.freeze, ["~> 1.0"]) + s.add_development_dependency(%q.freeze, ["~> 0.8"]) + s.add_development_dependency(%q.freeze, ["~> 3.26"]) else - s.add_dependency(%q.freeze, ["~> 5.11"]) - s.add_dependency(%q.freeze, [">= 10.0"]) - s.add_dependency(%q.freeze, ["~> 4.2"]) - s.add_dependency(%q.freeze, ["~> 0.6"]) + s.add_dependency(%q.freeze, ["~> 2.4"]) s.add_dependency(%q.freeze, ["~> 1.0"]) s.add_dependency(%q.freeze, ["~> 1.1"]) - s.add_dependency(%q.freeze, ["~> 1.5"]) - s.add_dependency(%q.freeze, ["~> 1.2"]) + s.add_dependency(%q.freeze, ["~> 1.7"]) + s.add_dependency(%q.freeze, ["~> 1.0"]) + s.add_dependency(%q.freeze, ["~> 5.16"]) s.add_dependency(%q.freeze, ["~> 1.0"]) s.add_dependency(%q.freeze, ["~> 1.2"]) - s.add_dependency(%q.freeze, ["~> 2.0"]) s.add_dependency(%q.freeze, ["~> 1.1"]) s.add_dependency(%q.freeze, ["~> 1.4"]) s.add_dependency(%q.freeze, ["~> 0.0"]) s.add_dependency(%q.freeze, ["~> 0.1"]) - s.add_dependency(%q.freeze, ["~> 0.8"]) + s.add_dependency(%q.freeze, ["~> 2.0"]) + s.add_dependency(%q.freeze, [">= 10.0", "< 14"]) + s.add_dependency(%q.freeze, ["~> 6.4"]) s.add_dependency(%q.freeze, ["~> 0.7"]) - s.add_dependency(%q.freeze, ["~> 3.17"]) + s.add_dependency(%q.freeze, ["~> 1.0"]) + s.add_dependency(%q.freeze, ["~> 0.8"]) + s.add_dependency(%q.freeze, ["~> 3.26"]) end end diff --git a/gemfiles/rack_1.gemfile b/gemfiles/rack_1.gemfile new file mode 100644 index 0000000..3d87284 --- /dev/null +++ b/gemfiles/rack_1.gemfile @@ -0,0 +1,9 @@ +# This file was generated by Appraisal + +source "https://rubygems.org/" + +gem "rack", "~> 1.6" +gem "rack-test", "~> 1.0" +gem "psych", "~> 4.0" + +gemspec path: "../" diff --git a/gemfiles/rack_2.gemfile b/gemfiles/rack_2.gemfile new file mode 100644 index 0000000..bbe8fbc --- /dev/null +++ b/gemfiles/rack_2.gemfile @@ -0,0 +1,9 @@ +# This file was generated by Appraisal + +source "https://rubygems.org/" + +gem "rack", "~> 2.0" +gem "rack-test", "~> 1.0" +gem "psych", "~> 4.0" + +gemspec path: "../" diff --git a/gemfiles/rack_3.gemfile b/gemfiles/rack_3.gemfile new file mode 100644 index 0000000..0f5d1a4 --- /dev/null +++ b/gemfiles/rack_3.gemfile @@ -0,0 +1,8 @@ +# This file was generated by Appraisal + +source "https://rubygems.org/" + +gem "rack", "~> 3.0" +gem "psych", "~> 4.0" + +gemspec path: "../" diff --git a/lib/cartage/rack.rb b/lib/cartage/rack.rb index ae62722..275261d 100644 --- a/lib/cartage/rack.rb +++ b/lib/cartage/rack.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'pathname' -require 'json' +require "pathname" +require "json" # Cartage, a package builder. class Cartage @@ -15,7 +15,7 @@ def self.Rack(root_path = nil, &filter) # +application/json+ value, or as a +text/plain+ string if called with # +.text+ or +.txt+. class Rack - VERSION = '2.2' #:nodoc: + VERSION = "2.3" # :nodoc: class << self # When +true+, Cartage::Rack and Cartage::Rack::Simple will raise an @@ -32,7 +32,7 @@ def require_metadata(value = (arg = false; nil)) # rubocop:disable Style/Semicol private def default_require_metadata - environment = ENV['RAILS_ENV'] || ENV['APP_ENV'] || ENV['RACK_ENV'] || 'development' + environment = ENV["RAILS_ENV"] || ENV["APP_ENV"] || ENV["RACK_ENV"] || "development" environment !~ /\A(?:development|test)\z/i end end @@ -41,12 +41,12 @@ def initialize(root_path = nil, &filter) # :nodoc: @metadata = Cartage::Rack::Metadata.new(root_path, filter: filter) end - def call(env) #:nodoc: + def call(env) # :nodoc: type, body = resolve_content(env) - [ '200', { 'Content-Type' => type }, [ body ] ] + ["200", {"Content-Type" => type}, [body]] end - def inspect #:nodoc: + def inspect # :nodoc: "#{self.class} for #{@metadata.inspect}" end @@ -55,32 +55,32 @@ def inspect #:nodoc: def resolve_content(env) content = @metadata.resolve - case env['PATH_INFO'] + case env["PATH_INFO"] when /\.te?xt\z/ - type = 'text/plain' + type = "text/plain" body = [ - "name: #{dig(content, 'package', 'name')}", - "environment: #{dig(content, 'env', 'name')}", - "hashref: #{dig(content, 'package', 'hashref')}" + "name: #{dig(content, "package", "name")}", + "environment: #{dig(content, "env", "name")}", + "hashref: #{dig(content, "package", "hashref")}" ] - value = dig(content, 'package', 'timestamp') + value = dig(content, "package", "timestamp") body << "timestamp: #{value}" if value - repo = dig(content, 'package', 'repo') - body << "#{repo['type']}: #{repo['url']}" if repo + repo = dig(content, "package", "repo") + body << "#{repo["type"]}: #{repo["url"]}" if repo body = body.join("\n") else - type = 'application/json' + type = "application/json" body = content.to_json end - [ type, body ] + [type, body] end attr_reader :metadata - #:nocov: + # :nocov: def dig(hash, key, *rest) if hash.respond_to?(:dig) hash.dig(key, *rest) @@ -89,7 +89,7 @@ def dig(hash, key, *rest) end end - DIGGER = ->(h, k, *r) { #:nodoc: + DIGGER = ->(h, k, *r) { # :nodoc: v = h[k] if v.nil? || r.empty? v @@ -98,9 +98,9 @@ def dig(hash, key, *rest) end } private_constant :DIGGER - #:nocov: + # :nocov: end end -require_relative 'rack/simple' -require_relative 'rack/metadata' +require_relative "rack/simple" +require_relative "rack/metadata" diff --git a/lib/cartage/rack/metadata.rb b/lib/cartage/rack/metadata.rb index 61126bd..738fad9 100644 --- a/lib/cartage/rack/metadata.rb +++ b/lib/cartage/rack/metadata.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require 'pathname' -require 'json' +require "pathname" +require "json" ## # A representation for Cartage metadata for use with Cartage::Rack and # Cartage::Rack::Simple. class Cartage::Rack::Metadata - METADATA_CLEANER = ->(_, v) { #:nodoc: - v.delete_if(&METADATA_CLEANER) if v.kind_of?(Hash) + METADATA_CLEANER = ->(_, v) { # :nodoc: + v.delete_if(&METADATA_CLEANER) if v.is_a?(Hash) v.nil? || (v.respond_to?(:empty?) && v.empty?) } private_constant :METADATA_CLEANER @@ -31,7 +31,7 @@ def initialize(root_path = nil, required: Cartage::Rack.require_metadata, filter @filter = filter @content = read_release_metadata_json || read_release_hashref - fail 'Cannot find release-metadata.json or release_hashref' if required && !@content + fail "Cannot find release-metadata.json or release_hashref" if required && !@content @source ||= :live end @@ -41,11 +41,11 @@ def initialize(root_path = nil, required: Cartage::Rack.require_metadata, filter # content data. def resolve content.merge(application_env).tap do |data| - @filter.call(data) if @filter + @filter&.call(data) end.delete_if(&METADATA_CLEANER) end - def inspect #:nodoc: + def inspect # :nodoc: "#{@root_path.expand_path.basename} (#{@source})" end @@ -53,7 +53,7 @@ def inspect #:nodoc: def application_env @application_env ||= { - 'env' => { 'name' => ENV['RAILS_ENV'] || ENV['APP_ENV'] || ENV['RACK_ENV'] || 'UNKNOWN' } + "env" => {"name" => ENV["RAILS_ENV"] || ENV["APP_ENV"] || ENV["RACK_ENV"] || "UNKNOWN"} } end @@ -61,24 +61,24 @@ def content return @content if @content { - 'package' => {} + "package" => {} }.tap do |result| - package = result['package'] - package['name'] = @root_path.basename.to_s - package['hashref'] = release_hashref - package['timestamp'] = Time.now.utc.strftime('%Y%m%d%H%M%S') + package = result["package"] + package["name"] = @root_path.basename.to_s + package["hashref"] = release_hashref + package["timestamp"] = Time.now.utc.strftime("%Y%m%d%H%M%S") if repo? - package['repo'] = { - 'type' => 'git', # Hardcoded until we have other support - 'url' => repo_url + package["repo"] = { + "type" => "git", # Hardcoded until we have other support + "url" => repo_url } end end end def read_release_metadata_json - file = @root_path.join('release-metadata.json') + file = @root_path.join("release-metadata.json") return unless file.exist? @@ -87,7 +87,7 @@ def read_release_metadata_json end def read_release_hashref - file = @root_path.join('release_hashref') + file = @root_path.join("release_hashref") return unless file.exist? @@ -96,10 +96,10 @@ def read_release_hashref hashref, timestamp, = file.read.split($/) { - 'package' => { - 'name' => @root_path.basename.to_s, - 'hashref' => hashref, - 'timestamp' => timestamp + "package" => { + "name" => @root_path.basename.to_s, + "hashref" => hashref, + "timestamp" => timestamp } }.delete_if(&METADATA_CLEANER) end @@ -107,22 +107,22 @@ def read_release_hashref def repo_url return unless repo? unless defined?(@repo_url) - @repo_url = %x(git remote show -n origin). - match(/\n\s+Fetch URL: (?[^\n]+)/)[:fetch] + @repo_url = `git remote show -n origin` + .match(/\n\s+Fetch URL: (?[^\n]+)/)[:fetch] end @repo_url end def release_hashref if repo? - "(git) #{%x(git rev-parse --abbrev-ref HEAD).chomp}" + "(git) #{`git rev-parse --abbrev-ref HEAD`.chomp}" else - 'UNKNOWN - no .git directory' + "UNKNOWN - no .git directory" end end def repo? - @is_repo = @root_path.join('.git').directory? unless defined?(@is_repo) + @is_repo = @root_path.join(".git").directory? unless defined?(@is_repo) @is_repo end end diff --git a/lib/cartage/rack/simple.rb b/lib/cartage/rack/simple.rb index fd9ae5c..e8d90a9 100644 --- a/lib/cartage/rack/simple.rb +++ b/lib/cartage/rack/simple.rb @@ -6,9 +6,9 @@ class << self # Creates a new instance of the Cartage::Rack::Simple application to the # specified +root_path+, or +Dir.pwd+. This method has been deprecated. def mount(root_path = nil) - warn <<-warning -Cartage::Rack.mount(path) is deprecated; use Cartage::Rack::Simple(path) instead. - warning + warn <<~WARNING + Cartage::Rack.mount(path) is deprecated; use Cartage::Rack::Simple(path) instead. + WARNING Simple(root_path) end @@ -36,21 +36,21 @@ def resolve_content(env) content = {} - content[:env] = dig(full_content, 'env', 'name') - content[:release_hashref] = dig(full_content, 'package', 'hashref') - content[:timestamp] = dig(full_content, 'package', 'timestamp') + content[:env] = dig(full_content, "env", "name") + content[:release_hashref] = dig(full_content, "package", "hashref") + content[:timestamp] = dig(full_content, "package", "timestamp") - case env['PATH_INFO'] + case env["PATH_INFO"] when /\.json\z/ - type = 'application/json' + type = "application/json" body = content.to_json else - type = 'text/plain' + type = "text/plain" body = "#{content[:env]}: #{content[:release_hashref]}" body += " (#{content[:timestamp]})" if content[:timestamp] end - [ type, body ] + [type, body] end end end diff --git a/test/minitest_config.rb b/test/minitest_helper.rb similarity index 81% rename from test/minitest_config.rb rename to test/minitest_helper.rb index 837031b..043f72e 100644 --- a/test/minitest_config.rb +++ b/test/minitest_helper.rb @@ -1,18 +1,16 @@ # frozen_string_literal: true -gem 'minitest' -require 'rack/test' -require 'minitest/autorun' -require 'minitest/pretty_diff' -require 'minitest/focus' -require 'minitest/moar' -require 'minitest/bisect' -require 'minitest/hooks/default' -require 'timecop' +gem "minitest" + +require "minitest/autorun" +require "minitest/hooks/default" +require "minitest/moar" +require "rack/test" +require "timecop" Timecop.safe_mode = true -require 'cartage/rack' +require "cartage/rack" module Minitest::CartageRackStubs def stub_dir_pwd value, *block_args, &block @@ -24,8 +22,6 @@ def stub_env env, options = {}, *block_args, &block env.fetch(key) { |k| if options[:passthrough] ENV.send(:"__minitest_stub__[]", k) - else - nil end } } @@ -75,8 +71,3 @@ def stub_pathname_exist?(result) Minitest::Test.send(:include, self) end - -class << Minitest::Spec - alias context describe - private :context -end diff --git a/test/test_cartage_rack.rb b/test/test_cartage_rack.rb index 7088de0..7519c04 100644 --- a/test/test_cartage_rack.rb +++ b/test/test_cartage_rack.rb @@ -1,22 +1,22 @@ # frozen_string_literal: true -require 'minitest_config' +require "minitest_helper" describe Cartage::Rack do include Rack::Test::Methods let(:app) { Cartage::Rack(path) } - let(:path) { 'test/hillvalley' } + let(:path) { "test/hillvalley" } let(:metadata) { { - 'package' => { - 'name' => 'hillvalley', - 'repo' => { - 'type' => 'git', - 'url' => 'git:doc@hillvalley.com/delorean.git' + "package" => { + "name" => "hillvalley", + "repo" => { + "type" => "git", + "url" => "git:doc@hillvalley.com/delorean.git" }, - 'hashref' => 'd0cb1ff', - 'timestamp' => '19851027104200' + "hashref" => "d0cb1ff", + "timestamp" => "19851027104200" } } } @@ -31,160 +31,160 @@ def around(&block) end end - it 'inspects nicely for `rake routes` in Rails' do - assert_equal 'Cartage::Rack for hillvalley (release_metadata_json)', + it "inspects nicely for `rake routes` in Rails" do + assert_equal "Cartage::Rack for hillvalley (release_metadata_json)", Cartage::Rack().inspect end - it 'returns application/json content by default' do - get '/' - assert_equal 'application/json', last_response.header['Content-Type'] + it "returns application/json content by default" do + get "/" + assert_equal "application/json", last_response.headers["Content-Type"] end - it 'returns text/plain content when requested' do - get '/.txt' - assert_equal 'text/plain', last_response.header['Content-Type'] + it "returns text/plain content when requested" do + get "/.txt" + assert_equal "text/plain", last_response.headers["Content-Type"] end - context 'application environment' do - it 'uses $RAILS_ENV first' do - stub_env 'RAILS_ENV' => 'vne_sliar', - 'APP_ENV' => 'vne_ppa', - 'RACK_ENV' => 'vne_kcar' do - get '/' + describe "application environment" do + it "uses $RAILS_ENV first" do + stub_env "RAILS_ENV" => "vne_sliar", + "APP_ENV" => "vne_ppa", + "RACK_ENV" => "vne_kcar" do + get "/" - metadata['env'] = { 'name' => 'vne_sliar' } + metadata["env"] = {"name" => "vne_sliar"} assert last_response.ok? assert_equal metadata.to_json, last_response.body - assert_equal 'application/json', last_response.header['Content-Type'] + assert_equal "application/json", last_response.headers["Content-Type"] end end - it 'uses $APP_ENV second' do - stub_env 'RAILS_ENV' => nil, 'APP_ENV' => 'vne_ppa', 'RACK_ENV' => 'vne_kcar' do - get '/' + it "uses $APP_ENV second" do + stub_env "RAILS_ENV" => nil, "APP_ENV" => "vne_ppa", "RACK_ENV" => "vne_kcar" do + get "/" - metadata['env'] = { 'name' => 'vne_ppa' } + metadata["env"] = {"name" => "vne_ppa"} assert last_response.ok? assert_equal metadata.to_json, last_response.body - assert_equal 'application/json', last_response.header['Content-Type'] + assert_equal "application/json", last_response.headers["Content-Type"] end end - it 'uses $RACK_ENV third' do - stub_env 'RAILS_ENV' => nil, 'APP_ENV' => nil, 'RACK_ENV' => 'vne_kcar' do - get '/' + it "uses $RACK_ENV third" do + stub_env "RAILS_ENV" => nil, "APP_ENV" => nil, "RACK_ENV" => "vne_kcar" do + get "/" - metadata['env'] = { 'name' => 'vne_kcar' } + metadata["env"] = {"name" => "vne_kcar"} assert last_response.ok? assert_equal metadata.to_json, last_response.body - assert_equal 'application/json', last_response.header['Content-Type'] + assert_equal "application/json", last_response.headers["Content-Type"] end end - it 'falls through to UNKNOWN without either $RAILS_ENV, $APP_ENV or $RACK_ENV' do - stub_env 'RAILS_ENV' => nil, 'APP_ENV' => nil, 'RACK_ENV' => nil do - get '/' + it "falls through to UNKNOWN without either $RAILS_ENV, $APP_ENV or $RACK_ENV" do + stub_env "RAILS_ENV" => nil, "APP_ENV" => nil, "RACK_ENV" => nil do + get "/" - metadata['env'] = { 'name' => 'UNKNOWN' } + metadata["env"] = {"name" => "UNKNOWN"} assert last_response.ok? assert_equal metadata.to_json, last_response.body - assert_equal 'application/json', last_response.header['Content-Type'] + assert_equal "application/json", last_response.headers["Content-Type"] end end end - context 'timestamp' do + describe "timestamp" do around do |&block| - metadata['package'].delete('timestamp') + metadata["package"].delete("timestamp") super(&block) end - it 'is omitted if not present in the metadata' do - stub_env 'RAILS_ENV' => nil, 'RACK_ENV' => nil do - get '/' + it "is omitted if not present in the metadata" do + stub_env "RAILS_ENV" => nil, "RACK_ENV" => nil do + get "/" - metadata['env'] = { 'name' => 'UNKNOWN' } + metadata["env"] = {"name" => "UNKNOWN"} assert last_response.ok? assert_equal metadata.to_json, last_response.body - assert_equal 'application/json', last_response.header['Content-Type'] + assert_equal "application/json", last_response.headers["Content-Type"] end end end - context 'text/plain' do - it 'returns a useful plaintext format' do - stub_env 'RAILS_ENV' => 'production' do - get '/.text' + describe "text/plain" do + it "returns a useful plaintext format" do + stub_env "RAILS_ENV" => "production" do + get "/.text" assert last_response.ok? - assert_equal <<-text.chomp, last_response.body -name: hillvalley -environment: production -hashref: d0cb1ff -timestamp: 19851027104200 -git: git:doc@hillvalley.com/delorean.git - text - assert_equal 'text/plain', last_response.header['Content-Type'] + assert_equal <<~TEXT.chomp, last_response.body + name: hillvalley + environment: production + hashref: d0cb1ff + timestamp: 19851027104200 + git: git:doc@hillvalley.com/delorean.git + TEXT + assert_equal "text/plain", last_response.headers["Content-Type"] end end - it 'skips the repo if package.repo is missing' do - stub_env 'RAILS_ENV' => 'production' do - metadata['package'].delete('repo') + it "skips the repo if package.repo is missing" do + stub_env "RAILS_ENV" => "production" do + metadata["package"].delete("repo") - get '/.text' + get "/.text" assert last_response.ok? - assert_equal <<-text.chomp, last_response.body -name: hillvalley -environment: production -hashref: d0cb1ff -timestamp: 19851027104200 - text - assert_equal 'text/plain', last_response.header['Content-Type'] + assert_equal <<~TEXT.chomp, last_response.body + name: hillvalley + environment: production + hashref: d0cb1ff + timestamp: 19851027104200 + TEXT + assert_equal "text/plain", last_response.headers["Content-Type"] end end - it 'skips the timestamp if package.timestamp is missing' do - stub_env 'RAILS_ENV' => 'production' do - metadata['package'].delete('timestamp') + it "skips the timestamp if package.timestamp is missing" do + stub_env "RAILS_ENV" => "production" do + metadata["package"].delete("timestamp") - get '/.text' + get "/.text" assert last_response.ok? - assert_equal <<-text.chomp, last_response.body -name: hillvalley -environment: production -hashref: d0cb1ff -git: git:doc@hillvalley.com/delorean.git - text - assert_equal 'text/plain', last_response.header['Content-Type'] + assert_equal <<~TEXT.chomp, last_response.body + name: hillvalley + environment: production + hashref: d0cb1ff + git: git:doc@hillvalley.com/delorean.git + TEXT + assert_equal "text/plain", last_response.headers["Content-Type"] end end end - context 'filter' do + describe "filter" do let(:app) { Cartage::Rack(path) { |content| - content['env']['name'] = content['env']['name'].reverse + content["env"]["name"] = content["env"]["name"].reverse } } - it 'applies the filter before returning' do - stub_env 'RAILS_ENV' => 'vne_sliar' do - get '/' + it "applies the filter before returning" do + stub_env "RAILS_ENV" => "vne_sliar" do + get "/" - metadata['env'] = { 'name' => 'rails_env' } + metadata["env"] = {"name" => "rails_env"} assert last_response.ok? assert_equal metadata.to_json, last_response.body - assert_equal 'application/json', last_response.header['Content-Type'] + assert_equal "application/json", last_response.headers["Content-Type"] end end end diff --git a/test/test_cartage_rack_metadata.rb b/test/test_cartage_rack_metadata.rb index 3e162b9..3e433bb 100644 --- a/test/test_cartage_rack_metadata.rb +++ b/test/test_cartage_rack_metadata.rb @@ -1,31 +1,31 @@ # frozen_string_literal: true -require 'minitest_config' +require "minitest_helper" describe Cartage::Rack::Metadata do let(:described_class) { Cartage::Rack::Metadata } - let(:path) { 'test/hillvalley' } - let(:env) { { 'RAILS_ENV' => 'production' } } + let(:path) { "test/hillvalley" } + let(:env) { {"RAILS_ENV" => "production"} } - context 'with release-metadata.json' do + describe "with release-metadata.json" do let(:expected) { { - 'env' => { 'name' => 'production' }, - 'package' => { - 'name' => 'hillvalley', - 'repo' => { - 'type' => 'git', - 'url' => 'git:doc@hillvalley.com/delorean.git' + "env" => {"name" => "production"}, + "package" => { + "name" => "hillvalley", + "repo" => { + "type" => "git", + "url" => "git:doc@hillvalley.com/delorean.git" }, - 'hashref' => 'd0cb1ff', - 'timestamp' => '19851027104200' + "hashref" => "d0cb1ff", + "timestamp" => "19851027104200" } } } - it '#inspect uses the source (release_metadata_json) for inspection' do - stub_pathname_exist? ->(v) { v.basename.to_s == 'release-metadata.json' } do - instance_stub Pathname, :read, '{}' do + it "#inspect uses the source (release_metadata_json) for inspection" do + stub_pathname_exist? ->(v) { v.basename.to_s == "release-metadata.json" } do + instance_stub Pathname, :read, "{}" do assert_match( /\Ahillvalley \(release_metadata_json\)\z/, described_class.new(path, required: false).inspect @@ -34,9 +34,9 @@ end end - it '#resolve returns the content as provided' do + it "#resolve returns the content as provided" do stub_env(env) do - stub_pathname_exist? ->(v) { v.basename.to_s == 'release-metadata.json' } do + stub_pathname_exist? ->(v) { v.basename.to_s == "release-metadata.json" } do instance_stub Pathname, :read, expected.to_json do assert_equal expected, described_class.new(path).resolve end @@ -44,25 +44,25 @@ end end - it '#resolve returns filtered content' do + it "#resolve returns filtered content" do filter = ->(content) { - content['env']['capacitor'] = 'flux' + content["env"]["capacitor"] = "flux" } stub_env(env) do - stub_pathname_exist? ->(v) { v.basename.to_s == 'release-metadata.json' } do + stub_pathname_exist? ->(v) { v.basename.to_s == "release-metadata.json" } do instance_stub Pathname, :read, expected.to_json do - expected['env']['capacitor'] = 'flux' + expected["env"]["capacitor"] = "flux" assert_equal expected, described_class.new(path, filter: filter).resolve end end end end - it '.new throws an exception with a non-JSON file' do + it ".new throws an exception with a non-JSON file" do stub_env(env) do - stub_pathname_exist? ->(v) { v.basename.to_s == 'release-metadata.json' } do - instance_stub Pathname, :read, 'supercalafragalisticexpealadocious' do + stub_pathname_exist? ->(v) { v.basename.to_s == "release-metadata.json" } do + instance_stub Pathname, :read, "supercalafragalisticexpealadocious" do ex = assert_raises(JSON::ParserError) do described_class.new(path) end @@ -74,31 +74,31 @@ end end - context 'with release_hashref' do - let(:one_line) { 'd0cb1ff' } + describe "with release_hashref" do + let(:one_line) { "d0cb1ff" } let(:two_line) { "d0cb1ff\n19851027104200\n" } let(:two_line_empty) { "d0cb1ff\n\n" } let(:three_line) { "d0cb1ff\n19851027104200\nsomethingelse\n" } let(:expected_notimestamp) { { - 'env' => { - 'name' => 'production' + "env" => { + "name" => "production" }, - 'package' => { - 'name' => 'hillvalley', - 'hashref' => 'd0cb1ff' + "package" => { + "name" => "hillvalley", + "hashref" => "d0cb1ff" } } } let(:expected_timestamp) { expected_notimestamp.dup.tap do |en| - en['package'] = en['package'].merge('timestamp' => '19851027104200') + en["package"] = en["package"].merge("timestamp" => "19851027104200") end } - it 'uses the source (release_hashref) for inspection' do - stub_pathname_exist? ->(v) { v.basename.to_s == 'release_hashref' } do - instance_stub Pathname, :read, '' do + it "uses the source (release_hashref) for inspection" do + stub_pathname_exist? ->(v) { v.basename.to_s == "release_hashref" } do + instance_stub Pathname, :read, "" do assert_match( /\Ahillvalley \(release_hashref\)\z/, described_class.new(path, required: false).inspect @@ -107,10 +107,10 @@ end end - context '#resolve' do - it 'returns the hashref from a one line release_hashref' do + describe "#resolve" do + it "returns the hashref from a one line release_hashref" do stub_env(env) do - stub_pathname_exist? ->(v) { v.basename.to_s == 'release_hashref' } do + stub_pathname_exist? ->(v) { v.basename.to_s == "release_hashref" } do instance_stub Pathname, :read, one_line do assert_equal expected_notimestamp, described_class.new(path).resolve end @@ -118,9 +118,9 @@ end end - it 'returns hashref and timestamp from a two line release_hashref' do + it "returns hashref and timestamp from a two line release_hashref" do stub_env(env) do - stub_pathname_exist? ->(v) { v.basename.to_s == 'release_hashref' } do + stub_pathname_exist? ->(v) { v.basename.to_s == "release_hashref" } do instance_stub Pathname, :read, two_line do assert_equal expected_timestamp, described_class.new(path).resolve end @@ -128,9 +128,9 @@ end end - it 'returns hashref from a two line release_hashref (with empty timestamp line)' do + it "returns hashref from a two line release_hashref (with empty timestamp line)" do stub_env(env) do - stub_pathname_exist? ->(v) { v.basename.to_s == 'release_hashref' } do + stub_pathname_exist? ->(v) { v.basename.to_s == "release_hashref" } do instance_stub Pathname, :read, two_line_empty do assert_equal expected_notimestamp, described_class.new(path).resolve end @@ -138,9 +138,9 @@ end end - it 'ignores anything larger than two lines in release_hashref' do + it "ignores anything larger than two lines in release_hashref" do stub_env(env) do - stub_pathname_exist? ->(v) { v.basename.to_s == 'release_hashref' } do + stub_pathname_exist? ->(v) { v.basename.to_s == "release_hashref" } do instance_stub Pathname, :read, three_line do assert_equal expected_timestamp, described_class.new(path).resolve end @@ -150,8 +150,8 @@ end end - context 'with live data' do - it 'uses the source (live) for inspection' do + describe "with live data" do + it "uses the source (live) for inspection" do instance_stub Pathname, :exist?, false do assert_match( /\(live\)\z/, @@ -162,44 +162,44 @@ let(:expected_nogit) { { - 'env' => { - 'name' => 'production' + "env" => { + "name" => "production" }, - 'package' => { - 'name' => 'hillvalley', - 'hashref' => 'UNKNOWN - no .git directory', - 'timestamp' => '19851027104200' + "package" => { + "name" => "hillvalley", + "hashref" => "UNKNOWN - no .git directory", + "timestamp" => "19851027104200" } } } let(:expected_git) { expected_nogit.dup.tap { |en| - en['package'] = en['package'].merge( - 'repo' => { - 'type' => 'git', - 'url' => 'git:doc@hillvalley.com/delorean.git' + en["package"] = en["package"].merge( + "repo" => { + "type" => "git", + "url" => "git:doc@hillvalley.com/delorean.git" }, - 'hashref' => '(git) verne' + "hashref" => "(git) verne" ) } } - it 'fails if required is true' do + it "fails if required is true" do ex = assert_raises(RuntimeError) do described_class.new(path, required: true) end - assert_equal 'Cannot find release-metadata.json or release_hashref', ex.message + assert_equal "Cannot find release-metadata.json or release_hashref", ex.message end - context '#resolve' do + describe "#resolve" do around do |&block| - Timecop.freeze(Time.new(1985, 10, 27, 2, 42, 0, '-08:00')) do + Timecop.freeze(Time.new(1985, 10, 27, 2, 42, 0, "-08:00")) do super(&block) end end - it 'excludes package.repo when no .git directory' do + it "excludes package.repo when no .git directory" do stub_env(env) do instance_stub Pathname, :exist?, false do instance_stub Pathname, :directory?, false do @@ -210,13 +210,13 @@ end end - it 'includes package.repo when a .git directory exists' do + it "includes package.repo when a .git directory exists" do backticks = ->(v) { case v when /remote show/ "\n Fetch URL: git:doc@hillvalley.com/delorean.git" when /rev-parse/ - 'verne' + "verne" else __stub_backticks__(v) end diff --git a/test/test_cartage_rack_simple.rb b/test/test_cartage_rack_simple.rb index 83663a0..310958c 100644 --- a/test/test_cartage_rack_simple.rb +++ b/test/test_cartage_rack_simple.rb @@ -1,23 +1,23 @@ # frozen_string_literal: true -require 'minitest_config' +require "minitest_helper" describe Cartage::Rack::Simple do include Rack::Test::Methods let(:app) { Cartage::Rack::Simple(path) } - let(:path) { 'test/hillvalley' } + let(:path) { "test/hillvalley" } let(:metadata) { { - 'env' => { 'name' => 'production' }, - 'package' => { - 'name' => 'hillvalley', - 'repo' => { - 'type' => 'git', - 'url' => 'git:doc@hillvalley.com/delorean.git' + "env" => {"name" => "production"}, + "package" => { + "name" => "hillvalley", + "repo" => { + "type" => "git", + "url" => "git:doc@hillvalley.com/delorean.git" }, - 'hashref' => 'd0cb1ff', - 'timestamp' => '19851027104200' + "hashref" => "d0cb1ff", + "timestamp" => "19851027104200" } } } @@ -32,7 +32,7 @@ def around(&block) end end - it 'warns when Cartage::Rack.mount(path) is used' do + it "warns when Cartage::Rack.mount(path) is used" do $VERBOSE, verbose = false, $VERBOSE assert_output nil, /Cartage::Rack.mount\(path\) is deprecated/ do Cartage::Rack.mount @@ -40,78 +40,78 @@ def around(&block) end end - it 'inspects nicely for `rake routes` in Rails' do - assert_equal 'Cartage::Rack::Simple for hillvalley (release_metadata_json)', + it "inspects nicely for `rake routes` in Rails" do + assert_equal "Cartage::Rack::Simple for hillvalley (release_metadata_json)", Cartage::Rack::Simple().inspect end - it 'returns text/plain content by default' do - get '/' - assert_equal 'text/plain', last_response.header['Content-Type'] + it "returns text/plain content by default" do + get "/" + assert_equal "text/plain", last_response.headers["Content-Type"] end - it 'returns application/json content when requested' do - get '/.json' - assert_equal 'application/json', last_response.header['Content-Type'] + it "returns application/json content when requested" do + get "/.json" + assert_equal "application/json", last_response.headers["Content-Type"] end - context 'application environment' do - it 'uses $RAILS_ENV first' do - stub_env 'RAILS_ENV' => 'vne_sliar', - 'APP_ENV' => 'vne_ppa', - 'RACK_ENV' => 'vne_kcar' do - get '/' + describe "application environment" do + it "uses $RAILS_ENV first" do + stub_env "RAILS_ENV" => "vne_sliar", + "APP_ENV" => "vne_ppa", + "RACK_ENV" => "vne_kcar" do + get "/" assert last_response.ok? - assert_equal 'vne_sliar: d0cb1ff (19851027104200)', last_response.body - assert_equal 'text/plain', last_response.header['Content-Type'] + assert_equal "vne_sliar: d0cb1ff (19851027104200)", last_response.body + assert_equal "text/plain", last_response.headers["Content-Type"] end end - it 'uses $APP_ENV second' do - stub_env 'RAILS_ENV' => nil, 'APP_ENV' => 'vne_ppa', 'RACK_ENV' => 'vne_kcar' do - get '/' + it "uses $APP_ENV second" do + stub_env "RAILS_ENV" => nil, "APP_ENV" => "vne_ppa", "RACK_ENV" => "vne_kcar" do + get "/" assert last_response.ok? - assert_equal 'vne_ppa: d0cb1ff (19851027104200)', last_response.body - assert_equal 'text/plain', last_response.header['Content-Type'] + assert_equal "vne_ppa: d0cb1ff (19851027104200)", last_response.body + assert_equal "text/plain", last_response.headers["Content-Type"] end end - it 'uses $RACK_ENV third' do - stub_env 'RAILS_ENV' => nil, 'APP_ENV' => nil, 'RACK_ENV' => 'vne_kcar' do - get '/' + it "uses $RACK_ENV third" do + stub_env "RAILS_ENV" => nil, "APP_ENV" => nil, "RACK_ENV" => "vne_kcar" do + get "/" assert last_response.ok? - assert_equal 'vne_kcar: d0cb1ff (19851027104200)', last_response.body - assert_equal 'text/plain', last_response.header['Content-Type'] + assert_equal "vne_kcar: d0cb1ff (19851027104200)", last_response.body + assert_equal "text/plain", last_response.headers["Content-Type"] end end - it 'falls through to UNKNOWN without either $RAILS_ENV, $APP_ENV or $RACK_ENV' do - stub_env 'RAILS_ENV' => nil, 'APP_ENV' => nil, 'RACK_ENV' => nil do - get '/' + it "falls through to UNKNOWN without either $RAILS_ENV, $APP_ENV or $RACK_ENV" do + stub_env "RAILS_ENV" => nil, "APP_ENV" => nil, "RACK_ENV" => nil do + get "/" assert last_response.ok? - assert_equal 'UNKNOWN: d0cb1ff (19851027104200)', last_response.body - assert_equal 'text/plain', last_response.header['Content-Type'] + assert_equal "UNKNOWN: d0cb1ff (19851027104200)", last_response.body + assert_equal "text/plain", last_response.headers["Content-Type"] end end end - context 'timestamp' do + describe "timestamp" do around do |&block| - metadata['package'].delete('timestamp') + metadata["package"].delete("timestamp") super(&block) end - it 'is omitted if not present in the metadata' do - stub_env 'RAILS_ENV' => nil, 'RACK_ENV' => nil do - get '/' + it "is omitted if not present in the metadata" do + stub_env "RAILS_ENV" => nil, "RACK_ENV" => nil do + get "/" assert last_response.ok? - assert_equal 'UNKNOWN: d0cb1ff', last_response.body - assert_equal 'text/plain', last_response.header['Content-Type'] + assert_equal "UNKNOWN: d0cb1ff", last_response.body + assert_equal "text/plain", last_response.headers["Content-Type"] end end end