Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Install and configure Rubocop #322

Open
wants to merge 104 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
1d36d4d
Install rubocop and disable all failing rules
paulelliott Mar 13, 2021
8f3999a
Enable Bundler/OrderedGems
paulelliott Mar 13, 2021
2461b1e
Specify 2.5 as minimum required Ruby version
paulelliott Mar 13, 2021
0e12a76
Enable Layout/AssignmentIndentation
paulelliott Mar 13, 2021
7f047ab
Keep RSpec/ExampleLength as a disabled rule
paulelliott Mar 13, 2021
7d609d7
Keep Style/Documentation as a disabled rule
paulelliott Mar 13, 2021
db6e80f
Keep Style/FrozenStringLiteralComment as a disabled rule
paulelliott Mar 13, 2021
adaf273
Enable Layout/BlockAlignment
paulelliott Mar 13, 2021
d6ecc75
Enable Layout/DotPosition
paulelliott Mar 13, 2021
cb06b27
Enable Layout/EmptyLineAfterGuardClause
paulelliott Mar 13, 2021
04a38c9
Enable Layout/EmptyLineAfterMagicComment
paulelliott Mar 13, 2021
30d6066
Enable Layout/EmptyLineBetweenDefs
paulelliott Mar 13, 2021
0d4ece8
Enable Layout/EmptyLines
paulelliott Mar 13, 2021
03605d4
Enable Layout/EmptyLinesAroundAttributeAccessor
paulelliott Mar 13, 2021
a623b4a
Enable Layout/EmptyLinesAroundBlockBody
paulelliott Mar 13, 2021
c38a778
Enable Layout/EmptyLinesAroundClassBody
paulelliott Mar 13, 2021
723f693
Enable Layout/EmptyLinesAroundModuleBody
paulelliott Mar 13, 2021
c7a2800
Enable Layout/ExtraSpacing
paulelliott Mar 13, 2021
9deabcf
Enable Layout/FirstHashElementIndentation
paulelliott Mar 13, 2021
d68f824
Enable Layout/IndentationWidth
paulelliott Mar 13, 2021
0935337
Enable Layout/LineLength
paulelliott Mar 13, 2021
22aa27a
Enable Layout/SpaceAfterComma
paulelliott Mar 13, 2021
505f107
Install and enable rubocop-rake
paulelliott Mar 13, 2021
e61f3e7
Enable Layout/SpaceAroundEqualsInParameterDefault
paulelliott Mar 13, 2021
e0ba6bc
Enable Layout/SpaceAroundOperators
paulelliott Mar 13, 2021
b9be0bc
Enable Layout/SpaceBeforeBlockBraces
paulelliott Mar 13, 2021
2815389
Enable Layout/SpaceInsideArrayLiteralBrackets
paulelliott Mar 13, 2021
1675f69
Enable Layout/SpaceInsideBlockBraces
paulelliott Mar 13, 2021
2c41bd1
Enable Layout/SpaceInsideHashLiteralBraces
paulelliott Mar 13, 2021
5d1cdb8
Enable Lint/AmbiguousBlockAssociation
paulelliott Mar 13, 2021
29b6444
Enable Lint/AmbiguousRegexpLiteral
paulelliott Mar 13, 2021
19c7e34
Enable Lint/AssignmentInCondition
paulelliott Mar 13, 2021
47c3529
Exclude spec from Lint/ConstantDefinitionInBlock and keep rule
paulelliott Mar 13, 2021
8b0a741
Enable Lint/EmptyBlock excluding Appraisals
paulelliott Mar 13, 2021
3b64311
Enable Lint/EmptyClass excluding specs
paulelliott Mar 13, 2021
374bf97
Enable Lint/IneffectiveAccessModifier
paulelliott Mar 13, 2021
8310fb1
Enable Lint/MissingSuper
paulelliott Mar 14, 2021
67879a9
Enable Lint/NonDeterministicRequireOrder
paulelliott Mar 14, 2021
c3c9bc8
Enable Lint/ParenthesesAsGroupedExpression
paulelliott Mar 14, 2021
7d8bf2f
Enable Lint/RedundantDirGlobSort
paulelliott Mar 14, 2021
4586066
Enable Lint/RedundantStringCoercion
paulelliott Mar 14, 2021
21b29e8
Enable Lint/RescueException
paulelliott Mar 14, 2021
4726d34
Enable Lint/ShadowingOuterLocalVariable
paulelliott Mar 14, 2021
91395d4
Enable Lint/UnusedBlockArgument
paulelliott Mar 14, 2021
820d1cf
Enable Lint/UnusedMethodArgument
paulelliott Mar 14, 2021
5e2284f
Enable Lint/UselessAccessModifier
paulelliott Mar 14, 2021
9f63a0e
Enable Lint/Void except for object_verification_steps
paulelliott Mar 14, 2021
d1cbae1
Enable Metrics/BlockLength except for specs
paulelliott Mar 14, 2021
128a02d
Enable Naming/MemoizedInstanceVariableName
paulelliott Mar 14, 2021
3d7eac6
Enable Naming/MethodName except for fabrication.rb
paulelliott Mar 14, 2021
2194d92
Enable Naming/PredicateName except for step_fabricator.rb
paulelliott Mar 14, 2021
4c82448
Enable Naming/RescuedExceptionsVariableName
paulelliott Mar 14, 2021
d1bc213
Enable Naming/VariableName
paulelliott Mar 14, 2021
d29b240
Enable Style/WordArray
paulelliott Mar 14, 2021
ae86800
Enable Style/SymbolProc
paulelliott Mar 14, 2021
be8c587
Enable Style/SymbolArray
paulelliott Mar 14, 2021
cccda04
Enable Style/StructInheritance
paulelliott Mar 14, 2021
3956ebf
Enable Style/StringLiterals
paulelliott Mar 14, 2021
6b78e4a
Enable Style/SpecialGlobalVars
paulelliott Mar 14, 2021
a3a2d3e
Enable Style/SingleLineMethods
paulelliott Mar 14, 2021
8177be1
Enable Style/SafeNavigation
paulelliott Mar 14, 2021
30a5bae
Enable Style/RescueStandardError
paulelliott Mar 14, 2021
dc97aed
Enable Style/RegexpLiteral
paulelliott Mar 14, 2021
1b740a8
Remove exclusion from Lint/EmptyBlock
paulelliott Mar 14, 2021
bf48f27
Enable Style/RedundantBegin
paulelliott Mar 14, 2021
f1ec777
Enable Style/RaiseArgs
paulelliott Mar 14, 2021
88952ba
Enable Style/Proc
paulelliott Mar 14, 2021
2f4e584
Enable Style/PreferredHashMethods
paulelliott Mar 14, 2021
4538735
Enable Style/PerlBackrefs
paulelliott Mar 14, 2021
8410c1f
Enable Style/PercentLiteralDelimiters
paulelliott Mar 14, 2021
0b45311
Enable Style/NumericLiterals
paulelliott Mar 14, 2021
034527e
Enable Style/MultilineTernaryOperator
paulelliott Mar 14, 2021
26aa181
Enable Style/Lambda
paulelliott Mar 14, 2021
e14589c
Enable Style/IfUnlessModifier
paulelliott Mar 14, 2021
643f487
Enable Style/HashSyntax
paulelliott Mar 14, 2021
607cfe8
Enable Style/ExpandPathArguments
paulelliott Mar 14, 2021
f91b02b
Enable Style/Encoding
paulelliott Mar 14, 2021
e7ea669
Enable Style/EmptyLiteral
paulelliott Mar 14, 2021
21b28c0
Enable Style/ConditionalAssignment
paulelliott Mar 14, 2021
7c467fc
Enable Style/ClassVars
paulelliott Mar 14, 2021
3e45dab
Enable Style/ClassCheck
paulelliott Mar 14, 2021
22a5adb
Enable Style/CaseEquality
paulelliott Mar 14, 2021
2d9d5b3
Enable Style/BlockDelimiters
paulelliott Mar 14, 2021
aa09af9
Enable Style/ArgumentsForwarding
paulelliott Mar 14, 2021
715c33c
Enable Style/AccessorGrouping
paulelliott Mar 14, 2021
e6864ee
Enable RSpec/Be
paulelliott Mar 14, 2021
e4d0c24
Enable RSpec/BeforeAfterAll
paulelliott Mar 14, 2021
3d933a8
Enable RSpec/EmptyLineAfterExample
paulelliott Mar 14, 2021
8175a95
Enable RSpec/EmptyLineAfterFinalLet
paulelliott Mar 14, 2021
27808b9
Enable RSpec/EmptyLineAfterHook
paulelliott Mar 14, 2021
ad069b9
Enable RSpec/EmptyLineAfterSubject
paulelliott Mar 14, 2021
212d6a1
Enable RSpec/EmptyLineAfterExampleGroup
paulelliott Mar 14, 2021
c132106
Enable RSpec/HookArgument
paulelliott Mar 14, 2021
f59cd3b
Enable RSpec/HooksBeforeExamples
paulelliott Mar 14, 2021
03050e4
Enable RSpec/NotToNot
paulelliott Mar 14, 2021
b3a49c1
Keep RSpec/MultipleExpectations disabled
paulelliott Mar 14, 2021
a510da0
Enable RSpec/LeadingSubject
paulelliott Mar 14, 2021
c23b1c5
Enable RSpec/ItBehavesLike
paulelliott Mar 14, 2021
8da243c
Keep RSpec/NestedGroups disabled
paulelliott Mar 14, 2021
9b98523
Enable RSpec/ExampleWording
paulelliott Mar 14, 2021
d414610
Enable RSpec/MultipleDescribes
paulelliott Mar 14, 2021
fe577d6
Enable RSpec/DescribedClass
paulelliott Mar 14, 2021
757aa05
Enable RSpec/ContextWording
paulelliott Mar 14, 2021
3096eae
Enable RSpec/NamedSubject
paulelliott Mar 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require:
- rubocop-rake
- rubocop-rspec

