Sfoglia il codice sorgente

Fix Rubocop lint errors

Andrew Swistak 6 anni fa
parent
commit
7307985694
51 ha cambiato i file con 187 aggiunte e 99 eliminazioni
  1. 13 11
      Gemfile
  2. 2 0
      Rakefile
  3. 2 0
      app/channels/application_cable/channel.rb
  4. 2 0
      app/channels/application_cable/connection.rb
  5. 9 9
      app/controllers/api/v1/application_controller.rb
  6. 16 16
      app/controllers/api/v1/pokemon_controller.rb
  7. 2 0
      app/controllers/application_controller.rb
  8. 3 2
      app/controllers/welcome_controller.rb
  9. 2 0
      app/helpers/application_helper.rb
  10. 2 0
      app/jobs/application_job.rb
  11. 2 0
      app/mailers/application_mailer.rb
  12. 2 0
      app/models/application_record.rb
  13. 2 0
      app/models/pokemon.rb
  14. 2 0
      app/views/api/v1/application/_error.json.jbuilder
  15. 2 0
      app/views/api/v1/pokemon/_pokemon.json.jbuilder
  16. 0 1
      app/views/api/v1/pokemon/index.json.jbuilder
  17. 2 0
      config.ru
  18. 2 0
      config/application.rb
  19. 2 0
      config/boot.rb
  20. 2 0
      config/environment.rb
  21. 3 1
      config/environments/development.rb
  22. 4 2
      config/environments/production.rb
  23. 3 1
      config/environments/test.rb
  24. 2 0
      config/initializers/application_controller_renderer.rb
  25. 2 0
      config/initializers/assets.rb
  26. 2 0
      config/initializers/backtrace_silencers.rb
  27. 3 1
      config/initializers/content_security_policy.rb
  28. 2 0
      config/initializers/cookies_serializer.rb
  29. 2 0
      config/initializers/filter_parameter_logging.rb
  30. 2 0
      config/initializers/inflections.rb
  31. 2 0
      config/initializers/mime_types.rb
  32. 4 2
      config/initializers/pkparse.rb
  33. 2 0
      config/initializers/wrap_parameters.rb
  34. 5 3
      config/puma.rb
  35. 3 1
      config/routes.rb
  36. 2 0
      config/spring.rb
  37. 2 0
      db/migrate/20181228215350_create_pokemon.rb
  38. 2 0
      db/seeds.rb
  39. 1 1
      lib/pkparse/client.rb
  40. 2 2
      lib/pkparse/error.rb
  41. 6 4
      lib/pkparse/pokemon.rb
  42. 4 4
      lib/pkparse/response.rb
  43. 12 9
      lib/pkparse/response_error.rb
  44. 6 2
      lib/tasks/factory_bot.rake
  45. 4 2
      spec/capybara_helper.rb
  46. 15 13
      spec/controllers/api/v1/pokemon_controller_spec.rb
  47. 2 0
      spec/factories/pokemon_factory.rb
  48. 2 3
      spec/lib/pkparse/client_spec.rb
  49. 11 9
      spec/rails_helper.rb
  50. 2 0
      spec/spec_helper.rb
  51. 2 0
      spec/systems/pokemon_spec.rb

+ 13 - 11
Gemfile

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 source 'https://rubygems.org'
 git_source(:github) { |repo| "https://github.com/#{repo}.git" }
 
@@ -23,24 +25,24 @@ gem 'webpacker'
 # gem 'image_processing', '~> 1.2'
 
 group :development, :test do
-  gem 'rubocop', '~> 0.67.2', require: false
-  gem 'rubocop-performance'
+  gem 'database_cleaner'
   gem 'dotenv-rails'
+  gem 'factory_bot_rails'
+  gem 'faker'
   gem 'pry'
   gem 'pry-rails'
   gem 'rails-controller-testing'
-  gem 'factory_bot_rails'
-  gem 'faker'
-  gem 'database_cleaner'
+  gem 'rubocop', '~> 0.67.2', require: false
+  gem 'rubocop-performance'
 
   # Using unreleased rspec version (since we're using Rails v6.0.0.beta3)
   # The following refs were the latest commits on their respective master
   # branches
