From ccfb3f310fd7e3efb86c0ea29f00a010b3f1e482 Mon Sep 17 00:00:00 2001 From: Nicolas Rodriguez Date: Mon, 4 Nov 2024 15:58:37 +0100 Subject: [PATCH] Housekeeping (#437) Housekeeping This includes : * Remove useless file * Move development dependencies to Gemfile * Switch from CircleCI to GithubActions * use Appraisal to specify Rails version during CI * Add support for latest Rails versions * Add support for latest Ruby versions * Disable RSpec monkey patch * Run tests in random order * Cleanup spec_helper.rb * Load parent Gemfile in integration tests * Cleanup spec_helper.rb in integration tests * Improve RSpec config in integration tests * Coding style * Improve DB loading/seeding in integration tests * Add bin/rackup binstub so we can start dummy application * Add simplecov to have code coverage --- .circleci/config.yml | 88 ---------- .github/workflows/ci.yml | 165 ++++++++++++++++++ .gitignore | 1 + .ruby-version | 1 - Appraisals | 25 +++ Gemfile | 18 ++ bin/appraisal | 27 +++ bin/bundle | 109 ++++++++++++ bin/rspec | 27 +++ gemfiles/rails_5.2.gemfile | 25 +++ gemfiles/rails_6.0.gemfile | 25 +++ gemfiles/rails_6.1.gemfile | 25 +++ gemfiles/rails_7.0.gemfile | 25 +++ gemfiles/rails_7.1.gemfile | 25 +++ gemfiles/rails_7.2.gemfile | 25 +++ integration/Gemfile | 18 +- integration/bin/bundle | 109 ++++++++++++ integration/bin/rackup | 27 +++ integration/bin/rspec | 27 +++ integration/gemfiles/rails_5_2.gemfile | 15 -- integration/gemfiles/rails_6_0.gemfile | 15 -- integration/gemfiles/rails_6_1.gemfile | 15 -- integration/gemfiles/rails_7_0.gemfile | 11 -- integration/spec/files/sitemap.create.rb | 3 - .../app/controllers/application_controller.rb | 3 + .../app/controllers/contents_controller.rb | 5 + integration/spec/internal/config/sitemap.rb | 3 - integration/spec/internal/db/schema.rb | 12 +- .../alternate_sitemap_spec.rb | 2 +- .../spec/sitemap_generator/tasks_spec.rb | 2 +- integration/spec/spec_helper.rb | 39 ++++- sitemap_generator.gemspec | 9 - .../adapters/aws_sdk_adapter_spec.rb | 2 +- .../adapters/file_adapter_spec.rb | 2 +- .../adapters/fog_adapter_spec.rb | 2 +- .../adapters/google_storage_adapter_spec.rb | 2 +- .../adapters/s3_adapter_spec.rb | 2 +- .../adapters/wave_adapter_spec.rb | 2 +- spec/sitemap_generator/application_spec.rb | 2 +- .../builder/sitemap_file_spec.rb | 2 +- .../builder/sitemap_index_file_spec.rb | 2 +- .../builder/sitemap_index_url_spec.rb | 2 +- .../builder/sitemap_url_spec.rb | 2 +- .../core_ext/bigdecimal_spec.rb | 2 +- .../core_ext/numeric_spec.rb | 2 +- .../helpers/number_helper_spec.rb | 2 +- spec/sitemap_generator/interpreter_spec.rb | 2 +- spec/sitemap_generator/link_set_spec.rb | 2 +- .../sitemap_generator_spec.rb | 2 +- spec/sitemap_generator/sitemap_groups_spec.rb | 2 +- .../sitemap_location_spec.rb | 4 +- spec/sitemap_generator/sitemap_namer_spec.rb | 2 +- .../sitemaps/alternate_sitemap_spec.rb | 2 +- .../sitemaps/mobile_sitemap_spec.rb | 2 +- .../sitemaps/news_sitemap_spec.rb | 2 +- .../sitemaps/pagemap_sitemap_spec.rb | 2 +- .../sitemaps/video_sitemap_spec.rb | 2 +- spec/sitemap_generator/templates_spec.rb | 2 +- .../utilities/existence_spec.rb | 2 +- spec/sitemap_generator/utilities/hash_spec.rb | 2 +- .../utilities/rounding_spec.rb | 2 +- spec/sitemap_generator/utilities_spec.rb | 2 +- spec/spec_helper.rb | 40 +++-- 63 files changed, 796 insertions(+), 232 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .ruby-version create mode 100644 Appraisals create mode 100755 bin/appraisal create mode 100755 bin/bundle create mode 100755 bin/rspec create mode 100644 gemfiles/rails_5.2.gemfile create mode 100644 gemfiles/rails_6.0.gemfile create mode 100644 gemfiles/rails_6.1.gemfile create mode 100644 gemfiles/rails_7.0.gemfile create mode 100644 gemfiles/rails_7.1.gemfile create mode 100644 gemfiles/rails_7.2.gemfile create mode 100755 integration/bin/bundle create mode 100755 integration/bin/rackup create mode 100755 integration/bin/rspec delete mode 100644 integration/gemfiles/rails_5_2.gemfile delete mode 100644 integration/gemfiles/rails_6_0.gemfile delete mode 100644 integration/gemfiles/rails_6_1.gemfile delete mode 100644 integration/gemfiles/rails_7_0.gemfile create mode 100644 integration/spec/internal/app/controllers/application_controller.rb create mode 100644 integration/spec/internal/app/controllers/contents_controller.rb diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 1a50f90b..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,88 +0,0 @@ -version: 2.1 - -jobs: - gem-test: - parameters: - ruby-version: - type: string - docker: - # See https://github.com/CircleCI-Public/cimg-ruby - - image: cimg/ruby:<< parameters.ruby-version >> - steps: - - checkout - - run: - name: Install dependencies - command: | - bundle install --path vendor/bundle --jobs=2 - - run: - name: Run tests - command: | - bundle exec rspec --profile 10 --format RspecJunitFormatter --out ./test-results/rspec/results.xml --format progress - - store_test_results: - path: test-results - - integration-test: - parameters: - ruby-version: - type: string - rails-version: - type: string - docker: - # See https://github.com/CircleCI-Public/cimg-ruby - - image: cimg/ruby:<< parameters.ruby-version >> - working_directory: ~/sitemap_generator/integration - steps: - - checkout: - path: ~/sitemap_generator - - run: - name: Install sqlite3 when on Ruby 2.5 - command: | - if [[ "$RUBY_VERSION" =~ 2\.5 ]]; then - sudo apt-get update && sudo apt-get install -y sqlite3 libsqlite3-dev - fi - - run: - name: Install Rails dependencies - environment: - BUNDLE_GEMFILE: "./gemfiles/rails_<< parameters.rails-version >>.gemfile" - command: | - bundle config set --local path 'vendor/bundle' - bundle install --jobs=2 - - run: - name: Run integration tests - environment: - BUNDLE_GEMFILE: "./gemfiles/rails_<< parameters.rails-version >>.gemfile" - command: | - bundle exec rspec --profile 10 --format RspecJunitFormatter --out ./test-results/rspec/results.xml --format progress - - store_test_results: - path: test-results - -workflows: - test: - jobs: - - gem-test: - # See https://circleci.com/blog/circleci-matrix-jobs/ - matrix: - parameters: - ruby-version: ["3.1", "3.0", "2.7", "2.5"] - name: gem-test-ruby-<< matrix.ruby-version >> - - integration-test: - # See https://circleci.com/blog/circleci-matrix-jobs/ - # See https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html for Ruby and Rails compatibility - matrix: - parameters: - ruby-version: ["3.1", "3.0", "2.7", "2.5"] - rails-version: ["5_2", "6_0", "6_1", "7_0"] - exclude: - - ruby-version: "2.5" - rails-version: "7_0" - - ruby-version: "2.7" - rails-version: "5_2" - - ruby-version: "3.0" - rails-version: "5_2" - - ruby-version: "3.0" - rails-version: "6_0" - - ruby-version: "3.1" - rails-version: "5_2" - - ruby-version: "3.1" - rails-version: "6_0" - name: integration-test-ruby-<< matrix.ruby-version >>-rails-<< matrix.rails-version >> diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..ec62b2d6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,165 @@ +--- +name: CI + +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + schedule: + - cron: '0 4 1 * *' + +jobs: + rspec: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + ruby: + - '3.3' + - '3.2' + - '3.1' + - '3.0' + - '2.7' + - '2.6' + - '2.5' + rails: + - rails_7.2 + - rails_7.1 + - rails_7.0 + - rails_6.1 + - rails_6.0 + - rails_5.2 + + exclude: + - ruby: '2.5' + rails: 'rails_7.0' + - ruby: '2.5' + rails: 'rails_7.1' + - ruby: '2.5' + rails: 'rails_7.2' + + - ruby: '2.6' + rails: 'rails_7.0' + - ruby: '2.6' + rails: 'rails_7.1' + - ruby: '2.6' + rails: 'rails_7.2' + + - ruby: '2.7' + rails: 'rails_5.2' + - ruby: '2.7' + rails: 'rails_7.2' + + - ruby: '3.0' + rails: 'rails_5.2' + - ruby: '3.0' + rails: 'rails_6.0' + - ruby: '3.0' + rails: 'rails_7.2' + + - ruby: '3.1' + rails: 'rails_5.2' + + - ruby: '3.2' + rails: 'rails_5.2' + + - ruby: '3.3' + rails: 'rails_5.2' + + env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.rails }}.gemfile + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + + - name: RSpec + run: 'echo "current_directory: ${PWD}" && bin/rspec --profile 10 --format RspecJunitFormatter --out ./test-results/rspec/results.xml --format progress' + + rspec-integration: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: ${{ github.workspace }}/integration + + strategy: + fail-fast: false + matrix: + ruby: + - '3.3' + - '3.2' + - '3.1' + - '3.0' + - '2.7' + - '2.6' + - '2.5' + rails: + - rails_7.2 + - rails_7.1 + - rails_7.0 + - rails_6.1 + - rails_6.0 + - rails_5.2 + + exclude: + - ruby: '2.5' + rails: 'rails_7.0' + - ruby: '2.5' + rails: 'rails_7.1' + - ruby: '2.5' + rails: 'rails_7.2' + + - ruby: '2.6' + rails: 'rails_7.0' + - ruby: '2.6' + rails: 'rails_7.1' + - ruby: '2.6' + rails: 'rails_7.2' + + - ruby: '2.7' + rails: 'rails_5.2' + - ruby: '2.7' + rails: 'rails_7.2' + + - ruby: '3.0' + rails: 'rails_5.2' + - ruby: '3.0' + rails: 'rails_6.0' + - ruby: '3.0' + rails: 'rails_7.2' + + - ruby: '3.1' + rails: 'rails_5.2' + + - ruby: '3.2' + rails: 'rails_5.2' + + - ruby: '3.3' + rails: 'rails_5.2' + + env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.rails }}.gemfile + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + + - name: RSpec + run: 'echo "current_directory: ${PWD}" && bin/rspec --profile 10 --format RspecJunitFormatter --out ./test-results/rspec/results.xml --format progress' diff --git a/.gitignore b/.gitignore index b132b6fc..1ef18e57 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ public Gemfile.lock integration/Gemfile.lock integration/gemfiles/*.lock +gemfiles/*.lock diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index fd2a0186..00000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -3.1.0 diff --git a/Appraisals b/Appraisals new file mode 100644 index 00000000..2e48d1cf --- /dev/null +++ b/Appraisals @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +appraise 'rails_5.2' do + gem 'rails', '~> 5.2.0' +end + +appraise 'rails_6.0' do + gem 'rails', '~> 6.0.0' +end + +appraise 'rails_6.1' do + gem 'rails', '~> 6.1.0' +end + +appraise 'rails_7.0' do + gem 'rails', '~> 7.0.0' +end + +appraise 'rails_7.1' do + gem 'rails', '~> 7.1.0' +end + +appraise 'rails_7.2' do + gem 'rails', '~> 7.2.0' +end diff --git a/Gemfile b/Gemfile index f75b96a5..2493a684 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,26 @@ source 'https://rubygems.org' gemspec +gem 'appraisal', git: 'https://github.com/thoughtbot/appraisal.git' + +gem 'aws-sdk-core' +gem 'aws-sdk-s3' +gem 'combustion' +gem 'fog-aws' +gem 'google-cloud-storage' +gem 'rails' +gem 'rake' +gem 'rspec_junit_formatter' +gem 'rspec' +gem 'rspec-rails' +gem 'simplecov' +gem 'sqlite3', '~> 1.5.0' +gem 'webmock' + if RUBY_VERSION =~ /2.5.*/ gem 'nokogiri', '1.12.5' +else + gem 'nokogiri' end group :test do diff --git a/bin/appraisal b/bin/appraisal new file mode 100755 index 00000000..5038ce52 --- /dev/null +++ b/bin/appraisal @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'appraisal' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("appraisal", "appraisal") diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 00000000..50da5fdf --- /dev/null +++ b/bin/bundle @@ -0,0 +1,109 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'bundle' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "rubygems" + +m = Module.new do + module_function + + def invoked_as_script? + File.expand_path($0) == File.expand_path(__FILE__) + end + + def env_var_version + ENV["BUNDLER_VERSION"] + end + + def cli_arg_version + return unless invoked_as_script? # don't want to hijack other binstubs + return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN) + bundler_version = a + end + next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 + update_index = i + end + bundler_version + end + + def gemfile + gemfile = ENV["BUNDLE_GEMFILE"] + return gemfile if gemfile && !gemfile.empty? + + File.expand_path("../Gemfile", __dir__) + end + + def lockfile + lockfile = + case File.basename(gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") + else "#{gemfile}.lock" + end + File.expand_path(lockfile) + end + + def lockfile_version + return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) + return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) + end + + def bundler_requirement + @bundler_requirement ||= + env_var_version || + cli_arg_version || + bundler_requirement_for(lockfile_version) + end + + def bundler_requirement_for(version) + return "#{Gem::Requirement.default}.a" unless version + + bundler_gem_version = Gem::Version.new(version) + + bundler_gem_version.approximate_recommendation + end + + def load_bundler! + ENV["BUNDLE_GEMFILE"] ||= gemfile + + activate_bundler + end + + def activate_bundler + gem_error = activation_error_handling do + gem "bundler", bundler_requirement + end + return if gem_error.nil? + require_error = activation_error_handling do + require "bundler/version" + end + return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" + exit 42 + end + + def activation_error_handling + yield + nil + rescue StandardError, LoadError => e + e + end +end + +m.load_bundler! + +if m.invoked_as_script? + load Gem.bin_path("bundler", "bundle") +end diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 00000000..cb53ebe5 --- /dev/null +++ b/bin/rspec @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rspec-core", "rspec") diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile new file mode 100644 index 00000000..883cdbb9 --- /dev/null +++ b/gemfiles/rails_5.2.gemfile @@ -0,0 +1,25 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "aws-sdk-core" +gem "aws-sdk-s3" +gem "combustion" +gem "fog-aws" +gem "google-cloud-storage" +gem "rails", "~> 5.2.0" +gem "rake" +gem "rspec_junit_formatter" +gem "rspec" +gem "rspec-rails" +gem "simplecov" +gem "sqlite3", "~> 1.5.0" +gem "webmock" +gem "nokogiri" + +group :test do + gem "byebug" +end + +gemspec path: "../" diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile new file mode 100644 index 00000000..132b544d --- /dev/null +++ b/gemfiles/rails_6.0.gemfile @@ -0,0 +1,25 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "aws-sdk-core" +gem "aws-sdk-s3" +gem "combustion" +gem "fog-aws" +gem "google-cloud-storage" +gem "rails", "~> 6.0.0" +gem "rake" +gem "rspec_junit_formatter" +gem "rspec" +gem "rspec-rails" +gem "simplecov" +gem "sqlite3", "~> 1.5.0" +gem "webmock" +gem "nokogiri" + +group :test do + gem "byebug" +end + +gemspec path: "../" diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile new file mode 100644 index 00000000..75634caa --- /dev/null +++ b/gemfiles/rails_6.1.gemfile @@ -0,0 +1,25 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "aws-sdk-core" +gem "aws-sdk-s3" +gem "combustion" +gem "fog-aws" +gem "google-cloud-storage" +gem "rails", "~> 6.1.0" +gem "rake" +gem "rspec_junit_formatter" +gem "rspec" +gem "rspec-rails" +gem "simplecov" +gem "sqlite3", "~> 1.5.0" +gem "webmock" +gem "nokogiri" + +group :test do + gem "byebug" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile new file mode 100644 index 00000000..91039152 --- /dev/null +++ b/gemfiles/rails_7.0.gemfile @@ -0,0 +1,25 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "aws-sdk-core" +gem "aws-sdk-s3" +gem "combustion" +gem "fog-aws" +gem "google-cloud-storage" +gem "rails", "~> 7.0.0" +gem "rake" +gem "rspec_junit_formatter" +gem "rspec" +gem "rspec-rails" +gem "simplecov" +gem "sqlite3", "~> 1.5.0" +gem "webmock" +gem "nokogiri" + +group :test do + gem "byebug" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile new file mode 100644 index 00000000..085f4470 --- /dev/null +++ b/gemfiles/rails_7.1.gemfile @@ -0,0 +1,25 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "aws-sdk-core" +gem "aws-sdk-s3" +gem "combustion" +gem "fog-aws" +gem "google-cloud-storage" +gem "rails", "~> 7.1.0" +gem "rake" +gem "rspec_junit_formatter" +gem "rspec" +gem "rspec-rails" +gem "simplecov" +gem "sqlite3", "~> 1.5.0" +gem "webmock" +gem "nokogiri" + +group :test do + gem "byebug" +end + +gemspec path: "../" diff --git a/gemfiles/rails_7.2.gemfile b/gemfiles/rails_7.2.gemfile new file mode 100644 index 00000000..c2fdff33 --- /dev/null +++ b/gemfiles/rails_7.2.gemfile @@ -0,0 +1,25 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git" +gem "aws-sdk-core" +gem "aws-sdk-s3" +gem "combustion" +gem "fog-aws" +gem "google-cloud-storage" +gem "rails", "~> 7.2.0" +gem "rake" +gem "rspec_junit_formatter" +gem "rspec" +gem "rspec-rails" +gem "simplecov" +gem "sqlite3", "~> 1.5.0" +gem "webmock" +gem "nokogiri" + +group :test do + gem "byebug" +end + +gemspec path: "../" diff --git a/integration/Gemfile b/integration/Gemfile index fb99bcc6..0d03694f 100644 --- a/integration/Gemfile +++ b/integration/Gemfile @@ -1,16 +1,2 @@ -# Default Gemfile for running tests in development. -source 'https://rubygems.org' - -ruby ">= 2.5.0" - -if RUBY_VERSION =~ /2.5.*/ - gem 'nokogiri', '1.12.5' -else - gem "nokogiri" -end -gem "rspec_junit_formatter" -gem "sitemap_generator", path: "../../" -gem "sqlite3" -gem "combustion" -gem "rails", "~> 6.1" -gem "rspec-rails" +instance_eval File.read(File.expand_path('../Gemfile', __dir__)).split("\n").delete_if {|x| x == 'gemspec' }.join("\n") +gemspec path: File.expand_path('../', __dir__) diff --git a/integration/bin/bundle b/integration/bin/bundle new file mode 100755 index 00000000..50da5fdf --- /dev/null +++ b/integration/bin/bundle @@ -0,0 +1,109 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'bundle' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "rubygems" + +m = Module.new do + module_function + + def invoked_as_script? + File.expand_path($0) == File.expand_path(__FILE__) + end + + def env_var_version + ENV["BUNDLER_VERSION"] + end + + def cli_arg_version + return unless invoked_as_script? # don't want to hijack other binstubs + return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN) + bundler_version = a + end + next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 + update_index = i + end + bundler_version + end + + def gemfile + gemfile = ENV["BUNDLE_GEMFILE"] + return gemfile if gemfile && !gemfile.empty? + + File.expand_path("../Gemfile", __dir__) + end + + def lockfile + lockfile = + case File.basename(gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, ".locked") + else "#{gemfile}.lock" + end + File.expand_path(lockfile) + end + + def lockfile_version + return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) + return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) + end + + def bundler_requirement + @bundler_requirement ||= + env_var_version || + cli_arg_version || + bundler_requirement_for(lockfile_version) + end + + def bundler_requirement_for(version) + return "#{Gem::Requirement.default}.a" unless version + + bundler_gem_version = Gem::Version.new(version) + + bundler_gem_version.approximate_recommendation + end + + def load_bundler! + ENV["BUNDLE_GEMFILE"] ||= gemfile + + activate_bundler + end + + def activate_bundler + gem_error = activation_error_handling do + gem "bundler", bundler_requirement + end + return if gem_error.nil? + require_error = activation_error_handling do + require "bundler/version" + end + return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" + exit 42 + end + + def activation_error_handling + yield + nil + rescue StandardError, LoadError => e + e + end +end + +m.load_bundler! + +if m.invoked_as_script? + load Gem.bin_path("bundler", "bundle") +end diff --git a/integration/bin/rackup b/integration/bin/rackup new file mode 100755 index 00000000..6408c791 --- /dev/null +++ b/integration/bin/rackup @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rackup' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rackup", "rackup") diff --git a/integration/bin/rspec b/integration/bin/rspec new file mode 100755 index 00000000..cb53ebe5 --- /dev/null +++ b/integration/bin/rspec @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rspec-core", "rspec") diff --git a/integration/gemfiles/rails_5_2.gemfile b/integration/gemfiles/rails_5_2.gemfile deleted file mode 100644 index 1040b175..00000000 --- a/integration/gemfiles/rails_5_2.gemfile +++ /dev/null @@ -1,15 +0,0 @@ -source "https://rubygems.org" - -ruby "< 2.7.0" - -if RUBY_VERSION =~ /2.5.*/ - gem 'nokogiri', '1.12.5' -else - gem "nokogiri" -end -gem "rspec_junit_formatter" -gem "sitemap_generator", path: "../../../" -gem "sqlite3" -gem "combustion" -gem "rails", "~> 5.2" -gem "rspec-rails" diff --git a/integration/gemfiles/rails_6_0.gemfile b/integration/gemfiles/rails_6_0.gemfile deleted file mode 100644 index be366c65..00000000 --- a/integration/gemfiles/rails_6_0.gemfile +++ /dev/null @@ -1,15 +0,0 @@ -source "https://rubygems.org" - -ruby "< 3.0.0" - -if RUBY_VERSION =~ /2.5.*/ - gem 'nokogiri', '1.12.5' -else - gem "nokogiri" -end -gem "rspec_junit_formatter" -gem "sitemap_generator", path: "../../../" -gem "sqlite3" -gem "combustion" -gem "rails", "~> 6.0" -gem "rspec-rails" diff --git a/integration/gemfiles/rails_6_1.gemfile b/integration/gemfiles/rails_6_1.gemfile deleted file mode 100644 index c30e90c7..00000000 --- a/integration/gemfiles/rails_6_1.gemfile +++ /dev/null @@ -1,15 +0,0 @@ -source "https://rubygems.org" - -ruby ">= 2.5.0" - -if RUBY_VERSION =~ /2.5.*/ - gem 'nokogiri', '1.12.5' -else - gem "nokogiri" -end -gem "rspec_junit_formatter" -gem "sitemap_generator", path: "../../../" -gem "sqlite3" -gem "combustion" -gem "rails", "~> 6.1" -gem "rspec-rails" diff --git a/integration/gemfiles/rails_7_0.gemfile b/integration/gemfiles/rails_7_0.gemfile deleted file mode 100644 index 3822d5e1..00000000 --- a/integration/gemfiles/rails_7_0.gemfile +++ /dev/null @@ -1,11 +0,0 @@ -source "https://rubygems.org" - -ruby ">= 2.7.0" - -gem "nokogiri" -gem "rspec_junit_formatter" -gem "sitemap_generator", path: "../../../" -gem "sqlite3" -gem "combustion" -gem "rails", "~> 7.0" -gem "rspec-rails" diff --git a/integration/spec/files/sitemap.create.rb b/integration/spec/files/sitemap.create.rb index ec7464b4..ff5d2344 100644 --- a/integration/spec/files/sitemap.create.rb +++ b/integration/spec/files/sitemap.create.rb @@ -1,6 +1,3 @@ -require File.expand_path('./spec/internal/db/schema.rb') -require File.expand_path('./spec/internal/db/seed.rb') - SitemapGenerator::Sitemap.default_host = "http://www.example.com" SitemapGenerator::Sitemap.create do diff --git a/integration/spec/internal/app/controllers/application_controller.rb b/integration/spec/internal/app/controllers/application_controller.rb new file mode 100644 index 00000000..e8065d95 --- /dev/null +++ b/integration/spec/internal/app/controllers/application_controller.rb @@ -0,0 +1,3 @@ +class ApplicationController < ActionController::Base + protect_from_forgery +end diff --git a/integration/spec/internal/app/controllers/contents_controller.rb b/integration/spec/internal/app/controllers/contents_controller.rb new file mode 100644 index 00000000..ad2f1801 --- /dev/null +++ b/integration/spec/internal/app/controllers/contents_controller.rb @@ -0,0 +1,5 @@ +class ContentsController < ApplicationController + def index + render plain: 'ok' + end +end diff --git a/integration/spec/internal/config/sitemap.rb b/integration/spec/internal/config/sitemap.rb index ec7464b4..ff5d2344 100644 --- a/integration/spec/internal/config/sitemap.rb +++ b/integration/spec/internal/config/sitemap.rb @@ -1,6 +1,3 @@ -require File.expand_path('./spec/internal/db/schema.rb') -require File.expand_path('./spec/internal/db/seed.rb') - SitemapGenerator::Sitemap.default_host = "http://www.example.com" SitemapGenerator::Sitemap.create do diff --git a/integration/spec/internal/db/schema.rb b/integration/spec/internal/db/schema.rb index c4b21cec..c16f2b60 100644 --- a/integration/spec/internal/db/schema.rb +++ b/integration/spec/internal/db/schema.rb @@ -1,7 +1,7 @@ - ActiveRecord::Schema.define(:version => 1) do - create_table "contents", force: true do |t| - t.string "title" - t.datetime "created_at" - t.datetime "updated_at" - end +ActiveRecord::Schema.define(:version => 1) do + create_table "contents", force: true do |t| + t.string "title" + t.datetime "created_at" + t.datetime "updated_at" end +end diff --git a/integration/spec/sitemap_generator/alternate_sitemap_spec.rb b/integration/spec/sitemap_generator/alternate_sitemap_spec.rb index f024f3a2..80ea888d 100644 --- a/integration/spec/sitemap_generator/alternate_sitemap_spec.rb +++ b/integration/spec/sitemap_generator/alternate_sitemap_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe "SitemapGenerator" do +RSpec.describe "SitemapGenerator" do it "should not include media element unless provided" do xml_fragment = SitemapGenerator::Builder::SitemapUrl.new('link_with_alternates.html', :host => 'http://www.example.com', diff --git a/integration/spec/sitemap_generator/tasks_spec.rb b/integration/spec/sitemap_generator/tasks_spec.rb index d833d347..003faec6 100644 --- a/integration/spec/sitemap_generator/tasks_spec.rb +++ b/integration/spec/sitemap_generator/tasks_spec.rb @@ -6,7 +6,7 @@ class << self end end -describe "SitemapGenerator" do +RSpec.describe "SitemapGenerator" do describe "reset!" do before :each do SitemapGenerator::Sitemap.default_host # Force initialization of the LinkSet diff --git a/integration/spec/spec_helper.rb b/integration/spec/spec_helper.rb index 0e3b4196..4d0136f9 100644 --- a/integration/spec/spec_helper.rb +++ b/integration/spec/spec_helper.rb @@ -1,21 +1,40 @@ -require 'bundler/setup' -Bundler.require +# Load combustion gem +require 'combustion' + # Setting load_schema: false results in "uninitialized constant ActiveRecord::MigrationContext" error Combustion.initialize! :active_record, :action_view, database_reset: false Combustion::Application.load_tasks -require 'sitemap_generator/tasks' # Combusition fails to load these tasks -SitemapGenerator.verbose = false +# Load rspec gem require 'rspec/rails' -require 'support/sitemap_macros' -require '../spec/support/file_macros' -require '../spec/support/xml_macros' +# Load support files +require_relative 'support/sitemap_macros' +require_relative '../../spec/support/file_macros' +require_relative '../../spec/support/xml_macros' + +# Configure rspec RSpec.configure do |config| config.include(FileMacros) config.include(XmlMacros) config.include(SitemapMacros) + # Use DB agnostic schema by default + load Rails.root.join('db', 'schema.rb').to_s + load Rails.root.join('db', 'seed.rb').to_s + + # run tests in random order + config.order = :random + Kernel.srand config.seed + + config.expect_with :rspec do |c| + c.syntax = :expect + end + + # disable monkey patching + # see: https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + config.disable_monkey_patching! + config.after(:all) do clean_sitemap_files_from_rails_app copy_sitemap_file_to_rails_app(:create) @@ -35,3 +54,9 @@ def invoke_task(task) Rake::Task[task.to_s].reenable end end + +puts "Running RSpec with Rails version: #{Rails.version}" + +# Load our own gem +require 'sitemap_generator/tasks' # Combusition fails to load these tasks +SitemapGenerator.verbose = false diff --git a/sitemap_generator.gemspec b/sitemap_generator.gemspec index edf1b5ed..1f62e48c 100644 --- a/sitemap_generator.gemspec +++ b/sitemap_generator.gemspec @@ -11,14 +11,5 @@ Gem::Specification.new do |s| s.description = 'SitemapGenerator is a framework-agnostic XML Sitemap generator written in Ruby with automatic Rails integration. It supports Video, News, Image, Mobile, PageMap and Alternate Links sitemap extensions and includes Rake tasks for managing your sitemaps, as well as many other great features.' s.license = 'MIT' s.add_dependency 'builder', '~> 3.0' - s.add_development_dependency 'aws-sdk-core' - s.add_development_dependency 'aws-sdk-s3' - s.add_development_dependency 'fog-aws' - s.add_development_dependency 'google-cloud-storage' - s.add_development_dependency 'nokogiri' - s.add_development_dependency 'rake' - s.add_development_dependency 'rspec_junit_formatter' - s.add_development_dependency 'rspec' - s.add_development_dependency 'webmock' s.files = Dir.glob('{lib,rails,templates}/**/*') + %w(CHANGES.md MIT-LICENSE README.md VERSION) end diff --git a/spec/sitemap_generator/adapters/aws_sdk_adapter_spec.rb b/spec/sitemap_generator/adapters/aws_sdk_adapter_spec.rb index c393f311..4b08b217 100644 --- a/spec/sitemap_generator/adapters/aws_sdk_adapter_spec.rb +++ b/spec/sitemap_generator/adapters/aws_sdk_adapter_spec.rb @@ -2,7 +2,7 @@ require 'aws-sdk-core' require 'aws-sdk-s3' -describe SitemapGenerator::AwsSdkAdapter do +RSpec.describe SitemapGenerator::AwsSdkAdapter do subject(:adapter) { described_class.new('bucket', **options) } let(:location) { SitemapGenerator::SitemapLocation.new(compress: compress) } diff --git a/spec/sitemap_generator/adapters/file_adapter_spec.rb b/spec/sitemap_generator/adapters/file_adapter_spec.rb index 177a8ba8..4c41fc8b 100644 --- a/spec/sitemap_generator/adapters/file_adapter_spec.rb +++ b/spec/sitemap_generator/adapters/file_adapter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'SitemapGenerator::FileAdapter' do +RSpec.describe 'SitemapGenerator::FileAdapter' do let(:location) { SitemapGenerator::SitemapLocation.new } let(:adapter) { SitemapGenerator::FileAdapter.new } diff --git a/spec/sitemap_generator/adapters/fog_adapter_spec.rb b/spec/sitemap_generator/adapters/fog_adapter_spec.rb index 721ac31f..8ac5c912 100644 --- a/spec/sitemap_generator/adapters/fog_adapter_spec.rb +++ b/spec/sitemap_generator/adapters/fog_adapter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' require 'fog-aws' -describe SitemapGenerator::FogAdapter do +RSpec.describe SitemapGenerator::FogAdapter do context 'when Fog::Storage is not defined' do it 'raises a LoadError' do hide_const('Fog::Storage') diff --git a/spec/sitemap_generator/adapters/google_storage_adapter_spec.rb b/spec/sitemap_generator/adapters/google_storage_adapter_spec.rb index eaed97bf..13176b36 100644 --- a/spec/sitemap_generator/adapters/google_storage_adapter_spec.rb +++ b/spec/sitemap_generator/adapters/google_storage_adapter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' require 'google/cloud/storage' -describe SitemapGenerator::GoogleStorageAdapter do +RSpec.describe SitemapGenerator::GoogleStorageAdapter do subject(:adapter) { described_class.new(options) } let(:options) { { credentials: 'abc', project_id: 'project_id', bucket: 'bucket' } } diff --git a/spec/sitemap_generator/adapters/s3_adapter_spec.rb b/spec/sitemap_generator/adapters/s3_adapter_spec.rb index 3204d82b..9e426dff 100644 --- a/spec/sitemap_generator/adapters/s3_adapter_spec.rb +++ b/spec/sitemap_generator/adapters/s3_adapter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' require 'fog-aws' -describe SitemapGenerator::S3Adapter do +RSpec.describe SitemapGenerator::S3Adapter do subject(:adapter) { described_class.new(options) } let(:location) do diff --git a/spec/sitemap_generator/adapters/wave_adapter_spec.rb b/spec/sitemap_generator/adapters/wave_adapter_spec.rb index f33db8ca..c06f2080 100644 --- a/spec/sitemap_generator/adapters/wave_adapter_spec.rb +++ b/spec/sitemap_generator/adapters/wave_adapter_spec.rb @@ -1,7 +1,7 @@ # encoding: UTF-8 require 'spec_helper' -describe 'SitemapGenerator::WaveAdapter' do +RSpec.describe 'SitemapGenerator::WaveAdapter' do context 'when CarrierWave::Uploader::Base is not defined' do it 'raises a LoadError' do hide_const('CarrierWave::Uploader::Base') diff --git a/spec/sitemap_generator/application_spec.rb b/spec/sitemap_generator/application_spec.rb index c7140611..6ae6e1be 100644 --- a/spec/sitemap_generator/application_spec.rb +++ b/spec/sitemap_generator/application_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe SitemapGenerator::Application do +RSpec.describe SitemapGenerator::Application do before do stub_const('Rails::VERSION', '1') @app = SitemapGenerator::Application.new diff --git a/spec/sitemap_generator/builder/sitemap_file_spec.rb b/spec/sitemap_generator/builder/sitemap_file_spec.rb index e6d0ec1d..3f7627b1 100644 --- a/spec/sitemap_generator/builder/sitemap_file_spec.rb +++ b/spec/sitemap_generator/builder/sitemap_file_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'SitemapGenerator::Builder::SitemapFile' do +RSpec.describe 'SitemapGenerator::Builder::SitemapFile' do let(:location) { SitemapGenerator::SitemapLocation.new(:namer => SitemapGenerator::SimpleNamer.new(:sitemap, :start => 2, :zero => 1), :public_path => 'tmp/', :sitemaps_path => 'test/', :host => 'http://example.com/') } let(:sitemap) { SitemapGenerator::Builder::SitemapFile.new(location) } diff --git a/spec/sitemap_generator/builder/sitemap_index_file_spec.rb b/spec/sitemap_generator/builder/sitemap_index_file_spec.rb index ac4c6164..de9ccd1f 100644 --- a/spec/sitemap_generator/builder/sitemap_index_file_spec.rb +++ b/spec/sitemap_generator/builder/sitemap_index_file_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'SitemapGenerator::Builder::SitemapIndexFile' do +RSpec.describe 'SitemapGenerator::Builder::SitemapIndexFile' do let(:location) { SitemapGenerator::SitemapLocation.new(:filename => 'sitemap.xml.gz', :public_path => '/public/', :host => 'http://example.com/') } let(:index) { SitemapGenerator::Builder::SitemapIndexFile.new(location) } diff --git a/spec/sitemap_generator/builder/sitemap_index_url_spec.rb b/spec/sitemap_generator/builder/sitemap_index_url_spec.rb index 0b95b12a..a934b9fe 100644 --- a/spec/sitemap_generator/builder/sitemap_index_url_spec.rb +++ b/spec/sitemap_generator/builder/sitemap_index_url_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe SitemapGenerator::Builder::SitemapIndexUrl do +RSpec.describe SitemapGenerator::Builder::SitemapIndexUrl do let(:index) { SitemapGenerator::Builder::SitemapIndexFile.new( :sitemaps_path => 'sitemaps/', diff --git a/spec/sitemap_generator/builder/sitemap_url_spec.rb b/spec/sitemap_generator/builder/sitemap_url_spec.rb index fabe5735..2ed75f8b 100644 --- a/spec/sitemap_generator/builder/sitemap_url_spec.rb +++ b/spec/sitemap_generator/builder/sitemap_url_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe SitemapGenerator::Builder::SitemapUrl do +RSpec.describe SitemapGenerator::Builder::SitemapUrl do let(:loc) { SitemapGenerator::SitemapLocation.new( :sitemaps_path => 'sitemaps/', diff --git a/spec/sitemap_generator/core_ext/bigdecimal_spec.rb b/spec/sitemap_generator/core_ext/bigdecimal_spec.rb index 931d2c16..8a19a1f7 100644 --- a/spec/sitemap_generator/core_ext/bigdecimal_spec.rb +++ b/spec/sitemap_generator/core_ext/bigdecimal_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'bigdecimal' -describe SitemapGenerator::BigDecimal do +RSpec.describe SitemapGenerator::BigDecimal do describe 'to_yaml' do it 'should serialize correctly' do expect(SitemapGenerator::BigDecimal.new('100000.30020320320000000000000000000000000000001').to_yaml).to match(/^--- 100000\.30020320320000000000000000000000000000001\n/) diff --git a/spec/sitemap_generator/core_ext/numeric_spec.rb b/spec/sitemap_generator/core_ext/numeric_spec.rb index c76d526a..9a4a5686 100644 --- a/spec/sitemap_generator/core_ext/numeric_spec.rb +++ b/spec/sitemap_generator/core_ext/numeric_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe SitemapGenerator::Numeric do +RSpec.describe SitemapGenerator::Numeric do def numeric(size) SitemapGenerator::Numeric.new(size) end diff --git a/spec/sitemap_generator/helpers/number_helper_spec.rb b/spec/sitemap_generator/helpers/number_helper_spec.rb index ce6a7637..03dc92d9 100644 --- a/spec/sitemap_generator/helpers/number_helper_spec.rb +++ b/spec/sitemap_generator/helpers/number_helper_spec.rb @@ -17,7 +17,7 @@ def terabytes(number) gigabytes(number) * 1024 end -describe SitemapGenerator::Helpers::NumberHelper do +RSpec.describe SitemapGenerator::Helpers::NumberHelper do include SitemapGenerator::Helpers::NumberHelper it 'should number_with_delimiter' do diff --git a/spec/sitemap_generator/interpreter_spec.rb b/spec/sitemap_generator/interpreter_spec.rb index 725a370d..f17af5b6 100644 --- a/spec/sitemap_generator/interpreter_spec.rb +++ b/spec/sitemap_generator/interpreter_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'sitemap_generator/interpreter' -describe SitemapGenerator::Interpreter do +RSpec.describe SitemapGenerator::Interpreter do let(:link_set) { SitemapGenerator::LinkSet.new } let(:interpreter) { SitemapGenerator::Interpreter.new(:link_set => link_set) } diff --git a/spec/sitemap_generator/link_set_spec.rb b/spec/sitemap_generator/link_set_spec.rb index 91fa5f80..f49d6388 100644 --- a/spec/sitemap_generator/link_set_spec.rb +++ b/spec/sitemap_generator/link_set_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe SitemapGenerator::LinkSet do +RSpec.describe SitemapGenerator::LinkSet do let(:default_host) { 'http://example.com' } let(:ls) { SitemapGenerator::LinkSet.new(:default_host => default_host) } diff --git a/spec/sitemap_generator/sitemap_generator_spec.rb b/spec/sitemap_generator/sitemap_generator_spec.rb index 078e97fd..6c745e51 100644 --- a/spec/sitemap_generator/sitemap_generator_spec.rb +++ b/spec/sitemap_generator/sitemap_generator_spec.rb @@ -15,7 +15,7 @@ def with_max_links(num) SitemapGenerator::Sitemap.max_sitemap_links = original end -describe 'SitemapGenerator' do +RSpec.describe 'SitemapGenerator' do describe 'reset!' do before do SitemapGenerator::Sitemap.default_host # Force initialization of the LinkSet diff --git a/spec/sitemap_generator/sitemap_groups_spec.rb b/spec/sitemap_generator/sitemap_groups_spec.rb index 824f1606..0cefc84e 100644 --- a/spec/sitemap_generator/sitemap_groups_spec.rb +++ b/spec/sitemap_generator/sitemap_groups_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'Sitemap Groups' do +RSpec.describe 'Sitemap Groups' do let(:linkset) { ::SitemapGenerator::LinkSet.new(:default_host => 'http://test.com') } before do diff --git a/spec/sitemap_generator/sitemap_location_spec.rb b/spec/sitemap_generator/sitemap_location_spec.rb index 8015eda4..ee0bb357 100644 --- a/spec/sitemap_generator/sitemap_location_spec.rb +++ b/spec/sitemap_generator/sitemap_location_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe SitemapGenerator::SitemapLocation do +RSpec.describe SitemapGenerator::SitemapLocation do let(:default_host) { 'http://example.com' } let(:location) { SitemapGenerator::SitemapLocation.new } @@ -217,7 +217,7 @@ end end -describe SitemapGenerator::SitemapIndexLocation do +RSpec.describe SitemapGenerator::SitemapIndexLocation do let(:location) { SitemapGenerator::SitemapIndexLocation.new } it 'should have a default namer' do diff --git a/spec/sitemap_generator/sitemap_namer_spec.rb b/spec/sitemap_generator/sitemap_namer_spec.rb index d1f43f6a..0f908975 100644 --- a/spec/sitemap_generator/sitemap_namer_spec.rb +++ b/spec/sitemap_generator/sitemap_namer_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe SitemapGenerator::SimpleNamer do +RSpec.describe SitemapGenerator::SimpleNamer do it 'should generate file names' do namer = SitemapGenerator::SimpleNamer.new(:sitemap) expect(namer.to_s).to eq('sitemap.xml.gz') diff --git a/spec/sitemap_generator/sitemaps/alternate_sitemap_spec.rb b/spec/sitemap_generator/sitemaps/alternate_sitemap_spec.rb index ea92291a..bee111bd 100644 --- a/spec/sitemap_generator/sitemaps/alternate_sitemap_spec.rb +++ b/spec/sitemap_generator/sitemaps/alternate_sitemap_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'SitemapGenerator' do +RSpec.describe 'SitemapGenerator' do it 'should not include media element unless provided' do xml_fragment = SitemapGenerator::Builder::SitemapUrl.new('link_with_alternates.html', :host => 'http://www.example.com', diff --git a/spec/sitemap_generator/sitemaps/mobile_sitemap_spec.rb b/spec/sitemap_generator/sitemaps/mobile_sitemap_spec.rb index 12768b0e..2e6f3981 100644 --- a/spec/sitemap_generator/sitemaps/mobile_sitemap_spec.rb +++ b/spec/sitemap_generator/sitemaps/mobile_sitemap_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'SitemapGenerator' do +RSpec.describe 'SitemapGenerator' do it 'should add the mobile sitemap element' do loc = 'http://www.example.com/mobile_page.html' diff --git a/spec/sitemap_generator/sitemaps/news_sitemap_spec.rb b/spec/sitemap_generator/sitemaps/news_sitemap_spec.rb index bab2461b..315bbc49 100644 --- a/spec/sitemap_generator/sitemaps/news_sitemap_spec.rb +++ b/spec/sitemap_generator/sitemaps/news_sitemap_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'SitemapGenerator' do +RSpec.describe 'SitemapGenerator' do it 'should add the news sitemap element' do loc = 'http://www.example.com/my_article.html' diff --git a/spec/sitemap_generator/sitemaps/pagemap_sitemap_spec.rb b/spec/sitemap_generator/sitemaps/pagemap_sitemap_spec.rb index 8d683ea9..63e9eb0c 100644 --- a/spec/sitemap_generator/sitemaps/pagemap_sitemap_spec.rb +++ b/spec/sitemap_generator/sitemaps/pagemap_sitemap_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'SitemapGenerator' do +RSpec.describe 'SitemapGenerator' do let(:schema) { SitemapGenerator::SCHEMAS['pagemap'] } it 'should add the pagemap sitemap element' do diff --git a/spec/sitemap_generator/sitemaps/video_sitemap_spec.rb b/spec/sitemap_generator/sitemaps/video_sitemap_spec.rb index f193d119..6c8b3ab8 100644 --- a/spec/sitemap_generator/sitemaps/video_sitemap_spec.rb +++ b/spec/sitemap_generator/sitemaps/video_sitemap_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'SitemapGenerator' do +RSpec.describe 'SitemapGenerator' do let(:url_options) do { :host => 'http://example.com', diff --git a/spec/sitemap_generator/templates_spec.rb b/spec/sitemap_generator/templates_spec.rb index cd626df4..551a8b4b 100644 --- a/spec/sitemap_generator/templates_spec.rb +++ b/spec/sitemap_generator/templates_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'Templates class' do +RSpec.describe 'Templates class' do it 'should provide method access to each template' do SitemapGenerator::Templates::FILES.each do |name, file| diff --git a/spec/sitemap_generator/utilities/existence_spec.rb b/spec/sitemap_generator/utilities/existence_spec.rb index c0f1f2f1..b1d98a2f 100644 --- a/spec/sitemap_generator/utilities/existence_spec.rb +++ b/spec/sitemap_generator/utilities/existence_spec.rb @@ -11,7 +11,7 @@ def empty?() false; end BLANK = [ EmptyTrue.new, nil, false, '', ' ', " \n\t \r ", [], {} ] NOT = [ EmptyFalse.new, Object.new, true, 0, 1, 'a', [nil], { nil => 0 } ] -describe Object do +RSpec.describe Object do let(:utils) { SitemapGenerator::Utilities } it 'should define blankness' do diff --git a/spec/sitemap_generator/utilities/hash_spec.rb b/spec/sitemap_generator/utilities/hash_spec.rb index 1a9fca04..cca08c55 100644 --- a/spec/sitemap_generator/utilities/hash_spec.rb +++ b/spec/sitemap_generator/utilities/hash_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe SitemapGenerator::Utilities do +RSpec.describe SitemapGenerator::Utilities do let(:utils) { SitemapGenerator::Utilities } describe 'assert_valid_keys' do diff --git a/spec/sitemap_generator/utilities/rounding_spec.rb b/spec/sitemap_generator/utilities/rounding_spec.rb index fe88356f..909f8900 100644 --- a/spec/sitemap_generator/utilities/rounding_spec.rb +++ b/spec/sitemap_generator/utilities/rounding_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe SitemapGenerator::Utilities do +RSpec.describe SitemapGenerator::Utilities do describe 'rounding' do let(:utils) { SitemapGenerator::Utilities } diff --git a/spec/sitemap_generator/utilities_spec.rb b/spec/sitemap_generator/utilities_spec.rb index b1e876a6..026fdd60 100644 --- a/spec/sitemap_generator/utilities_spec.rb +++ b/spec/sitemap_generator/utilities_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe SitemapGenerator::Utilities do +RSpec.describe SitemapGenerator::Utilities do describe 'assert_valid_keys' do it 'should raise error on invalid keys' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3f0e112c..65dd534e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,18 +1,38 @@ -# require 'simplecov' -# SimpleCov.start -require 'bundler/setup' -Bundler.require - -require './spec/support/file_macros' -require './spec/support/xml_macros' -require 'webmock/rspec' +# Load dev/test libs require 'byebug' +require 'webmock/rspec' -WebMock.disable_net_connect! +# Load support files +require_relative 'support/file_macros' +require_relative 'support/xml_macros' -SitemapGenerator.verbose = false +# Load simplecov +require 'simplecov' +SimpleCov.start do + add_filter 'spec/' +end +# Configure webmock +WebMock.disable_net_connect! + +# Configure rspec RSpec.configure do |config| config.include(FileMacros) config.include(XmlMacros) + + # run tests in random order + config.order = :random + Kernel.srand config.seed + + config.expect_with :rspec do |c| + c.syntax = :expect + end + + # disable monkey patching + # see: https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + config.disable_monkey_patching! end + +# Load our own gem +require 'sitemap_generator' +SitemapGenerator.verbose = false