AllCops:
Exclude:
- gemfiles/*
NewCops: enable
TargetRubyVersion: 2.5

Lint/ConstantDefinitionInBlock:
Exclude:
- spec/**/*
Lint/EmptyClass:
Exclude:
- spec/**/*
Lint/Void:
Exclude:
- features/step_definitions/object_verification_steps.rb

Metrics/BlockLength:
Exclude:
- spec/**/*

Naming/MethodName:
Exclude:
- lib/fabrication.rb
Naming/PredicateName:
Exclude:
- lib/fabrication/cucumber/step_fabricator.rb

RSpec/ExampleLength:
Enabled: false
RSpec/MultipleExpectations:
Enabled: false
RSpec/NestedGroups:
Enabled: false

Style/Documentation:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: false

Metrics/AbcSize:
Enabled: False
Metrics/ClassLength:
Enabled: False
Metrics/CyclomaticComplexity:
Enabled: False
Metrics/MethodLength:
Enabled: False
Metrics/PerceivedComplexity:
Enabled: False
RSpec/ImplicitExpect:
Enabled: False
RSpec/ImplicitSubject:
Enabled: False
RSpec/LeakyConstantDeclaration:
Enabled: False
RSpec/MessageSpies:
Enabled: False
RSpec/StubbedMock:
Enabled: False
RSpec/VerifiedDoubles:
Enabled: False
Style/ClassAndModuleChildren:
Enabled: False
Style/MissingRespondToMissing:
Enabled: False
Style/ModuleFunction:
Enabled: False
Style/MultilineBlockChain:
Enabled: False
Style/MutableConstant:
Enabled: False
1 change: 1 addition & 0 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ appraise 'kitchen-sink' do
end