-  gem 'rspec-support', github: "rspec/rspec-support", ref: "b2389"
-  gem 'rspec-expectations', github: "rspec/rspec-expectations", ref: "8d630"
-  gem 'rspec-mocks', github: "rspec/rspec-mocks", ref: "f1b69"
-  gem 'rspec-core', github: "rspec/rspec-core", :ref => "4a29a"
-  gem 'rspec-rails', github: "rspec/rspec-rails", branch: "4-0-dev"
+  gem 'rspec-core', github: 'rspec/rspec-core', ref: '4a29a'
+  gem 'rspec-expectations', github: 'rspec/rspec-expectations', ref: '8d630'
+  gem 'rspec-mocks', github: 'rspec/rspec-mocks', ref: 'f1b69'
+  gem 'rspec-rails', github: 'rspec/rspec-rails', branch: '4-0-dev'
+  gem 'rspec-support', github: 'rspec/rspec-support', ref: 'b2389'
 end
 
 group :development do
@@ -61,4 +63,4 @@ group :test do
 end
 
 # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
-gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
+gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

+ 2 - 0
Rakefile

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # Add your own tasks in files placed in lib/tasks ending in .rake,
 # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
 

+ 2 - 0
app/channels/application_cable/channel.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 module ApplicationCable
   class Channel < ActionCable::Channel::Base
   end

+ 2 - 0
app/channels/application_cable/connection.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 module ApplicationCable
   class Connection < ActionCable::Connection::Base
   end

+ 9 - 9
app/controllers/api/v1/application_controller.rb

@@ -8,20 +8,20 @@ class API::V1::ApplicationController < ActionController::API
   rescue_from StandardError, with: :handle_unhandled_api_error
 
   def not_found
-    @error = APIError::BaseError.new("The requested resource was not found")
+    @error = APIError::BaseError.new('The requested resource was not found')
     render partial: 'error', status: :not_found
   end
 
   private
 
-  def handle_unhandled_api_error(e)
-    Rails.logger.error("Unhandled API Error: #{e}\n#{e.backtrace.join("\n")}")
+    def handle_unhandled_api_error(err)
+      Rails.logger.error("Unhandled API Error: #{err}\n#{err.backtrace.join("\n")}")
 
-    @error = APIError::BaseError.new("An unhandled exception occurred.", internal_error: e)
-    render partial: 'error', status: :internal_server_error
-  end
+      @error = APIError::BaseError.new('An unhandled exception occurred.', internal_error: err)
+      render partial: 'error', status: :internal_server_error
+    end
 
-  def set_default_response_format
-    request.format = :json
-  end
+    def set_default_response_format
+      request.format = :json
+    end
 end

+ 16 - 16
app/controllers/api/v1/pokemon_controller.rb

@@ -6,8 +6,8 @@ class API::V1::PokemonController < API::V1::ApplicationController
   def create
     @pokemon = Pokemon.new(new_pokemon_params)
 
-    if !@pokemon.save
-      @error = APIError::BaseError.new("Failed to create pokemon.")
+    unless @pokemon.save
+      @error = APIError::BaseError.new('Failed to create pokemon.')
       render partial: 'error', status: :unprocessable_entity
     end
   end
@@ -18,7 +18,7 @@ class API::V1::PokemonController < API::V1::ApplicationController
     if @pokemon.destroy
       render :show
     else
-      @error = APIError::BaseError.new("Failed to delete pokemon.")
+      @error = APIError::BaseError.new('Failed to delete pokemon.')
       render partial: 'error', status: :unprocessable_entity
     end
   end
@@ -30,7 +30,7 @@ class API::V1::PokemonController < API::V1::ApplicationController
   def show
     @pokemon = Pokemon.find_by(id: params[:id])
 
-    if !@pokemon
+    unless @pokemon
       @error = APIError::BaseError.new("Pokemon with 'id'=#{params[:id]} was not found.")
       render partial: 'error', status: :not_found
     end
@@ -38,7 +38,7 @@ class API::V1::PokemonController < API::V1::ApplicationController
 
   def upload
     files = params[:pokemon]
