diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..0578a365 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,75 @@ +# +version: 2 +jobs: + build: + docker: + # specify the version you desire here + - image: circleci/ruby:2.3.4-node-browsers + environment: + CC_TEST_REPORTER_ID: 2ad0d3196c872832cf5d6b34c83bf21dbf0a30e2191ba036be003b01e417a6a1 + PG_HOST: localhost + PG_USER: postgres + RAILS_ENV: test + RACK_ENV: test + DATABASE_URL: "postgres://postgres:postgres@localhost:5432/micropurchase_test" + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + - image: postgres:9.6.2 + environment: + POSTGRES_USER: postgres + POSTGRES_DB: micropurchase_test + POSTGRES_PASSWORD: postgres + + working_directory: ~/micropurchase + + steps: + - checkout + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "Gemfile.lock" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: + name: install dependencies + command: | + bundle install --jobs=4 --retry=3 --path vendor/bundle + curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + chmod +x ./cc-test-reporter + + - save_cache: + paths: + - ./venv + key: v1-dependencies-{{ checksum "Gemfile.lock" }} + # Database setup + - run: bundle exec rake db:create + - run: bundle exec rake db:schema:load + + # run tests! + # TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)" + - run: + name: run tests + command: | + mkdir /tmp/test-results + ./cc-test-reporter before-build + bundle exec rspec --format progress \ + --format RspecJunitFormatter \ + --out /tmp/test-results/rspec.xml \ + --format progress + ./cc-test-reporter format-coverage --output coverage/codeclimate.rspec.json + bundle exec cucumber --format junit --out /tmp/test-results/cucumber.xml + ./cc-test-reporter format-coverage --output coverage/codeclimate.cucumber.json + ./cc-test-reporter sum-coverage --parts 2 --output coverage/codeclimate.json coverage/codeclimate.*.json + ./cc-test-reporter upload-coverage + + # --format CircleCICucumberFormatter::CircleCIJson + # collect reports + - store_test_results: + path: /tmp/test-results + - store_artifacts: + path: /tmp/test-results + destination: test-results diff --git a/.ruby-version b/.ruby-version index 0bee604d..3f684d2d 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.3.3 +2.3.4 diff --git a/.simplecov b/.simplecov index 59027b20..27b8a3fe 100644 --- a/.simplecov +++ b/.simplecov @@ -3,10 +3,8 @@ SimpleCov.add_filter '/spec' SimpleCov.add_filter '/features' SimpleCov.add_filter '/vendor' -if ENV['CI'] - ENV['DEFAULT_BRANCH'] = 'develop' - require 'codeclimate_batch' - CodeclimateBatch.start -else - SimpleCov.start +if ENV['CIRCLE_ARTIFACTS'] + dir = File.join(ENV['CIRCLE_ARTIFACTS'], "coverage") + SimpleCov.coverage_dir(dir) end +SimpleCov.start diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 09b9f86e..00000000 --- a/.travis.yml +++ /dev/null @@ -1,48 +0,0 @@ -language: generic - -services: - - docker - -before_install: - - cp .env.test .env - - rm .ruby-version - - sudo rm /usr/local/bin/docker-compose - - curl -L https://github.com/docker/compose/releases/download/1.4.2/docker-compose-`uname -s`-`uname -m` > docker-compose - - chmod +x docker-compose - - sudo mv docker-compose /usr/local/bin - -script: - - docker-compose build - - docker-compose up -d - - docker-compose run web bundle exec rake - -notifications: - email: false - -addons: - code_climate: - repo_token: 2ad0d3196c872832cf5d6b34c83bf21dbf0a30e2191ba036be003b01e417a6a1 - -after_script: -- "./bin/codeclimate-batch --groups 2" -- docker pull 18fgsa/pa11y-crawl-docker -- docker-compose up -d -- docker run -t --net="host" 18fgsa/pa11y-crawl-docker pa11y-crawl http://localhost:3000 - -before_deploy: -- export PATH=$HOME:$PATH -- travis_retry curl -L -o $HOME/cf.tgz "https://cli.run.pivotal.io/stable?release=linux64-binary&version=6.22.2" -- tar xzvf $HOME/cf.tgz -C $HOME -- cf install-plugin autopilot -f -r CF-Community -- docker-compose run web bundle exec rake git:dump_sha -deploy: -- provider: script - script: "./bin/deploy.sh staging" - skip_cleanup: true - on: - branch: develop -- provider: script - script: "./bin/deploy.sh production" - skip_cleanup: true - on: - branch: master diff --git a/Gemfile b/Gemfile index f7f74bb1..cfc4a291 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '2.3.3' +ruby '2.3.4' gem 'rails', '4.2.7.1' gem 'pg' @@ -41,9 +41,8 @@ gem 'uswds-rails', github: '18F/uswds-rails-gem' gem 'rest-client' group :test do - gem "codeclimate-test-reporter", require: nil - gem 'codeclimate_batch', require: nil gem 'dotenv' + gem "simplecov", require: nil gem 'db-query-matchers' gem 'json-schema' gem 'shoulda-matchers' @@ -53,6 +52,7 @@ end group :development, :test do gem 'rspec-rails' + gem 'rspec_junit_formatter' gem 'cucumber-rails', require: false gem 'capybara' gem 'poltergeist' diff --git a/Gemfile.lock b/Gemfile.lock index a3e2b6fc..504b1b2d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -103,10 +103,6 @@ GEM clockwork (2.0.2) activesupport tzinfo - codeclimate-test-reporter (1.0.8) - simplecov (<= 0.13) - codeclimate_batch (0.5.0) - json coderay (1.1.1) commander (4.4.3) highline (~> 1.7.2) @@ -354,6 +350,8 @@ GEM rspec-mocks (~> 3.6.0) rspec-support (~> 3.6.0) rspec-support (3.6.0) + rspec_junit_formatter (0.3.0) + rspec-core (>= 2, < 4, != 2.12.0) rubocop (0.48.1) parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) @@ -449,8 +447,6 @@ DEPENDENCIES cf-app-utils chronic clockwork - codeclimate-test-reporter - codeclimate_batch cucumber-rails daemons database_cleaner @@ -491,6 +487,7 @@ DEPENDENCIES redcarpet rest-client rspec-rails + rspec_junit_formatter rubocop ruby-saml (= 1.4.2) saml_idp! @@ -499,6 +496,7 @@ DEPENDENCIES selectize-rails shoulda-matchers simple_form + simplecov sinatra timecop uglifier @@ -508,7 +506,7 @@ DEPENDENCIES webmock RUBY VERSION - ruby 2.3.3p222 + ruby 2.3.4p301 BUNDLED WITH - 1.14.6 + 1.15.3 diff --git a/README.md b/README.md index 0da71844..42d6837a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Code Climate](https://codeclimate.com/github/18F/micropurchase/badges/gpa.svg)](https://codeclimate.com/github/18F/micropurchase) [![Test Coverage](https://codeclimate.com/github/18F/micropurchase/badges/coverage.svg)](https://codeclimate.com/github/18F/micropurchase/coverage) [![Dependency Status](https://gemnasium.com/18F/micropurchase.svg)](https://gemnasium.com/18F/micropurchase) [![security](https://hakiri.io/github/18F/micropurchase/master.svg)](https://hakiri.io/github/18F/micropurchase/master) -[![Accessibility](https://continua11y.18f.gov/18F/micropurchase.svg?branch=develop)](https://continua11y.18f.gov/18F/micropurchase) +[![Accessibility](https://continua11y.18f.gov/18F/micropurchase.svg?branch=develop)](https://continua11y.18f.gov/18F/micropurchase) [![Build Status](https://circleci.com/gh/18F/micropurchase.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/18F/micropurchase.svg?style=shield&circle-token=:circle-token) # Micro-purchase diff --git a/features/support/_circleci_formatter.rb b/features/support/_circleci_formatter.rb new file mode 100644 index 00000000..32197e4a --- /dev/null +++ b/features/support/_circleci_formatter.rb @@ -0,0 +1,79 @@ +require 'time' + +if Cucumber::VERSION =~ /^2.*/ + require 'cucumber/core/test/timer' + require 'cucumber/formatter/json' + module Cucumber + module Core + module Test + class Timer + def unpatched_time_now + if Time.respond_to?(:now_without_mock_time) + Time.now_without_mock_time + else + Time.now + end + end + + def time_in_nanoseconds + t = unpatched_time_now + t.to_i * 10 ** 9 + t.nsec + end + end + end + end + end + + module CircleCICucumberFormatter + class CircleCIJson < Cucumber::Formatter::Json #:nodoc: + end + end +end # if + +if Cucumber::VERSION =~ /^1.*/ + require 'cucumber/formatter/gherkin_formatter_adapter' + require 'cucumber/formatter/io' + require 'gherkin/formatter/argument' + require 'gherkin/formatter/json_formatter' + + module CircleCICucumberFormatter + class CircleCIJson < Cucumber::Formatter::GherkinFormatterAdapter #:nodoc: + include Cucumber::Formatter::Io + + alias_method :original_before_step, :before_step + + def unpatched_time_now + if Time.respond_to?(:now_without_mock_time) + Time.now_without_mock_time + else + Time.now + end + end + + def initialize(_runtime, io, options) + @io = ensure_io(io, 'json') + f = Gherkin::Formatter::JSONFormatter.new(@io) + begin + super(f, false, options) + rescue ArgumentError # backwards compatibility with old arity + super(f, false) + end + end + + # override @step_time with un-patched Time.now + def before_step(step) + original_before_step(step) + @step_time = unpatched_time_now + end + + # used for capturing duration, copied from gherkin_formatter_adapter.rb + # override step_finish with un-patched Time.now + def after_step(_step) + return if @outline && @options && @options[:expand] && + !@in_instantiated_scenario + step_finish = (unpatched_time_now - @step_time) + @gf.append_duration(step_finish) + end + end + end # module +end # if