Skip to content

Commit

Permalink
Fix remaining RuboCop TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
composerinteralia committed Oct 4, 2018
1 parent 7907b08 commit c84e6b2
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 54 deletions.
25 changes: 1 addition & 24 deletions .rubocop.yml
Expand Up @@ -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
6 changes: 3 additions & 3 deletions 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 -")
20 changes: 10 additions & 10 deletions features/step_definitions/rails_steps.rb
Expand Up @@ -15,20 +15,20 @@
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

Expand Down
13 changes: 9 additions & 4 deletions features/support/env.rb
@@ -1,22 +1,27 @@
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 }
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
Expand Down
6 changes: 5 additions & 1 deletion lib/factory_bot_rails/generators/non_rspec_generator.rb
Expand Up @@ -6,7 +6,11 @@ def initialize(generators)
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
Expand Down
11 changes: 9 additions & 2 deletions lib/factory_bot_rails/generators/rspec_generator.rb
Expand Up @@ -6,7 +6,10 @@ def initialize(generators)
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
Expand All @@ -16,7 +19,11 @@ def fixture_replacement_setting
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
Expand Down
13 changes: 11 additions & 2 deletions lib/generators/factory_bot.rb
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions lib/generators/factory_bot/model/model_generator.rb
Expand Up @@ -53,18 +53,18 @@ def create_factory_file
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

Expand Down

0 comments on commit c84e6b2

Please sign in to comment.