-    response = pkparse.parse(files)
+    response = pkparse_client.parse(files)
 
     Pokemon.transaction do
       @pokemon = Pokemon.create!(response.pokemon.map(&:to_h))
@@ -51,21 +51,21 @@ class API::V1::PokemonController < API::V1::ApplicationController
   rescue ActiveRecord::ActiveRecordError => e
     PKParse.logger.error("Failed to commit parsed results: #{e}\n#{e.backtrace.join("\n")}")
 
-    @error = APIError::BaseError.new("Failed to commit the uploaded pokemon.", internal_error: e)
+    @error = APIError::BaseError.new('Failed to commit the uploaded pokemon.', internal_error: e)
     render partial: 'error', status: :unprocessable_entity
   end
 
   private
 
-  def new_pokemon_params
-    params.require(:pokemon).permit(
-      :id, :pokedex_number, :nickname
-    )
-  end
+    def new_pokemon_params
+      params.require(:pokemon).permit(
+        :id, :pokedex_number, :nickname
+      )
+    end
 
-  def pkparse
-    # There may be some configuration we'll provide in the future that would
-    # benefit from instantiating the client in this way
-    @pkparse_client ||= PKParse::Client.new
-  end
+    def pkparse_client
+      # There may be some configuration we'll provide in the future that would
+      # benefit from instantiating the client in this way
+      @pkparse_client ||= PKParse::Client.new
+    end
 end

+ 2 - 0
app/controllers/application_controller.rb

@@ -1,2 +1,4 @@
+# frozen_string_literal: true
+
 class ApplicationController < ActionController::Base
 end

+ 3 - 2
app/controllers/welcome_controller.rb

@@ -1,4 +1,5 @@
+# frozen_string_literal: true
+
 class WelcomeController < ApplicationController
-  def root
-  end
+  def root; end
 end

+ 2 - 0
app/helpers/application_helper.rb

@@ -1,2 +1,4 @@
+# frozen_string_literal: true
+
 module ApplicationHelper
 end

+ 2 - 0
app/jobs/application_job.rb

@@ -1,2 +1,4 @@
+# frozen_string_literal: true
+
 class ApplicationJob < ActiveJob::Base
 end

+ 2 - 0
app/mailers/application_mailer.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class ApplicationMailer < ActionMailer::Base
   default from: 'from@example.com'
   layout 'mailer'

+ 2 - 0
app/models/application_record.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class ApplicationRecord < ActiveRecord::Base
   self.abstract_class = true
 end

+ 2 - 0
app/models/pokemon.rb

@@ -1,2 +1,4 @@
+# frozen_string_literal: true
+
 class Pokemon < ApplicationRecord
 end

+ 2 - 0
app/views/api/v1/application/_error.json.jbuilder

@@ -1 +1,3 @@
+# frozen_string_literal: true
+
 json.extract! @error, :message, :type

+ 2 - 0
app/views/api/v1/pokemon/_pokemon.json.jbuilder

@@ -1 +1,3 @@
+# frozen_string_literal: true
+
 json.extract! pokemon, :id, :pokedex_number, :nickname

+ 0 - 1
app/views/api/v1/pokemon/index.json.jbuilder

@@ -1,4 +1,3 @@
 # frozen_string_literal: true
 
 json.array! @pokemon, partial: 'pokemon', as: :pokemon
-

+ 2 - 0
config.ru

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # This file is used by Rack-based servers to start the application.
 
 require_relative 'config/environment'

+ 2 - 0
config/application.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require_relative 'boot'
 
 require 'rails/all'

+ 2 - 0
config/boot.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
 
 require 'bundler/setup' # Set up gems listed in the Gemfile.

+ 2 - 0
config/environment.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # Load the Rails application.
 require_relative 'application'
 

+ 3 - 1
config/environments/development.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 Rails.application.configure do
   # Verifies that versions and hashed value of the package contents in the project's package.json
   config.webpacker.check_yarn_integrity = true
@@ -21,7 +23,7 @@ Rails.application.configure do
 
     config.cache_store = :memory_store
     config.public_file_server.headers = {
-      'Cache-Control' => "public, max-age=#{2.days.to_i}"
+      'Cache-Control' => "public, max-age=#{2.days.to_i}",
     }
   else
     config.action_controller.perform_caching = false

