1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot_rails.git synced 2022-11-09 11:49:18 -05:00

Fix remaining RuboCop TODOs

This commit is contained in:
Daniel Colson 2018-09-28 22:34:23 -04:00
parent 7907b085fd
commit c84e6b2aa2
8 changed files with 56 additions and 54 deletions

View file

@ -2,33 +2,10 @@ inherit_from:
- https://raw.githubusercontent.com/thoughtbot/guides/master/style/ruby/.rubocop.yml - https://raw.githubusercontent.com/thoughtbot/guides/master/style/ruby/.rubocop.yml
AllCops: AllCops:
TargetRubyVersion: 2.3
Exclude: Exclude:
- "tmp/**/*" - "tmp/**/*"
- "gemfiles/*" - "gemfiles/*"
Style/EmptyMethod: Style/EmptyMethod:
EnforcedStyle: expanded 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

View file

@ -1,5 +1,5 @@
When /^I run `([^"]+)` with a clean environment$/ do |command| 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 end
# system({'BUNDLE_GEMFILE' => nil}, "cd tmp/aruba/testapp && #{command} && cd -")

View file

@ -15,20 +15,20 @@ When /^I print out "([^"]*)"$/ do |path|
end end
When /^I configure the factories as:$/ do |string| When /^I configure the factories as:$/ do |string|
append_to_file File.join("config", "application.rb"), <<-RUBY append_to_file File.join("config", "application.rb"), <<~RUBY
class Testapp::Application class Testapp::Application
#{string} #{string}
end end
RUBY RUBY
end end
When /^I configure the factories directory as "([^"]+)"$/ do |factory_dir| When /^I configure the factories directory as "([^"]+)"$/ do |factory_dir|
append_to_file File.join("config", "application.rb"), <<-RUBY append_to_file File.join("config", "application.rb"), <<~RUBY
class Testapp::Application class Testapp::Application
config.generators do |g| config.generators do |g|
g.fixture_replacement :factory_bot, :dir => "#{factory_dir}" g.fixture_replacement :factory_bot, :dir => "#{factory_dir}"
end end
end end
RUBY RUBY
end end

View file

@ -1,6 +1,7 @@
require "aruba/cucumber" 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| Aruba.configure do |config|
config.exit_timeout = Integer ENV.fetch("ARUBA_TIMEOUT") { 120 } config.exit_timeout = Integer ENV.fetch("ARUBA_TIMEOUT") { 120 }
@ -8,15 +9,19 @@ end
if RUBY_PLATFORM == "java" if RUBY_PLATFORM == "java"
Aruba.configure do |config| Aruba.configure do |config|
config.before_cmd do |_| config.before_cmd do
set_env("JRUBY_OPTS", "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived # disable JIT since these processes are so short lived
set_env("JRUBY_OPTS", "-X-C #{ENV['JRUBY_OPTS']}")
java_options = ENV["JAVA_OPTS"] java_options = ENV["JAVA_OPTS"]
if 1.size == 4 # 4 for 32 bit java, 8 for 64 bit java. if 1.size == 4 # 4 for 32 bit java, 8 for 64 bit java.
set_env("JAVA_OPTS", "-d32 #{java_options}") set_env("JAVA_OPTS", "-d32 #{java_options}")
else 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 end
end end

View file

@ -6,7 +6,11 @@ module FactoryBotRails
end end
def run 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 end
private private

View file

@ -6,7 +6,10 @@ module FactoryBotRails
end end
def run def run
@generators.fixture_replacement fixture_replacement_setting, dir: factory_bot_directory @generators.fixture_replacement(
fixture_replacement_setting,
dir: factory_bot_directory,
)
end end
private private
@ -16,7 +19,11 @@ module FactoryBotRails
end end
def factory_bot_directory 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 end
end end

View file

@ -4,11 +4,20 @@ module FactoryBot
module Generators module Generators
class Base < Rails::Generators::NamedBase #:nodoc: class Base < Rails::Generators::NamedBase #:nodoc:
def self.source_root 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 end
def explicit_class_option 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 end
end end

View file

@ -53,18 +53,18 @@ module FactoryBot
end end
def factory_definition def factory_definition
<<-RUBY <<~RUBY
factory :#{singular_table_name}#{explicit_class_option} do factory :#{singular_table_name}#{explicit_class_option} do
#{factory_attributes.gsub(/^/, ' ')} #{factory_attributes.gsub(/^/, ' ')}
end end
RUBY RUBY
end end
def single_file_factory_definition def single_file_factory_definition
<<-RUBY <<~RUBY
FactoryBot.define do FactoryBot.define do
#{factory_definition.chomp} #{factory_definition.chomp}
end end
RUBY RUBY
end end