* Alphabetize gem listing in various Gemfiles [Rubocop Bundler/OrderedGems]
* Fix alignment of if/else/end statement [Rubocop Layout/ElseAlignment]
* Method definitions should have a empty line between them [Rubocop Layout/EmptyLineBetweenDefs]
* Modules, Classes, and blocks should have an empty line around them [Rubocop]
Cops:
Layout/EmptyLinesAroundBlockBody
Layout/EmptyLinesAroundModuleBody
Layout/EmptyLinesAroundClassBody
Layout/EmptyLinesAroundAccessModifier
* Keep a blank line before and after access modifiers [Rubocop Layout/EmptyLinesAroundAccessModifier]
* Remove misc extra whitespace [Rubocop Layout/ExtraSpacing]
* Indent the first line of the right-hand-side of a multi-line assignment [Rubocop Layout/IndentAssignment]
* Remove extraneous whitespace [Rubocop]
Cops:
Layout/IndentationWidth
Layout/LeadingCommentSpace
Layout/SpaceAroundEqualsInParameterDefault
Layout/SpaceInsideArrayLiteralBrackets
Layout/SpaceInsideBlockBraces
Layout/SpaceInsideParens
Layout/TrailingBlankLines
* Revert rubocop changes to gemfiles; exclude files from rubocop checks
The files in gemfiles/ are generated by Appraisal, so we shouldn't edit them. Instead, let's tell RuboCop to exclude this directory.
Most of this was fixed by adding the `attribute-defined-statically-cop`
branch of `thoughtbot/rubocop-rspec` to the Gemfile and running:
```sh
rubocop \
--require rubocop-rspec \
--only FactoryBot/AttributeDefinedStatically \
--auto-correct
```
I had to update the cucumber tests manually, and I realized our changes
don't handle `ignore` blocks or blocks with arity 1 that use the yielded
DefinitionProxy. I will update
https://github.com/rubocop-hq/rubocop-rspec/pull/666to handle these
cases.
Instead of calling before_create, after_build, after_create, or
after_stub, you can now call:
before(:create) {|instance| instance.name = "overridden!" }
after(:create) {|instance| instance.name = "overridden!" }
after(:build) {|instance| instance.name = "overridden!" }
after(:stub) {|instance| instance.name = "overridden!" }
Additionally, you can declare callbacks longhand:
callback(:after_stub) {|instance| instance.name = "overridden!" }
This allows for custom callbacks to be defined:
callback(:custom_callback) {|instance| instance.name = "overridden!" }
Which can then be used from a custom strategy:
class CustomStrategy
def association(runner); end
def result(evaluation)
evaluation.object.tap do |instance|
evaluation.notify(:custom_callback, instance)
end
end
end
FactoryGirl.register_strategy(:custom, CustomStrategy)
This would allow for calling:
FactoryGirl.custom(:user)
Which would return the user instance but execute the :custom_callback callback
on the user instance first.
Static attributes must be executed first because dynamic attributes might
rely on them. This is really important when using the :parent relationship.
Previous code didn't work fine in situations like this one:
Factory.define(:generic_user, :class => User) do |u|
u.email { |user| "#{user.name}@example.com }
end
Factory.define(:flavio, :parent => :generic_user) do |u|
u.name "flavio"
end
When building a :user object the previous code would have set the email
attribute and then the name attribute. This results in a user object with
an invalid email address: the 'name' attribute is yet not set while the
'email' attribute is evaluated.
Closes#159