From 8d9ab25aec05e7310db42e1329bd24a1196c6d2f Mon Sep 17 00:00:00 2001 From: andrew morton Date: Sun, 31 Mar 2019 21:47:51 -0600 Subject: [PATCH] Get tests passing after gem updates - Lock sqlite3 to 1.3.x - Downgrade to bundler 1.x - Test non-EOL ruby versions - Move make_site.sh to scripts/ - Add scripts/run_tests.sh --- .rubocop.yml | 4 ++-- .travis.yml | 15 ++++++++++---- CONTRIBUTING.md | 12 ++++++------ Gemfile | 29 ++++++++++++++-------------- make_site.sh => scripts/make_site.sh | 15 ++++---------- scripts/run_tests.sh | 6 ++++++ 6 files changed, 44 insertions(+), 37 deletions(-) rename make_site.sh => scripts/make_site.sh (62%) create mode 100755 scripts/run_tests.sh diff --git a/.rubocop.yml b/.rubocop.yml index edba7fe..2932e23 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -678,7 +678,7 @@ Style/IndentationConsistency: Style/IndentationWidth: Description: 'Use 2 spaces for indentation.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation' - Enabled: false + Enabled: true Style/IndentArray: Description: >- @@ -708,7 +708,7 @@ Style/LambdaCall: Style/LeadingCommentSpace: Description: 'Comments should start with a space.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space' - Enabled: false + Enabled: true Style/LineEndConcatenation: Description: >- diff --git a/.travis.yml b/.travis.yml index 6f88f0f..39a61fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,26 @@ language: ruby rvm: - - 2.2 - 2.3 - 2.4 - 2.5 + - 2.6 env: - RAILS_VERSION=3.2.0 - RAILS_VERSION=4.2.0 - - RAILS_VERSION=5.1.0 + - RAILS_VERSION=5.2.0 cache: bundler -install: ./make_site.sh -script: bundle exec rspec +before_install: + # Revert to bundler 1.x for compatibility with Rails 4.2 on Ruby 2.5 + - "find /home/travis/.rvm/rubies -wholename '*default/bundler-*.gemspec' -delete" + - rvm @global do gem uninstall bundler -a -x -I || true + - gem install bundler -v '~> 1.17' +install: scripts/make_site.sh +script: scripts/run_tests.sh matrix: exclude: - rvm: 2.4 env: RAILS_VERSION=3.2.0 - rvm: 2.5 env: RAILS_VERSION=3.2.0 + - rvm: 2.6 + env: RAILS_VERSION=3.2.0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 344f5fd..1355817 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,14 +2,14 @@ ## Running tests -The `make_site.sh` script will create a test site for a specific version of -Rails and run the tests: +The `scripts/make_site.sh` script will create a test site for a specific version of +Rails: ``` -RAILS_VERSION=4.2.0 -./make_site.sh +export RAILS_VERSION=4.2.0 +scripts/make_site.sh ``` -Once the test site is created you can just re-run the tests: +Once the test site is created you can run the tests: ``` -bundle exec rspec +scripts/run_tests.sh ``` diff --git a/Gemfile b/Gemfile index 855c61b..0240090 100644 --- a/Gemfile +++ b/Gemfile @@ -3,22 +3,23 @@ source "https://rubygems.org" gemspec # Allow the rails version to come from an ENV setting so Tavis can test multiple -# versions. Inspired by http://www.schneems.com/post/50991826838/testing-against-multiple-rails-versions/ -rails_version = ENV['RAILS_VERSION'] || '3.2.22' +# versions. +rails_version = ENV['RAILS_VERSION'] || '5.2.0' rails_major = rails_version.split('.').first -rails_gem = case rails_version - when "default" then - "~> 5.0.0" - else - "~> #{rails_version}" - end -gem 'rails', rails_gem -gem 'sqlite3' +gem 'rails', "~> #{rails_version}" gem 'pry' gem 'pry-byebug' +gem 'sqlite3', '~> 1.3.13' -# Rails 3 requires this but it was removed in Ruby 2.2 -gem 'test-unit', '~> 3.0' if rails_major == '3' -# Need this for Rails 4 to get the JSON responses from the scaffold -gem 'jbuilder' if rails_major == '4' +case rails_major +when '3' + # Rails 3 requires this but it was removed in Ruby 2.2 + gem 'test-unit', '~> 3.0' +when '4' + # Need this for Rails 4 to get the JSON responses from the scaffold + gem 'jbuilder' +when '5' + # Required for 5.2+ + gem 'bootsnap' +end diff --git a/make_site.sh b/scripts/make_site.sh similarity index 62% rename from make_site.sh rename to scripts/make_site.sh index eb3f93d..4ab4040 100755 --- a/make_site.sh +++ b/scripts/make_site.sh @@ -1,20 +1,17 @@ #!/bin/bash -set -x +set -x -e -# export RAILS_VERSION=3.2.0 -# export RAILS_VERSION=4.0.0 -# export RAILS_VERSION=5.0.0 major=$(echo $RAILS_VERSION | cut -d '.' -f1) -rm Gemfile.lock +rm Gemfile.lock || true bundle install -rm -r spec/testapp +rm -r spec/testapp || true bundle exec rails new spec/testapp --api -d sqlite3 --skip-gemfile --skip-bundle --skip-test-unit --skip-action-mailer --skip-puma --skip-action-cable --skip-sprockets --skip-javascript --skip-spring --skip-listen cd spec/testapp bundle exec rails generate scaffold Post title:string body:text -rm -r spec +rm -r spec || true if [ $major -eq 5 ] then @@ -26,7 +23,3 @@ else fi cd - - -bundle exec rspec -# Duplicating the body of the rake task. Need to figure out how to call it directly. -bundle exec rspec -f RSpec::Rails::Swagger::Formatter --order defined -t swagger_object diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh new file mode 100755 index 0000000..2456ae2 --- /dev/null +++ b/scripts/run_tests.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -x -e + +bundle exec rspec +# Duplicating the body of the rake task. Need to figure out how to call it directly. +bundle exec rspec -f RSpec::Rails::Swagger::Formatter --order defined -t swagger_object