diff --git a/lib/factory_bot/attribute/dynamic.rb b/lib/factory_bot/attribute/dynamic.rb index 753ab65..d0b4cd2 100644 --- a/lib/factory_bot/attribute/dynamic.rb +++ b/lib/factory_bot/attribute/dynamic.rb @@ -16,6 +16,7 @@ module FactoryBot else instance_exec(&block) end raise SequenceAbuseError if FactoryBot::Sequence === value + value } end diff --git a/lib/factory_bot/configuration.rb b/lib/factory_bot/configuration.rb index 1b85d9c..2f29f9c 100644 --- a/lib/factory_bot/configuration.rb +++ b/lib/factory_bot/configuration.rb @@ -24,7 +24,7 @@ module FactoryBot end delegate :to_create, :skip_create, :constructor, :before, :after, - :callback, :callbacks, to: :@definition + :callback, :callbacks, to: :@definition def initialize_with(&block) @definition.define_constructor(&block) diff --git a/lib/factory_bot/linter.rb b/lib/factory_bot/linter.rb index 82ed413..8bb438a 100644 --- a/lib/factory_bot/linter.rb +++ b/lib/factory_bot/linter.rb @@ -72,8 +72,8 @@ module FactoryBot result = [] begin FactoryBot.public_send(factory_strategy, factory.name) - rescue StandardError => error - result |= [FactoryError.new(error, factory)] + rescue StandardError => e + result |= [FactoryError.new(e, factory)] end result end @@ -83,9 +83,9 @@ module FactoryBot factory.definition.defined_traits.map(&:name).each do |trait_name| begin FactoryBot.public_send(factory_strategy, factory.name, trait_name) - rescue StandardError => error + rescue StandardError => e result |= - [FactoryTraitError.new(error, factory, trait_name)] + [FactoryTraitError.new(e, factory, trait_name)] end end result diff --git a/lib/factory_bot/null_factory.rb b/lib/factory_bot/null_factory.rb index e22bab0..9dc1a97 100644 --- a/lib/factory_bot/null_factory.rb +++ b/lib/factory_bot/null_factory.rb @@ -8,7 +8,7 @@ module FactoryBot end delegate :defined_traits, :callbacks, :attributes, :constructor, - :to_create, to: :definition + :to_create, to: :definition def compile; end diff --git a/lib/factory_bot/registry.rb b/lib/factory_bot/registry.rb index f1f2af4..bc5b164 100644 --- a/lib/factory_bot/registry.rb +++ b/lib/factory_bot/registry.rb @@ -21,8 +21,8 @@ module FactoryBot def find(name) @items.fetch(name) - rescue KeyError => key_error - raise key_error_with_custom_message(key_error) + rescue KeyError => e + raise key_error_with_custom_message(e) end alias :[] :find diff --git a/spec/acceptance/attributes_for_spec.rb b/spec/acceptance/attributes_for_spec.rb index 48fa178..cbe37e5 100644 --- a/spec/acceptance/attributes_for_spec.rb +++ b/spec/acceptance/attributes_for_spec.rb @@ -5,8 +5,8 @@ describe "a generated attributes hash" do define_model("User") define_model("Comment") - define_model("Post", title: :string, - body: :string, + define_model("Post", title: :string, + body: :string, summary: :string, user_id: :integer) do belongs_to :user diff --git a/spec/acceptance/attributes_ordered_spec.rb b/spec/acceptance/attributes_ordered_spec.rb index 483f3e6..fe429a4 100644 --- a/spec/acceptance/attributes_ordered_spec.rb +++ b/spec/acceptance/attributes_ordered_spec.rb @@ -2,10 +2,10 @@ describe "a generated attributes hash where order matters" do include FactoryBot::Syntax::Methods before do - define_model("ParentModel", static: :integer, - evaluates_first: :integer, + define_model("ParentModel", static: :integer, + evaluates_first: :integer, evaluates_second: :integer, - evaluates_third: :integer) + evaluates_third: :integer) FactoryBot.define do factory :parent_model do diff --git a/spec/acceptance/build_stubbed_spec.rb b/spec/acceptance/build_stubbed_spec.rb index 2af6bf5..4e3bec4 100644 --- a/spec/acceptance/build_stubbed_spec.rb +++ b/spec/acceptance/build_stubbed_spec.rb @@ -4,9 +4,9 @@ describe "a generated stub instance" do before do define_model("User") - define_model("Post", title: :string, - body: :string, - age: :integer, + define_model("Post", title: :string, + body: :string, + age: :integer, user_id: :integer, draft: :boolean) do belongs_to :user diff --git a/spec/acceptance/overrides_spec.rb b/spec/acceptance/overrides_spec.rb index 34078a9..1653317 100644 --- a/spec/acceptance/overrides_spec.rb +++ b/spec/acceptance/overrides_spec.rb @@ -1,13 +1,14 @@ describe "attribute overrides" do before do - define_model("User", admin: :boolean) - define_model("Post", title: :string, - secure: :boolean, + define_model("User", admin: :boolean) + define_model("Post", title: :string, + secure: :boolean, user_id: :integer) do belongs_to :user def secure=(value) return unless user&.admin? + write_attribute(:secure, value) end end diff --git a/spec/acceptance/traits_spec.rb b/spec/acceptance/traits_spec.rb index 6a96d6b..180d7d8 100644 --- a/spec/acceptance/traits_spec.rb +++ b/spec/acceptance/traits_spec.rb @@ -1,12 +1,12 @@ describe "an instance generated by a factory with multiple traits" do before do define_model("User", - name: :string, - admin: :boolean, - gender: :string, - email: :string, + name: :string, + admin: :boolean, + gender: :string, + email: :string, date_of_birth: :date, - great: :string) + great: :string) FactoryBot.define do factory :user_without_admin_scoping, class: User do diff --git a/spec/support/macros/define_constant.rb b/spec/support/macros/define_constant.rb index e140cf3..aee6400 100644 --- a/spec/support/macros/define_constant.rb +++ b/spec/support/macros/define_constant.rb @@ -25,9 +25,9 @@ module DefineConstantMacros connection.create_table(table_name, &block) created_tables << table_name connection - rescue Exception => exception # rubocop:disable Lint/RescueException + rescue Exception => e # rubocop:disable Lint/RescueException connection.execute("DROP TABLE IF EXISTS #{table_name}") - raise exception + raise e end end @@ -56,7 +56,7 @@ RSpec.configure do |config| config.before(:all) do ActiveRecord::Base.establish_connection( - adapter: "sqlite3", + adapter: "sqlite3", database: ":memory:", ) end