diff --git a/.rubocop.yml b/.rubocop.yml index d01e468..f3705f5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,33 +2,10 @@ inherit_from: - https://raw.githubusercontent.com/thoughtbot/guides/master/style/ruby/.rubocop.yml AllCops: + TargetRubyVersion: 2.3 Exclude: - "tmp/**/*" - "gemfiles/*" Style/EmptyMethod: EnforcedStyle: expanded - -# TODO: -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2018-09-17 20:19:38 -0400 using RuboCop version 0.54.0. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent -Layout/IndentHeredoc: - Exclude: - - 'features/step_definitions/rails_steps.rb' - - 'lib/generators/factory_bot/model/model_generator.rb' - -# Offense count: 11 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Metrics/LineLength: - Max: 133 diff --git a/features/step_definitions/appraisal.rb b/features/step_definitions/appraisal.rb index 94dade4..eef03c7 100644 --- a/features/step_definitions/appraisal.rb +++ b/features/step_definitions/appraisal.rb @@ -1,5 +1,5 @@ When /^I run `([^"]+)` with a clean environment$/ do |command| - step %{I successfully run `ruby -e 'system({"BUNDLE_GEMFILE" => nil, "DISABLE_SPRING" => "true"}, "#{command}")'`} + step <<~STEP + I successfully run `ruby -e 'system({"BUNDLE_GEMFILE" => nil, "DISABLE_SPRING" => "true"}, "#{command}")'` + STEP end - -# system({'BUNDLE_GEMFILE' => nil}, "cd tmp/aruba/testapp && #{command} && cd -") diff --git a/features/step_definitions/rails_steps.rb b/features/step_definitions/rails_steps.rb index 92b0177..9170b09 100644 --- a/features/step_definitions/rails_steps.rb +++ b/features/step_definitions/rails_steps.rb @@ -15,20 +15,20 @@ When /^I print out "([^"]*)"$/ do |path| end When /^I configure the factories as:$/ do |string| - append_to_file File.join("config", "application.rb"), <<-RUBY -class Testapp::Application - #{string} -end + append_to_file File.join("config", "application.rb"), <<~RUBY + class Testapp::Application + #{string} + end RUBY end When /^I configure the factories directory as "([^"]+)"$/ do |factory_dir| - append_to_file File.join("config", "application.rb"), <<-RUBY -class Testapp::Application - config.generators do |g| - g.fixture_replacement :factory_bot, :dir => "#{factory_dir}" - end -end + append_to_file File.join("config", "application.rb"), <<~RUBY + class Testapp::Application + config.generators do |g| + g.fixture_replacement :factory_bot, :dir => "#{factory_dir}" + end + end RUBY end diff --git a/features/support/env.rb b/features/support/env.rb index 80ac5fb..d234143 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,6 +1,7 @@ require "aruba/cucumber" -PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "..", "..")).freeze +PROJECT_ROOT = + File.expand_path(File.join(File.dirname(__FILE__), "..", "..")).freeze Aruba.configure do |config| config.exit_timeout = Integer ENV.fetch("ARUBA_TIMEOUT") { 120 } @@ -8,15 +9,19 @@ end if RUBY_PLATFORM == "java" Aruba.configure do |config| - config.before_cmd do |_| - set_env("JRUBY_OPTS", "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived + config.before_cmd do + # disable JIT since these processes are so short lived + set_env("JRUBY_OPTS", "-X-C #{ENV['JRUBY_OPTS']}") java_options = ENV["JAVA_OPTS"] if 1.size == 4 # 4 for 32 bit java, 8 for 64 bit java. set_env("JAVA_OPTS", "-d32 #{java_options}") else - set_env("JAVA_OPTS", "-XX:+TieredCompilation -XX:TieredStopAtLevel=1 #{java_options}") + set_env( + "JAVA_OPTS", + "-XX:+TieredCompilation -XX:TieredStopAtLevel=1 #{java_options}", + ) end end end diff --git a/lib/factory_bot_rails/generators/non_rspec_generator.rb b/lib/factory_bot_rails/generators/non_rspec_generator.rb index 0aa7d5d..7d2d770 100644 --- a/lib/factory_bot_rails/generators/non_rspec_generator.rb +++ b/lib/factory_bot_rails/generators/non_rspec_generator.rb @@ -6,7 +6,11 @@ module FactoryBotRails end def run - @generators.test_framework test_framework, fixture: false, fixture_replacement: :factory_bot + @generators.test_framework( + test_framework, + fixture: false, + fixture_replacement: :factory_bot, + ) end private diff --git a/lib/factory_bot_rails/generators/rspec_generator.rb b/lib/factory_bot_rails/generators/rspec_generator.rb index 9718b77..96dde63 100644 --- a/lib/factory_bot_rails/generators/rspec_generator.rb +++ b/lib/factory_bot_rails/generators/rspec_generator.rb @@ -6,7 +6,10 @@ module FactoryBotRails end def run - @generators.fixture_replacement fixture_replacement_setting, dir: factory_bot_directory + @generators.fixture_replacement( + fixture_replacement_setting, + dir: factory_bot_directory, + ) end private @@ -16,7 +19,11 @@ module FactoryBotRails end def factory_bot_directory - @generators.options.fetch(:factory_bot, {}).fetch(:dir, "spec/factories") + factory_bot_options.fetch(:dir, "spec/factories") + end + + def factory_bot_options + @generators.options.fetch(:factory_bot, {}) end end end diff --git a/lib/generators/factory_bot.rb b/lib/generators/factory_bot.rb index 650e79b..7a80f45 100644 --- a/lib/generators/factory_bot.rb +++ b/lib/generators/factory_bot.rb @@ -4,11 +4,20 @@ module FactoryBot module Generators class Base < Rails::Generators::NamedBase #:nodoc: def self.source_root - File.expand_path(File.join(File.dirname(__FILE__), "factory_bot", generator_name, "templates")) + path = File.join( + File.dirname(__FILE__), + "factory_bot", + generator_name, + "templates", + ) + + File.expand_path(path) end def explicit_class_option - ", class: '#{class_name}'" unless class_name == singular_table_name.camelize + return if class_name == singular_table_name.camelize + + ", class: '#{class_name}'" end end end diff --git a/lib/generators/factory_bot/model/model_generator.rb b/lib/generators/factory_bot/model/model_generator.rb index 2e6ed96..1abb4d1 100644 --- a/lib/generators/factory_bot/model/model_generator.rb +++ b/lib/generators/factory_bot/model/model_generator.rb @@ -53,18 +53,18 @@ module FactoryBot end def factory_definition - <<-RUBY - factory :#{singular_table_name}#{explicit_class_option} do -#{factory_attributes.gsub(/^/, ' ')} - end + <<~RUBY + factory :#{singular_table_name}#{explicit_class_option} do + #{factory_attributes.gsub(/^/, ' ')} + end RUBY end def single_file_factory_definition - <<-RUBY -FactoryBot.define do -#{factory_definition.chomp} -end + <<~RUBY + FactoryBot.define do + #{factory_definition.chomp} + end RUBY end