appraise 'blank-slate' do
# this simulates requiring fabrication with no known frameworks present
end

appraise 'rails-6.1' do
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ gem 'pry'
gem 'rake'
gem 'rspec'
gem 'rspec-its'
gem 'rubocop-rake', require: false
gem 'rubocop-rspec', require: false
gem 'sqlite3'
27 changes: 27 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ GEM
bundler
rake
thor (>= 0.14.0)
ast (2.4.2)
backports (3.8.0)
builder (3.2.3)
coderay (1.1.2)
Expand All @@ -35,10 +36,16 @@ GEM
method_source (0.9.0)
multi_json (1.12.2)
multi_test (0.1.2)
parallel (1.20.1)
parser (3.0.0.0)
ast (~> 2.4.1)
pry (0.11.1)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rainbow (3.0.0)
rake (12.1.0)
regexp_parser (2.1.1)
rexml (3.2.4)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
Expand All @@ -55,8 +62,26 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
rubocop (1.11.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.2.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.4.1)
parser (>= 2.7.1.5)
rubocop-rake (0.5.1)
rubocop
rubocop-rspec (2.2.0)
rubocop (~> 1.0)
rubocop-ast (>= 1.1.0)
ruby-progressbar (1.11.0)
sqlite3 (1.3.13)
thor (0.20.0)
unicode-display_width (2.0.0)

PLATFORMS
ruby
Expand All @@ -70,6 +95,8 @@ DEPENDENCIES
rake
rspec
rspec-its
rubocop-rake
rubocop-rspec
sqlite3

BUNDLED WITH
Expand Down
16 changes: 7 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
require "rubygems"
require "bundler/setup"
require 'rubygems'
require 'bundler/setup'