+ 4 - 2
config/environments/production.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 Rails.application.configure do
   # Verifies that versions and hashed value of the package contents in the project's package.json
   config.webpacker.check_yarn_integrity = false
@@ -56,7 +58,7 @@ Rails.application.configure do
   config.log_level = :debug
 
   # Prepend all log lines with the following tags.
-  config.log_tags = [ :request_id ]
+  config.log_tags = [:request_id]
 
   # Use a different cache store in production.
   # config.cache_store = :mem_cache_store
@@ -85,7 +87,7 @@ Rails.application.configure do
   # require 'syslog/logger'
   # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
 
-  if ENV["RAILS_LOG_TO_STDOUT"].present?
+  if ENV['RAILS_LOG_TO_STDOUT'].present?
     logger           = ActiveSupport::Logger.new(STDOUT)
     logger.formatter = config.log_formatter
     config.logger    = ActiveSupport::TaggedLogging.new(logger)

+ 3 - 1
config/environments/test.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 Rails.application.configure do
   # Settings specified here will take precedence over those in config/application.rb.
 
@@ -15,7 +17,7 @@ Rails.application.configure do
   # Configure public file server for tests with Cache-Control for performance.
   config.public_file_server.enabled = true
   config.public_file_server.headers = {
-    'Cache-Control' => "public, max-age=#{1.hour.to_i}"
+    'Cache-Control' => "public, max-age=#{1.hour.to_i}",
   }
 
   # Show full error reports and disable caching.

+ 2 - 0
config/initializers/application_controller_renderer.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # Be sure to restart your server when you modify this file.
 
 # ActiveSupport::Reloader.to_prepare do

+ 2 - 0
config/initializers/assets.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # Be sure to restart your server when you modify this file.
 
 # Version of your assets, change this if you want to expire all your assets.

+ 2 - 0
config/initializers/backtrace_silencers.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # Be sure to restart your server when you modify this file.
 
 # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.

+ 3 - 1
config/initializers/content_security_policy.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # Be sure to restart your server when you modify this file.
 
 # Define an application-wide content security policy
@@ -19,7 +21,7 @@
 # end
 
 # If you are using UJS then enable automatic nonce generation
-Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
+Rails.application.config.content_security_policy_nonce_generator = ->(_request) { SecureRandom.base64(16) }
 
 # Report CSP violations to a specified URI
 # For further information see the following documentation:

+ 2 - 0
config/initializers/cookies_serializer.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # Be sure to restart your server when you modify this file.
 
 # Specify a serializer for the signed and encrypted cookie jars.

+ 2 - 0
config/initializers/filter_parameter_logging.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # Be sure to restart your server when you modify this file.
 
 # Configure sensitive parameters which will be filtered from the log file.

+ 2 - 0
config/initializers/inflections.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # Be sure to restart your server when you modify this file.
 
 # Add new inflection rules using the following format. Inflections

+ 2 - 0
config/initializers/mime_types.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # Be sure to restart your server when you modify this file.
 
 # Add new mime types for use in respond_to blocks:

+ 4 - 2
config/initializers/pkparse.rb

@@ -1,4 +1,6 @@
+# frozen_string_literal: true
+
 require './lib/pkparse'
 require './lib/tagged_logger'
-PKParse.service_url = ENV["PKPARSE_URL"]
-PKParse.logger = TaggedLogger.new(Rails.logger, "PKParse")
+PKParse.service_url = ENV['PKPARSE_URL']
+PKParse.logger = TaggedLogger.new(Rails.logger, 'PKParse')

+ 2 - 0
config/initializers/wrap_parameters.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # Be sure to restart your server when you modify this file.
 
 # This file contains settings for ActionController::ParamsWrapper which

+ 5 - 3
config/puma.rb

@@ -1,19 +1,21 @@
+# frozen_string_literal: true
+
 # Puma can serve each request in a thread from an internal thread pool.
 # The `threads` method setting takes two numbers: a minimum and maximum.
 # Any libraries that use thread pools should be configured to match
 # the maximum value specified for Puma. Default is set to 5 threads for minimum
 # and maximum; this matches the default thread size of Active Record.
 #
-threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
+threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
 threads threads_count, threads_count
 
 # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
 #
-port        ENV.fetch("PORT") { 3000 }
+port        ENV.fetch('PORT') { 3000 }
 
 # Specifies the `environment` that Puma will run in.
 #
-environment ENV.fetch("RAILS_ENV") { "development" }
+environment ENV.fetch('RAILS_ENV') { 'development' }
 
 # Specifies the number of `workers` to boot in clustered mode.
 # Workers are forked webserver processes. If using threads and workers together

+ 3 - 1
config/routes.rb

@@ -1,7 +1,9 @@
+# frozen_string_literal: true
+
 Rails.application.routes.draw do
   # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
 
-  root to: "welcome#root"
+  root to: 'welcome#root'
 
   namespace :api, defaults: { formats: :json } do
     namespace :v1 do

+ 2 - 0
config/spring.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 %w[
   .ruby-version
   .rbenv-vars

+ 2 - 0
db/migrate/20181228215350_create_pokemon.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class CreatePokemon < ActiveRecord::Migration[5.2]
   def change
     create_table :pokemon do |t|

+ 2 - 0
db/seeds.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # This file should contain all the record creation needed to seed the database with its default values.
 # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
 #

+ 1 - 1
lib/pkparse/client.rb

@@ -10,7 +10,7 @@ module PKParse
 
       PKParse::Response.new(response)
     rescue RestClient::Exception => e
-      raise PKParse::ResponseError.new(e)
+      raise PKParse::ResponseError, e
     rescue JSON::ParserError => e
       raise PKParse::Error.new(e, 'Received invalid parse response')
     end

+ 2 - 2
lib/pkparse/error.rb

@@ -5,8 +5,8 @@ module PKParse
     attr_accessor :original_exception
     attr_writer :message
 
-    def initialize(e, message = nil)
-      @original_exception = e
+    def initialize(error, message = nil)
+      @original_exception = error
       @message = message
     end
 

+ 6 - 4
lib/pkparse/pokemon.rb

@@ -6,9 +6,11 @@ module PKParse
   class Pokemon
     attr_accessor :pokedex_number, :nickname, :raw_nickname, :raw_pokemon
 
-    def initialize(attributes={})
-      attributes.each do |attr,v|
-        send("#{attr}=", v) rescue nil
+    def initialize(attributes = {})
+      attributes.each do |attr, v|
+        send("#{attr}=", v)
+      rescue StandardError
+        nil
       end
     end
 
@@ -21,7 +23,7 @@ module PKParse
       }
     end
 
-    def to_json
+    def to_json(*_args)
       to_h
     end
   end

+ 4 - 4
lib/pkparse/response.rb

@@ -11,10 +11,10 @@ module PKParse
 
     private
 
-    def build_pokemon
-      @pokemon = response.map do |pkmn|
-        PKParse::Pokemon.new(pkmn)
+      def build_pokemon
+        @pokemon = response.map do |pkmn|
+          PKParse::Pokemon.new(pkmn)
+        end
       end
-    end
   end
 end

+ 12 - 9
lib/pkparse/response_error.rb

@@ -1,20 +1,23 @@
 # frozen_string_literal: true
 
+require 'English'
+
 module PKParse
   class ResponseError < Error
-    def initialize(e)
-      super(e)
+    def initialize(error)
+      super(error)
       parse_body
     end
 
     private
 
-    def parse_body
-      body = original_exception.http_body
-      parsed_body = JSON.parse(body, symbolize_keys: true)
-      @message = parsed_body[:error]
-    rescue
-      PKParse.logger.error("Exception parsing ResponseError http body:\n#{$!}\n#{$!.backtrace.join("\n")}")
-    end
+      def parse_body
+        body = original_exception.http_body
+        parsed_body = JSON.parse(body, symbolize_keys: true)
+        @message = parsed_body[:error]
+      rescue StandardError
+        err = $ERROR_INFO
+        PKParse.logger.error("Exception parsing ResponseError http body:\n#{err}\n#{err.backtrace.join("\n")}")
+      end
   end
 end

+ 6 - 2
lib/tasks/factory_bot.rake