Bundler.require

require "rspec/core/rake_task"
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = "spec/**/*_spec.rb"
spec.pattern = 'spec/**/*_spec.rb'
end

desc 'All cucumber features with kitchen sink appraisal'
task :cucumber do
system('appraisal kitchen-sink cucumber -f progress')
end

if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
task default: [:cucumber, :appraisal]
else
task default: :spec
end
default_task = !ENV['APPRAISAL_INITIALIZED'] && !ENV['TRAVIS'] ? %i[cucumber appraisal] : :spec

task default: default_task
26 changes: 13 additions & 13 deletions fabrication.gemspec
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib/', __FILE__)
$:.unshift lib unless $:.include?(lib)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)

require 'fabrication/version'

Gem::Specification.new do |s|
s.name = "fabrication"
s.name = 'fabrication'
s.version = Fabrication::VERSION
s.license = "MIT"
s.license = 'MIT'

s.authors = ["Paul Elliott"]
s.email = ["[email protected]"]
s.description = "Fabrication is an object generation framework for ActiveRecord, Mongoid, DataMapper, Sequel, or any other Ruby object."
s.authors = ['Paul Elliott']
s.email = ['[email protected]']
s.description = 'Fabrication is an object generation framework for ActiveRecord, ' \
'Mongoid, DataMapper, Sequel, or any other Ruby object.'

s.homepage = "http://fabricationgem.org"
s.require_paths = ["lib"]
s.rubygems_version = "1.3.7"
s.homepage = 'http://fabricationgem.org'
s.require_paths = ['lib']
s.rubygems_version = '1.3.7'
s.summary = "Implementing the factory pattern in Ruby so you don't have to."

s.required_ruby_version = '>= 2.2.0'
s.required_ruby_version = '>= 2.5.0'

s.files = Dir.glob("lib/**/*") + %w(LICENSE README.markdown Rakefile)
s.files = Dir.glob('lib/**/*') + %w[LICENSE README.markdown Rakefile]
s.require_path = 'lib'
end
21 changes: 10 additions & 11 deletions features/step_definitions/object_verification_steps.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
ORDINALS = {
"first" => 0,
"second" => 1
'first' => 0,
'second' => 1
}

def dehumanize(string)
string.gsub(/\W+/,'_').downcase
string.gsub(/\W+/, '_').downcase
end

def generate_fabricator_name(model_name)
Expand All @@ -16,26 +16,25 @@ def get_class(model_name)
Fabrication.manager[fabricator_name].send(:klass)
end


Then /^that ([^"]*) should be persisted$/ do |object_name|
Then(/^that ([^"]*) should be persisted$/) do |object_name|
object_name = dehumanize(object_name)
object = fabrications[object_name]
object.should be_persisted
end

Then /^that ([^"]*) should have "([^"]*)" for a "([^"]*)"$/ do |object_name, value, field|
Then(/^that ([^"]*) should have "([^"]*)" for a "([^"]*)"$/) do |object_name, value, field|
object_name = dehumanize(object_name)
object = fabrications[object_name]
object.send(dehumanize(field)).to_s.should == value
end

Then /^they should be persisted$/ do
Then(/^they should be persisted$/) do
@they.each do |object|
object.should be_persisted
end
end

Then /^they should reference that ([^"]*)$/ do |parent_name|
Then(/^they should reference that ([^"]*)$/) do |parent_name|
parent_name = dehumanize(parent_name)
parent = fabrications[parent_name]
parent_class = get_class(parent_name)
Expand All @@ -46,12 +45,12 @@ def get_class(model_name)
end
end

Then /^the ([^"]*) should have "([^"]*)" for a "([^"]*)"$/ do |ordindal, value, field|
Then(/^the ([^"]*) should have "([^"]*)" for a "([^"]*)"$/) do |ordindal, value, field|
object = @they[ORDINALS[ordindal]]
object.send(dehumanize(field)).to_s.should == value
end

Then /^that ([^"]*) should reference that ([^"]*)$/ do |child_name, parent_name|
Then(/^that ([^"]*) should reference that ([^"]*)$/) do |child_name, parent_name|
parent_name = dehumanize(parent_name)
parent = fabrications[parent_name]
parent_class = get_class(parent_name)
Expand All @@ -61,7 +60,7 @@ def get_class(model_name)
child.send(parent_class_name).should == parent
end

Then /^that (.*) should have (\d+) (.*)$/ do |parent_name, count, child_name|
Then(/^that (.*) should have (\d+) (.*)$/) do |parent_name, count, child_name|
parent_name = dehumanize(parent_name)
parent = fabrications[parent_name]
parent.send(dehumanize(child_name).pluralize).count.should == count.to_i
Expand Down
12 changes: 5 additions & 7 deletions features/step_definitions/other_steps.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
When /^I try to fabricate "([^"]*)"$/ do |fabricator_name|
When(/^I try to fabricate "([^"]*)"$/) do |fabricator_name|
@fabricator_name = fabricator_name
end

Then /^it should tell me that it isn't defined$/ do
begin
step "1 #{@fabricator_name}"
rescue Exception => e
e.message.should == "No Fabricator defined for '#{@fabricator_name}'"
end
Then(/^it should tell me that it isn't defined$/) do
step "1 #{@fabricator_name}"
rescue StandardError => e
e.message.should == "No Fabricator defined for '#{@fabricator_name}'"
end
4 changes: 3 additions & 1 deletion features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

Bundler.require(:default, :development)

Dir[File.expand_path(File.join(File.dirname(__FILE__),'..','..','spec','support','**','*.rb'))].each {|f| require f}
Dir[File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec', 'support', '**', '*.rb'))].sort.each do |f|
require f
end
load 'lib/rails/generators/fabrication/cucumber_steps/templates/fabrication_steps.rb'

Before do
Expand Down
23 changes: 10 additions & 13 deletions lib/fabricate.rb
Original file line number Diff line number Diff line change
@@ -1,51 +1,48 @@
class Fabricate
def self.times(count, name, overrides={}, &block)
def self.times(count, name, overrides = {}, &block)
count.times.map { Fabricate(name, overrides, &block) }
end

def self.build_times(count, name, overrides={}, &block)
def self.build_times(count, name, overrides = {}, &block)
count.times.map { Fabricate.build(name, overrides, &block) }
end

def self.attributes_for_times(count, name, overrides={}, &block)
def self.attributes_for_times(count, name, overrides = {}, &block)
count.times.map { Fabricate.attributes_for(name, overrides, &block) }
end

def self.attributes_for(name, overrides={}, &block)
def self.attributes_for(name, overrides = {}, &block)
fail_if_initializing(name)
schematic(name).to_attributes(overrides, &block)
end

def self.to_params(name, overrides={}, &block)
def self.to_params(name, overrides = {}, &block)
fail_if_initializing(name)
schematic(name).to_params(overrides, &block)
end

def self.build(name, overrides={}, &block)
def self.build(name, overrides = {}, &block)
fail_if_initializing(name)
schematic(name).build(overrides, &block).tap do |object|
Fabrication::Cucumber::Fabrications[name] = object if Fabrication::Config.register_with_steps?
end
end

def self.create(name, overrides={}, &block)
def self.create(name, overrides = {}, &block)
fail_if_initializing(name)
schematic(name).fabricate(overrides, &block)
end

def self.sequence(name=Fabrication::Sequencer::DEFAULT, start=nil, &block)
def self.sequence(name = Fabrication::Sequencer::DEFAULT, start = nil, &block)
Fabrication::Sequencer.sequence(name, start, &block)
end

def self.schematic(name)
Fabrication.manager.load_definitions if Fabrication.manager.empty?
Fabrication.manager[name] || raise(Fabrication::UnknownFabricatorError.new(name))
Fabrication.manager[name] || raise(Fabrication::UnknownFabricatorError, name)
end

private

def self.fail_if_initializing(name)
raise Fabrication::MisplacedFabricateError.new(name) if Fabrication.manager.initializing?
raise Fabrication::MisplacedFabricateError, name if Fabrication.manager.initializing?
end

end
7 changes: 4 additions & 3 deletions lib/fabrication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ def self.manager
end

def self.schematics
puts "DEPRECATION WARNING: Fabrication.schematics has been replaced by Fabrication.manager and will be removed in 3.0.0."
puts 'DEPRECATION WARNING: Fabrication.schematics has been replaced by Fabrication.manager' \
' and will be removed in 3.0.0.'
manager
end
end

def Fabricator(name, options={}, &block)
def Fabricator(name, options = {}, &block)
Fabrication.manager.register(name, options, &block)
end

def Fabricate(name, overrides={}, &block)
def Fabricate(name, overrides = {}, &block)
Fabricate.create(name, overrides, &block).tap do |object|
Fabrication::Cucumber::Fabrications[name] = object if Fabrication::Config.register_with_steps?
end
Expand Down
Loading