@@ -1,5 +1,9 @@
+# frozen_string_literal: true
+
+require 'English'
+
 namespace :factory_bot do
-  desc "Verify that all FactoryBot factories are valid"
+  desc 'Verify that all FactoryBot factories are valid'
   task lint: :environment do
     if Rails.env.test?
       DatabaseCleaner.clean_with(:deletion)
@@ -8,7 +12,7 @@ namespace :factory_bot do
       end
     else
       system("bundle exec rake factory_bot:lint RAILS_ENV='test'")
-      fail if $?.exitstatus.nonzero?
+      raise if $CHILD_STATUS.exitstatus.nonzero?
     end
   end
 end

+ 4 - 2
spec/capybara_helper.rb

@@ -1,8 +1,10 @@
+# frozen_string_literal: true
+
 require 'capybara/rspec'
 require 'selenium/webdriver'
 
 Capybara.default_max_wait_time = 10
-Capybara.server = :puma, {Silent: true}
+Capybara.server = :puma, { Silent: true }
 
 # Headless firefox and chrome configuration. Useful for CI matrices.
 # See https://gist.github.com/bbonamin/4b01be9ed5dd1bdaf909462ff4fdca95
@@ -44,7 +46,7 @@ Capybara.register_driver :headless_chrome do |app|
   bridge.http.call(:post, path, cmd: 'Page.setDownloadBehavior',
                                 params: {
                                   behavior: 'allow',
-                                  downloadPath: '/tmp/downloads'
+                                  downloadPath: '/tmp/downloads',
                                 })
   ###
 

+ 15 - 13
spec/controllers/api/v1/pokemon_controller_spec.rb

@@ -5,22 +5,22 @@ require 'rails_helper'
 RSpec.describe API::V1::PokemonController, type: :controller do
   def non_existant_pokemon_id(initial_id = 1)
     id = initial_id
-    id *= 2 until !Pokemon.find_by(id: id)
+    id *= 2 while Pokemon.find_by(id: id)
     id
   end
 
-  describe "DELETE #destroy" do
+  describe 'DELETE #destroy' do
     let!(:pokemon) { FactoryBot.create(:pokemon) }
-    subject { delete :destroy, params: {id: pokemon.id} }
+    subject { delete :destroy, params: { id: pokemon.id } }
 
-    context "the pokemon is successfully deleted" do
+    context 'the pokemon is successfully deleted' do
       it 'deletes the pokemon' do
         expect{subject}.to change{Pokemon.count}.by(-1)
         expect(response).to render_template 'api/v1/pokemon/show'
       end
     end
 
-    context "the pokemon is not deleted" do
+    context 'the pokemon is not deleted' do
       before { allow_any_instance_of(Pokemon).to receive(:destroy).and_return(false) }
 
       it 'does not delete the pokemon' do
@@ -29,8 +29,8 @@ RSpec.describe API::V1::PokemonController, type: :controller do
       end
     end
 
-    context "the pokemon does not exist" do
-      let(:pokemon) { double(id: non_existant_pokemon_id ) }
+    context 'the pokemon does not exist' do
+      let(:pokemon) { double(id: non_existant_pokemon_id) }
 
       it 'raises an error' do
         expect{subject rescue nil}.to change{Pokemon.count}.by(0)
@@ -39,11 +39,14 @@ RSpec.describe API::V1::PokemonController, type: :controller do
     end
   end
 
-  describe "POST #upload" do
-    subject { post :upload, params: {pokemon: double()} }
-    let(:pokemon) { double(pokedex_number: 10, nickname: "pyukuchu", to_h: {pokedex_number: 10, nickname: "pyukuchu"}) }
+  describe 'POST #upload' do
+    subject { post :upload, params: { pokemon: double } }
     let(:client_response) { double(pokemon: [pokemon]) }
 
+    let(:pokemon) do
+      double(pokedex_number: 10, nickname: 'pyukuchu', to_h: { pokedex_number: 10, nickname: 'pyukuchu' })
+    end
+
     before do
       allow_any_instance_of(PKParse::Client).to receive(:parse).and_return(client_response)
     end
@@ -53,7 +56,7 @@ RSpec.describe API::V1::PokemonController, type: :controller do
         before { allow(Pokemon).to receive(:create!).and_raise(ActiveRecord::ActiveRecordError.new) }
 
         it 'does not create any new pokemon' do
-          #expect{subject}.to raise_error 'canned failure'
+          # expect{subject}.to raise_error 'canned failure'
           expect{(subject rescue nil)}.to change{Pokemon.count}.by(0)
           expect(response).to render_template 'api/v1/application/_error'
         end
@@ -69,7 +72,6 @@ RSpec.describe API::V1::PokemonController, type: :controller do
           expect(response).to render_template 'api/v1/pokemon/index'
         end
       end
-
     end
 
     context 'parsing fails' do
@@ -87,7 +89,7 @@ RSpec.describe API::V1::PokemonController, type: :controller do
   describe 'GET #show' do
     context 'the pokemon exists' do
       let!(:pokemon) { FactoryBot.create(:pokemon) }
-      subject { get :show, params: {id: pokemon.id}, format: :json }
+      subject { get :show, params: { id: pokemon.id }, format: :json }
 
       it 'renders the pokemon JSON' do
         subject

+ 2 - 0
spec/factories/pokemon_factory.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 FactoryBot.define do
   factory :pokemon do
     pokedex_number { Random.rand(151) }

+ 2 - 3
spec/lib/pkparse/client_spec.rb

@@ -21,17 +21,16 @@ RSpec.describe PKParse::Client do
         before { allow(RestClient).to receive(:post).and_raise(RestClient::Exception.new) }
 
         it 'returns a more specific error' do
-          expect{subject}.to raise_error(PKParse::ResponseError)
+          expect { subject }.to raise_error(PKParse::ResponseError)
         end
       end
 
       context 'processing a response' do
         before { allow(JSON).to receive(:parse).and_raise(JSON::ParserError.new) }
         it 'returns a more specific error' do
-          expect{subject}.to raise_error(PKParse::Error)
+          expect { subject }.to raise_error(PKParse::Error)
         end
       end
     end
   end
 end
-

+ 11 - 9
spec/rails_helper.rb

@@ -1,9 +1,11 @@
+# frozen_string_literal: true
+
 # This file is copied to spec/ when you run 'rails generate rspec:install'
 require 'spec_helper'
 ENV['RAILS_ENV'] ||= 'test'
-require File.expand_path('../../config/environment', __FILE__)
+require File.expand_path('../config/environment', __dir__)
 # Prevent database truncation if the environment is production
-abort("The Rails environment is running in production mode!") if Rails.env.production?
+abort('The Rails environment is running in production mode!') if Rails.env.production?
 require 'rspec/rails'
 # Add additional requires below this line. Rails is not loaded until this point!
 require 'spec_helper'
@@ -66,16 +68,16 @@ RSpec.configure do |config|
 
   # Condtionally swap driver setup, defaults to `:headless_firefox`
   driver = []
-  driver.push("headless") unless ENV["CAPYBARA_GUI_DRIVER"] == 'true'
+  driver.push('headless') unless ENV['CAPYBARA_GUI_DRIVER'] == 'true'
 
-  if ENV["CAPYBARA_JS_DRIVER"] == "chrome"
-    driver.push("chrome")
-  elsif ENV["CAPYBARA_JS_DRIVER"] == "firefox"
-    driver.push("firefox")
+  if ENV['CAPYBARA_JS_DRIVER'] == 'chrome'
+    driver.push('chrome')
+  elsif ENV['CAPYBARA_JS_DRIVER'] == 'firefox'
+    driver.push('firefox')
   else
-    driver.push("firefox")
+    driver.push('firefox')
   end
-  driver = driver.join("_").to_sym
+  driver = driver.join('_').to_sym
 
   config.before(:each, type: :system) do
     driven_by driver

+ 2 - 0
spec/spec_helper.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # This file was generated by the `rails generate rspec:install` command. Conventionally, all
 # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
 # The generated `.rspec` file contains `--require spec_helper` which will cause

+ 2 - 0
spec/systems/pokemon_spec.rb

@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'rails_helper'
 
 RSpec.describe 'Pokemon', type: :system do