Rubocop: Fix Style/StringLiterals Offenses (#1216)
This commit is contained in:
parent
89ee4a4524
commit
c22c9ab052
|
@ -66,13 +66,6 @@ Style/MethodMissing:
|
|||
- 'lib/factory_bot/definition_proxy.rb'
|
||||
- 'lib/factory_bot/evaluator.rb'
|
||||
|
||||
# Offense count: 308
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
||||
# SupportedStyles: single_quotes, double_quotes
|
||||
Style/StringLiterals:
|
||||
Enabled: false
|
||||
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: MinSize.
|
||||
# SupportedStyles: percent, brackets
|
||||
|
|
16
Appraisals
16
Appraisals
|
@ -1,15 +1,15 @@
|
|||
appraise '4.2' do
|
||||
gem 'activerecord', "~> 4.2.5.1"
|
||||
appraise "4.2" do
|
||||
gem "activerecord", "~> 4.2.5.1"
|
||||
end
|
||||
|
||||
appraise '5.0' do
|
||||
gem 'activerecord', "~> 5.0.0"
|
||||
appraise "5.0" do
|
||||
gem "activerecord", "~> 5.0.0"
|
||||
end
|
||||
|
||||
appraise '5.1' do
|
||||
gem 'activerecord', "~> 5.1.0"
|
||||
appraise "5.1" do
|
||||
gem "activerecord", "~> 5.1.0"
|
||||
end
|
||||
|
||||
appraise '5.2' do
|
||||
gem 'activerecord', "~> 5.2.0"
|
||||
appraise "5.2" do
|
||||
gem "activerecord", "~> 5.2.0"
|
||||
end
|
||||
|
|
12
Gemfile
12
Gemfile
|
@ -1,10 +1,10 @@
|
|||
source 'https://rubygems.org'
|
||||
source "https://rubygems.org"
|
||||
|
||||
gemspec name: 'factory_bot'
|
||||
gemspec name: "factory_bot"
|
||||
|
||||
gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
|
||||
gem 'jdbc-sqlite3', platforms: :jruby
|
||||
gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
|
||||
gem "jdbc-sqlite3", platforms: :jruby
|
||||
|
||||
gem 'sqlite3', '~> 1.3.10', platforms: :ruby
|
||||
gem "sqlite3", "~> 1.3.10", platforms: :ruby
|
||||
|
||||
gem 'rubocop', '0.54', require: false
|
||||
gem "rubocop", "0.54", require: false
|
||||
|
|
30
Rakefile
30
Rakefile
|
@ -1,34 +1,34 @@
|
|||
require 'rubygems'
|
||||
require 'bundler'
|
||||
require 'rake'
|
||||
require 'appraisal'
|
||||
require 'yard'
|
||||
require 'rspec/core/rake_task'
|
||||
require 'cucumber/rake/task'
|
||||
require "rubygems"
|
||||
require "bundler"
|
||||
require "rake"
|
||||
require "appraisal"
|
||||
require "yard"
|
||||
require "rspec/core/rake_task"
|
||||
require "cucumber/rake/task"
|
||||
|
||||
Bundler::GemHelper.install_tasks(name: 'factory_bot')
|
||||
Bundler::GemHelper.install_tasks(name: "factory_bot")
|
||||
|
||||
desc 'Default: run the specs and features.'
|
||||
desc "Default: run the specs and features."
|
||||
task default: %w(spec:unit spec:acceptance features)
|
||||
|
||||
namespace :spec do
|
||||
desc "Run unit specs"
|
||||
RSpec::Core::RakeTask.new('unit') do |t|
|
||||
t.pattern = 'spec/{*_spec.rb,factory_bot/**/*_spec.rb}'
|
||||
RSpec::Core::RakeTask.new("unit") do |t|
|
||||
t.pattern = "spec/{*_spec.rb,factory_bot/**/*_spec.rb}"
|
||||
end
|
||||
|
||||
desc "Run acceptance specs"
|
||||
RSpec::Core::RakeTask.new('acceptance') do |t|
|
||||
t.pattern = 'spec/acceptance/**/*_spec.rb'
|
||||
RSpec::Core::RakeTask.new("acceptance") do |t|
|
||||
t.pattern = "spec/acceptance/**/*_spec.rb"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Run the unit and acceptance specs"
|
||||
task spec: ['spec:unit', 'spec:acceptance']
|
||||
task spec: ["spec:unit", "spec:acceptance"]
|
||||
|
||||
Cucumber::Rake::Task.new(:features) do |t|
|
||||
t.fork = true
|
||||
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
|
||||
t.cucumber_opts = ["--format", (ENV["CUCUMBER_FORMAT"] || "progress")]
|
||||
end
|
||||
|
||||
YARD::Rake::YardocTask.new do |t|
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
$LOAD_PATH << File.expand_path('lib', __dir__)
|
||||
$LOAD_PATH << File.expand_path("lib", __dir__)
|
||||
require "factory_bot/version"
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
||||
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
|
||||
|
||||
require "simplecov"
|
||||
|
||||
$: << File.join(PROJECT_ROOT, 'lib')
|
||||
$: << File.join(PROJECT_ROOT, "lib")
|
||||
|
||||
require 'active_record'
|
||||
require 'factory_bot'
|
||||
require "active_record"
|
||||
require "factory_bot"
|
||||
|
||||
require 'aruba/cucumber'
|
||||
require "aruba/cucumber"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
ActiveRecord::Base.establish_connection(
|
||||
adapter: 'sqlite3',
|
||||
database: File.join(File.dirname(__FILE__), 'test.db'),
|
||||
adapter: "sqlite3",
|
||||
database: File.join(File.dirname(__FILE__), "test.db"),
|
||||
)
|
||||
|
||||
migration_class =
|
||||
|
|
|
@ -1,50 +1,50 @@
|
|||
require 'set'
|
||||
require 'active_support/core_ext/module/delegation'
|
||||
require 'active_support/deprecation'
|
||||
require 'active_support/notifications'
|
||||
require "set"
|
||||
require "active_support/core_ext/module/delegation"
|
||||
require "active_support/deprecation"
|
||||
require "active_support/notifications"
|
||||
|
||||
require 'factory_bot/definition_hierarchy'
|
||||
require 'factory_bot/configuration'
|
||||
require 'factory_bot/errors'
|
||||
require 'factory_bot/factory_runner'
|
||||
require 'factory_bot/strategy_syntax_method_registrar'
|
||||
require 'factory_bot/strategy_calculator'
|
||||
require 'factory_bot/strategy/build'
|
||||
require 'factory_bot/strategy/create'
|
||||
require 'factory_bot/strategy/attributes_for'
|
||||
require 'factory_bot/strategy/stub'
|
||||
require 'factory_bot/strategy/null'
|
||||
require 'factory_bot/registry'
|
||||
require 'factory_bot/null_factory'
|
||||
require 'factory_bot/null_object'
|
||||
require 'factory_bot/evaluation'
|
||||
require 'factory_bot/factory'
|
||||
require 'factory_bot/attribute_assigner'
|
||||
require 'factory_bot/evaluator'
|
||||
require 'factory_bot/evaluator_class_definer'
|
||||
require 'factory_bot/attribute'
|
||||
require 'factory_bot/callback'
|
||||
require 'factory_bot/callbacks_observer'
|
||||
require 'factory_bot/declaration_list'
|
||||
require 'factory_bot/declaration'
|
||||
require 'factory_bot/sequence'
|
||||
require 'factory_bot/attribute_list'
|
||||
require 'factory_bot/trait'
|
||||
require 'factory_bot/aliases'
|
||||
require 'factory_bot/definition'
|
||||
require 'factory_bot/definition_proxy'
|
||||
require 'factory_bot/syntax'
|
||||
require 'factory_bot/syntax_runner'
|
||||
require 'factory_bot/find_definitions'
|
||||
require 'factory_bot/reload'
|
||||
require 'factory_bot/decorator'
|
||||
require 'factory_bot/decorator/attribute_hash'
|
||||
require 'factory_bot/decorator/class_key_hash'
|
||||
require 'factory_bot/decorator/disallows_duplicates_registry'
|
||||
require 'factory_bot/decorator/invocation_tracker'
|
||||
require 'factory_bot/decorator/new_constructor'
|
||||
require 'factory_bot/linter'
|
||||
require 'factory_bot/version'
|
||||
require "factory_bot/definition_hierarchy"
|
||||
require "factory_bot/configuration"
|
||||
require "factory_bot/errors"
|
||||
require "factory_bot/factory_runner"
|
||||
require "factory_bot/strategy_syntax_method_registrar"
|
||||
require "factory_bot/strategy_calculator"
|
||||
require "factory_bot/strategy/build"
|
||||
require "factory_bot/strategy/create"
|
||||
require "factory_bot/strategy/attributes_for"
|
||||
require "factory_bot/strategy/stub"
|
||||
require "factory_bot/strategy/null"
|
||||
require "factory_bot/registry"
|
||||
require "factory_bot/null_factory"
|
||||
require "factory_bot/null_object"
|
||||
require "factory_bot/evaluation"
|
||||
require "factory_bot/factory"
|
||||
require "factory_bot/attribute_assigner"
|
||||
require "factory_bot/evaluator"
|
||||
require "factory_bot/evaluator_class_definer"
|
||||
require "factory_bot/attribute"
|
||||
require "factory_bot/callback"
|
||||
require "factory_bot/callbacks_observer"
|
||||
require "factory_bot/declaration_list"
|
||||
require "factory_bot/declaration"
|
||||
require "factory_bot/sequence"
|
||||
require "factory_bot/attribute_list"
|
||||
require "factory_bot/trait"
|
||||
require "factory_bot/aliases"
|
||||
require "factory_bot/definition"
|
||||
require "factory_bot/definition_proxy"
|
||||
require "factory_bot/syntax"
|
||||
require "factory_bot/syntax_runner"
|
||||
require "factory_bot/find_definitions"
|
||||
require "factory_bot/reload"
|
||||
require "factory_bot/decorator"
|
||||
require "factory_bot/decorator/attribute_hash"
|
||||
require "factory_bot/decorator/class_key_hash"
|
||||
require "factory_bot/decorator/disallows_duplicates_registry"
|
||||
require "factory_bot/decorator/invocation_tracker"
|
||||
require "factory_bot/decorator/new_constructor"
|
||||
require "factory_bot/linter"
|
||||
require "factory_bot/version"
|
||||
|
||||
module FactoryBot
|
||||
def self.configuration
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'factory_bot/attribute/dynamic'
|
||||
require 'factory_bot/attribute/association'
|
||||
require 'factory_bot/attribute/sequence'
|
||||
require "factory_bot/attribute/dynamic"
|
||||
require "factory_bot/attribute/association"
|
||||
require "factory_bot/attribute/sequence"
|
||||
|
||||
module FactoryBot
|
||||
# @api private
|
||||
|
|
|
@ -6,10 +6,10 @@ module FactoryBot
|
|||
attr_accessor :allow_class_lookup, :use_parent_strategy
|
||||
|
||||
def initialize
|
||||
@factories = Decorator::DisallowsDuplicatesRegistry.new(Registry.new('Factory'))
|
||||
@sequences = Decorator::DisallowsDuplicatesRegistry.new(Registry.new('Sequence'))
|
||||
@traits = Decorator::DisallowsDuplicatesRegistry.new(Registry.new('Trait'))
|
||||
@strategies = Registry.new('Strategy')
|
||||
@factories = Decorator::DisallowsDuplicatesRegistry.new(Registry.new("Factory"))
|
||||
@sequences = Decorator::DisallowsDuplicatesRegistry.new(Registry.new("Sequence"))
|
||||
@traits = Decorator::DisallowsDuplicatesRegistry.new(Registry.new("Trait"))
|
||||
@strategies = Registry.new("Strategy")
|
||||
@callback_names = Set.new
|
||||
@definition = Definition.new(:configuration)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'factory_bot/declaration/dynamic'
|
||||
require 'factory_bot/declaration/association'
|
||||
require 'factory_bot/declaration/implicit'
|
||||
require "factory_bot/declaration/dynamic"
|
||||
require "factory_bot/declaration/association"
|
||||
require "factory_bot/declaration/implicit"
|
||||
|
||||
module FactoryBot
|
||||
# @api private
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'observer'
|
||||
require "observer"
|
||||
|
||||
module FactoryBot
|
||||
class Evaluation
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require 'active_support/core_ext/hash/except'
|
||||
require 'active_support/core_ext/class/attribute'
|
||||
require "active_support/core_ext/hash/except"
|
||||
require "active_support/core_ext/class/attribute"
|
||||
|
||||
module FactoryBot
|
||||
# @api private
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require 'active_support/core_ext/hash/keys'
|
||||
require 'active_support/inflector'
|
||||
require "active_support/core_ext/hash/keys"
|
||||
require "active_support/inflector"
|
||||
|
||||
module FactoryBot
|
||||
# @api private
|
||||
|
|
|
@ -25,7 +25,7 @@ module FactoryBot
|
|||
factory: factory,
|
||||
}
|
||||
|
||||
ActiveSupport::Notifications.instrument('factory_bot.run_factory', instrumentation_payload) do
|
||||
ActiveSupport::Notifications.instrument("factory_bot.run_factory", instrumentation_payload) do
|
||||
factory.run(runner_strategy, @overrides, &block)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ module FactoryBot
|
|||
load("#{path}.rb") if File.exist?("#{path}.rb")
|
||||
|
||||
if File.directory? path
|
||||
Dir[File.join(path, '**', '*.rb')].sort.each do |file|
|
||||
Dir[File.join(path, "**", "*.rb")].sort.each do |file|
|
||||
load file
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require 'factory_bot/syntax/methods'
|
||||
require 'factory_bot/syntax/default'
|
||||
require "factory_bot/syntax/methods"
|
||||
require "factory_bot/syntax/default"
|
||||
|
||||
module FactoryBot
|
||||
module Syntax
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
describe "attribute aliases" do
|
||||
before do
|
||||
define_model('User', name: :string, age: :integer)
|
||||
define_model("User", name: :string, age: :integer)
|
||||
|
||||
define_model('Post', user_id: :integer) do
|
||||
define_model("Post", user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@ describe "a generated attributes hash" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
define_model('Comment')
|
||||
define_model("User")
|
||||
define_model("Comment")
|
||||
|
||||
define_model('Post', title: :string,
|
||||
define_model("Post", title: :string,
|
||||
body: :string,
|
||||
summary: :string,
|
||||
user_id: :integer) do
|
||||
|
@ -29,7 +29,7 @@ describe "a generated attributes hash" do
|
|||
end
|
||||
end
|
||||
|
||||
subject { attributes_for(:post, title: 'overridden title') }
|
||||
subject { attributes_for(:post, title: "overridden title") }
|
||||
|
||||
it "assigns an overridden value" do
|
||||
expect(subject[:title]).to eq "overridden title"
|
||||
|
@ -53,7 +53,7 @@ describe "calling `attributes_for` with a block" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('Company', name: :string)
|
||||
define_model("Company", name: :string)
|
||||
|
||||
FactoryBot.define do
|
||||
factory :company
|
||||
|
@ -61,8 +61,8 @@ describe "calling `attributes_for` with a block" do
|
|||
end
|
||||
|
||||
it "passes the hash of attributes" do
|
||||
attributes_for(:company, name: 'thoughtbot') do |attributes|
|
||||
expect(attributes[:name]).to eq('thoughtbot')
|
||||
attributes_for(:company, name: "thoughtbot") do |attributes|
|
||||
expect(attributes[:name]).to eq("thoughtbot")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe "calling methods on the model instance" do
|
||||
before do
|
||||
define_model('User', age: :integer, age_copy: :integer) do
|
||||
define_model("User", age: :integer, age_copy: :integer) do
|
||||
def age
|
||||
read_attribute(:age) || 18
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ describe "a generated attributes hash where order matters" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('ParentModel', static: :integer,
|
||||
define_model("ParentModel", static: :integer,
|
||||
evaluates_first: :integer,
|
||||
evaluates_second: :integer,
|
||||
evaluates_third: :integer)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe "build multiple instances" do
|
||||
before do
|
||||
define_model('Post', title: :string, position: :integer)
|
||||
define_model("Post", title: :string, position: :integer)
|
||||
|
||||
FactoryBot.define do
|
||||
factory(:post) do |post|
|
||||
|
|
|
@ -2,9 +2,9 @@ describe "a built instance" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
define_model("User")
|
||||
|
||||
define_model('Post', user_id: :integer) do
|
||||
define_model("Post", user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -51,9 +51,9 @@ describe "a built instance with strategy: :create" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
define_model("User")
|
||||
|
||||
define_model('Post', user_id: :integer) do
|
||||
define_model("Post", user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -80,7 +80,7 @@ describe "calling `build` with a block" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('Company', name: :string)
|
||||
define_model("Company", name: :string)
|
||||
|
||||
FactoryBot.define do
|
||||
factory :company
|
||||
|
@ -88,8 +88,8 @@ describe "calling `build` with a block" do
|
|||
end
|
||||
|
||||
it "passes the built instance" do
|
||||
build(:company, name: 'thoughtbot') do |company|
|
||||
expect(company.name).to eq('thoughtbot')
|
||||
build(:company, name: "thoughtbot") do |company|
|
||||
expect(company.name).to eq("thoughtbot")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ describe "a generated stub instance" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
define_model("User")
|
||||
|
||||
define_model('Post', title: :string,
|
||||
define_model("Post", title: :string,
|
||||
body: :string,
|
||||
age: :integer,
|
||||
user_id: :integer,
|
||||
|
@ -23,14 +23,14 @@ describe "a generated stub instance" do
|
|||
end
|
||||
end
|
||||
|
||||
subject { build_stubbed(:post, title: 'overridden title') }
|
||||
subject { build_stubbed(:post, title: "overridden title") }
|
||||
|
||||
it "assigns a default attribute" do
|
||||
expect(subject.body).to eq 'default body'
|
||||
expect(subject.body).to eq "default body"
|
||||
end
|
||||
|
||||
it "assigns an overridden attribute" do
|
||||
expect(subject.title).to eq 'overridden title'
|
||||
expect(subject.title).to eq "overridden title"
|
||||
end
|
||||
|
||||
it "assigns associations" do
|
||||
|
@ -113,7 +113,7 @@ describe "calling `build_stubbed` with a block" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('Company', name: :string)
|
||||
define_model("Company", name: :string)
|
||||
|
||||
FactoryBot.define do
|
||||
factory :company
|
||||
|
@ -121,8 +121,8 @@ describe "calling `build_stubbed` with a block" do
|
|||
end
|
||||
|
||||
it "passes the stub instance" do
|
||||
build_stubbed(:company, name: 'thoughtbot') do |company|
|
||||
expect(company.name).to eq('thoughtbot')
|
||||
build_stubbed(:company, name: "thoughtbot") do |company|
|
||||
expect(company.name).to eq("thoughtbot")
|
||||
expect { company.save }.to raise_error(RuntimeError)
|
||||
end
|
||||
end
|
||||
|
@ -141,8 +141,8 @@ describe "defaulting `created_at`" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('ThingWithTimestamp', created_at: :datetime)
|
||||
define_model('ThingWithoutTimestamp')
|
||||
define_model("ThingWithTimestamp", created_at: :datetime)
|
||||
define_model("ThingWithoutTimestamp")
|
||||
|
||||
FactoryBot.define do
|
||||
factory :thing_with_timestamp
|
||||
|
@ -157,13 +157,13 @@ describe "defaulting `created_at`" do
|
|||
end
|
||||
|
||||
it "defaults created_at for objects with created_at to the correct time with zone" do
|
||||
original_timezone = ENV['TZ']
|
||||
ENV['TZ'] = 'UTC'
|
||||
Time.zone = 'Eastern Time (US & Canada)'
|
||||
original_timezone = ENV["TZ"]
|
||||
ENV["TZ"] = "UTC"
|
||||
Time.zone = "Eastern Time (US & Canada)"
|
||||
|
||||
expect(build_stubbed(:thing_with_timestamp).created_at.zone).to eq 'EST'
|
||||
expect(build_stubbed(:thing_with_timestamp).created_at.zone).to eq "EST"
|
||||
|
||||
ENV['TZ'] = original_timezone
|
||||
ENV["TZ"] = original_timezone
|
||||
end
|
||||
|
||||
it "doesn't add created_at to objects who don't have the method" do
|
||||
|
@ -216,16 +216,16 @@ describe "defaulting `updated_at`" do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'defaulting `id`' do
|
||||
describe "defaulting `id`" do
|
||||
before do
|
||||
define_model('Post')
|
||||
define_model("Post")
|
||||
|
||||
FactoryBot.define do
|
||||
factory :post
|
||||
end
|
||||
end
|
||||
|
||||
it 'allows overriding id' do
|
||||
it "allows overriding id" do
|
||||
expect(FactoryBot.build_stubbed(:post, id: 12).id).to eq 12
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,49 +4,49 @@ describe "callbacks" do
|
|||
|
||||
FactoryBot.define do
|
||||
factory :user_with_callbacks, class: :user do
|
||||
after(:stub) { |user| user.first_name = 'Stubby' }
|
||||
after(:build) { |user| user.first_name = 'Buildy' }
|
||||
after(:create) { |user| user.last_name = 'Createy' }
|
||||
after(:stub) { |user| user.first_name = "Stubby" }
|
||||
after(:build) { |user| user.first_name = "Buildy" }
|
||||
after(:create) { |user| user.last_name = "Createy" }
|
||||
end
|
||||
|
||||
factory :user_with_inherited_callbacks, parent: :user_with_callbacks do
|
||||
after(:stub) { |user| user.last_name = 'Double-Stubby' }
|
||||
after(:build) { |user| user.first_name = 'Child-Buildy' }
|
||||
after(:stub) { |user| user.last_name = "Double-Stubby" }
|
||||
after(:build) { |user| user.first_name = "Child-Buildy" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "runs the after(:stub) callback when stubbing" do
|
||||
user = FactoryBot.build_stubbed(:user_with_callbacks)
|
||||
expect(user.first_name).to eq 'Stubby'
|
||||
expect(user.first_name).to eq "Stubby"
|
||||
end
|
||||
|
||||
it "runs the after(:build) callback when building" do
|
||||
user = FactoryBot.build(:user_with_callbacks)
|
||||
expect(user.first_name).to eq 'Buildy'
|
||||
expect(user.first_name).to eq "Buildy"
|
||||
end
|
||||
|
||||
it "runs both the after(:build) and after(:create) callbacks when creating" do
|
||||
user = FactoryBot.create(:user_with_callbacks)
|
||||
expect(user.first_name).to eq 'Buildy'
|
||||
expect(user.last_name).to eq 'Createy'
|
||||
expect(user.first_name).to eq "Buildy"
|
||||
expect(user.last_name).to eq "Createy"
|
||||
end
|
||||
|
||||
it "runs both the after(:stub) callback on the factory and the inherited after(:stub) callback" do
|
||||
user = FactoryBot.build_stubbed(:user_with_inherited_callbacks)
|
||||
expect(user.first_name).to eq 'Stubby'
|
||||
expect(user.last_name).to eq 'Double-Stubby'
|
||||
expect(user.first_name).to eq "Stubby"
|
||||
expect(user.last_name).to eq "Double-Stubby"
|
||||
end
|
||||
|
||||
it "runs child callback after parent callback" do
|
||||
user = FactoryBot.build(:user_with_inherited_callbacks)
|
||||
expect(user.first_name).to eq 'Child-Buildy'
|
||||
expect(user.first_name).to eq "Child-Buildy"
|
||||
end
|
||||
end
|
||||
|
||||
describe 'callbacks using Symbol#to_proc' do
|
||||
describe "callbacks using Symbol#to_proc" do
|
||||
before do
|
||||
define_model('User') do
|
||||
define_model("User") do
|
||||
def confirmed?
|
||||
!!@confirmed
|
||||
end
|
||||
|
@ -63,7 +63,7 @@ describe 'callbacks using Symbol#to_proc' do
|
|||
end
|
||||
end
|
||||
|
||||
it 'runs the callback correctly' do
|
||||
it "runs the callback correctly" do
|
||||
user = FactoryBot.build(:user)
|
||||
expect(user).to be_confirmed
|
||||
end
|
||||
|
@ -173,9 +173,9 @@ describe "custom callbacks" do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'binding a callback to multiple callbacks' do
|
||||
describe "binding a callback to multiple callbacks" do
|
||||
before do
|
||||
define_model('User', name: :string)
|
||||
define_model("User", name: :string)
|
||||
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
|
@ -186,31 +186,31 @@ describe 'binding a callback to multiple callbacks' do
|
|||
end
|
||||
end
|
||||
|
||||
it 'binds the callback to creation' do
|
||||
expect(FactoryBot.create(:user, name: 'John Doe').name).to eq 'JOHN DOE'
|
||||
it "binds the callback to creation" do
|
||||
expect(FactoryBot.create(:user, name: "John Doe").name).to eq "JOHN DOE"
|
||||
end
|
||||
|
||||
it 'does not bind the callback to building' do
|
||||
expect(FactoryBot.build(:user, name: 'John Doe').name).to eq 'John Doe'
|
||||
it "does not bind the callback to building" do
|
||||
expect(FactoryBot.build(:user, name: "John Doe").name).to eq "John Doe"
|
||||
end
|
||||
|
||||
it 'binds the callback to stubbing' do
|
||||
expect(FactoryBot.build_stubbed(:user, name: 'John Doe').name).to eq 'JOHN DOE'
|
||||
it "binds the callback to stubbing" do
|
||||
expect(FactoryBot.build_stubbed(:user, name: "John Doe").name).to eq "JOHN DOE"
|
||||
end
|
||||
end
|
||||
|
||||
describe 'global callbacks' do
|
||||
describe "global callbacks" do
|
||||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User', name: :string)
|
||||
define_model('Company', name: :string)
|
||||
define_model("User", name: :string)
|
||||
define_model("Company", name: :string)
|
||||
|
||||
FactoryBot.define do
|
||||
after :build do |object|
|
||||
object.name = case object.class.to_s
|
||||
when 'User' then 'John Doe'
|
||||
when 'Company' then 'Acme Suppliers'
|
||||
when "User" then "John Doe"
|
||||
when "Company" then "Acme Suppliers"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -242,10 +242,10 @@ describe 'global callbacks' do
|
|||
end
|
||||
end
|
||||
|
||||
it 'triggers after build callbacks for all factories' do
|
||||
expect(build(:user).name).to eq 'john doe'
|
||||
expect(create(:user).name).to eq 'john doe!!!'
|
||||
expect(create(:user, :awesome).name).to eq 'A___john doe___!!!Z'
|
||||
expect(build(:company).name).to eq 'ACME SUPPLIERS'
|
||||
it "triggers after build callbacks for all factories" do
|
||||
expect(build(:user).name).to eq "john doe"
|
||||
expect(create(:user).name).to eq "john doe!!!"
|
||||
expect(create(:user, :awesome).name).to eq "A___john doe___!!!Z"
|
||||
expect(build(:company).name).to eq "ACME SUPPLIERS"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe "create multiple instances" do
|
||||
before do
|
||||
define_model('Post', title: :string, position: :integer)
|
||||
define_model("Post", title: :string, position: :integer)
|
||||
|
||||
FactoryBot.define do
|
||||
factory(:post) do |post|
|
||||
|
@ -63,11 +63,11 @@ end
|
|||
|
||||
describe "multiple creates and transient attributes to dynamically build attribute lists" do
|
||||
before do
|
||||
define_model('User', name: :string) do
|
||||
define_model("User", name: :string) do
|
||||
has_many :posts
|
||||
end
|
||||
|
||||
define_model('Post', title: :string, user_id: :integer) do
|
||||
define_model("Post", title: :string, user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe "create multiple instances" do
|
||||
before do
|
||||
define_model('Post', title: :string, position: :integer)
|
||||
define_model("Post", title: :string, position: :integer)
|
||||
|
||||
FactoryBot.define do
|
||||
factory(:post) do |post|
|
||||
|
|
|
@ -2,9 +2,9 @@ describe "a created instance" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
define_model("User")
|
||||
|
||||
define_model('Post', user_id: :integer) do
|
||||
define_model("Post", user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -17,7 +17,7 @@ describe "a created instance" do
|
|||
end
|
||||
end
|
||||
|
||||
subject { create('post') }
|
||||
subject { create("post") }
|
||||
|
||||
it { should_not be_new_record }
|
||||
|
||||
|
@ -31,9 +31,9 @@ describe "a created instance, specifying strategy: :build" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
define_model("User")
|
||||
|
||||
define_model('Post', user_id: :integer) do
|
||||
define_model("Post", user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -58,7 +58,7 @@ describe "a custom create" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_class('User') do
|
||||
define_class("User") do
|
||||
def initialize
|
||||
@persisted = false
|
||||
end
|
||||
|
@ -110,7 +110,7 @@ describe "calling `create` with a block" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('Company', name: :string)
|
||||
define_model("Company", name: :string)
|
||||
|
||||
FactoryBot.define do
|
||||
factory :company
|
||||
|
@ -118,8 +118,8 @@ describe "calling `create` with a block" do
|
|||
end
|
||||
|
||||
it "passes the created instance" do
|
||||
create(:company, name: 'thoughtbot') do |company|
|
||||
expect(company.name).to eq('thoughtbot')
|
||||
create(:company, name: "thoughtbot") do |company|
|
||||
expect(company.name).to eq("thoughtbot")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
describe 'defining methods inside FactoryBot' do
|
||||
it 'raises with a meaningful message' do
|
||||
define_model('User')
|
||||
describe "defining methods inside FactoryBot" do
|
||||
it "raises with a meaningful message" do
|
||||
define_model("User")
|
||||
|
||||
expect do
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
def generate_name
|
||||
'John Doe'
|
||||
"John Doe"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,11 +3,11 @@ describe "an instance generated by a factory named a camel case string " do
|
|||
define_model("UserModel")
|
||||
|
||||
FactoryBot.define do
|
||||
factory 'UserModel', class: UserModel
|
||||
factory "UserModel", class: UserModel
|
||||
end
|
||||
end
|
||||
|
||||
it "registers the UserModel factory" do
|
||||
expect(FactoryBot.factory_by_name('UserModel')).to be_a(FactoryBot::Factory)
|
||||
expect(FactoryBot.factory_by_name("UserModel")).to be_a(FactoryBot::Factory)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe 'global initialize_with' do
|
||||
describe "global initialize_with" do
|
||||
before do
|
||||
define_class('User') do
|
||||
define_class("User") do
|
||||
attr_accessor :name
|
||||
|
||||
def initialize(name)
|
||||
|
@ -8,7 +8,7 @@ describe 'global initialize_with' do
|
|||
end
|
||||
end
|
||||
|
||||
define_class('Post') do
|
||||
define_class("Post") do
|
||||
attr_reader :name
|
||||
|
||||
def initialize(name)
|
||||
|
@ -41,28 +41,28 @@ describe 'global initialize_with' do
|
|||
end
|
||||
end
|
||||
|
||||
it 'handles base initialize_with' do
|
||||
expect(FactoryBot.build(:user).name).to eq 'initialize_with'
|
||||
expect(FactoryBot.build(:post).name).to eq 'initialize_with'
|
||||
it "handles base initialize_with" do
|
||||
expect(FactoryBot.build(:user).name).to eq "initialize_with"
|
||||
expect(FactoryBot.build(:post).name).to eq "initialize_with"
|
||||
end
|
||||
|
||||
it 'handles child initialize_with' do
|
||||
expect(FactoryBot.build(:child_user).name).to eq 'initialize_with'
|
||||
expect(FactoryBot.build(:child_post).name).to eq 'initialize_with'
|
||||
it "handles child initialize_with" do
|
||||
expect(FactoryBot.build(:child_user).name).to eq "initialize_with"
|
||||
expect(FactoryBot.build(:child_post).name).to eq "initialize_with"
|
||||
end
|
||||
|
||||
it 'handles child initialize_with with trait' do
|
||||
expect(FactoryBot.build(:child_user_with_trait).name).to eq 'trait initialize_with'
|
||||
expect(FactoryBot.build(:child_post_with_trait).name).to eq 'trait initialize_with'
|
||||
it "handles child initialize_with with trait" do
|
||||
expect(FactoryBot.build(:child_user_with_trait).name).to eq "trait initialize_with"
|
||||
expect(FactoryBot.build(:child_post_with_trait).name).to eq "trait initialize_with"
|
||||
end
|
||||
|
||||
it 'handles inline trait override' do
|
||||
expect(FactoryBot.build(:child_user, :with_initialize_with).name).to eq 'trait initialize_with'
|
||||
expect(FactoryBot.build(:child_post, :with_initialize_with).name).to eq 'trait initialize_with'
|
||||
it "handles inline trait override" do
|
||||
expect(FactoryBot.build(:child_user, :with_initialize_with).name).to eq "trait initialize_with"
|
||||
expect(FactoryBot.build(:child_post, :with_initialize_with).name).to eq "trait initialize_with"
|
||||
end
|
||||
|
||||
it 'uses initialize_with globally across FactoryBot.define' do
|
||||
define_class('Company') do
|
||||
it "uses initialize_with globally across FactoryBot.define" do
|
||||
define_class("Company") do
|
||||
attr_reader :name
|
||||
|
||||
def initialize(name)
|
||||
|
@ -74,7 +74,7 @@ describe 'global initialize_with' do
|
|||
factory :company
|
||||
end
|
||||
|
||||
expect(FactoryBot.build(:company).name).to eq 'initialize_with'
|
||||
expect(FactoryBot.build(:company, :with_initialize_with).name).to eq 'trait initialize_with'
|
||||
expect(FactoryBot.build(:company).name).to eq "initialize_with"
|
||||
expect(FactoryBot.build(:company, :with_initialize_with).name).to eq "trait initialize_with"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -104,23 +104,23 @@ describe "global skip_create" do
|
|||
end
|
||||
end
|
||||
|
||||
it 'does not persist any record' do
|
||||
it "does not persist any record" do
|
||||
expect(FactoryBot.create(:user)).to be_new_record
|
||||
expect(FactoryBot.create(:post)).to be_new_record
|
||||
end
|
||||
|
||||
it 'does not persist child records' do
|
||||
it "does not persist child records" do
|
||||
expect(FactoryBot.create(:child_user)).to be_new_record
|
||||
expect(FactoryBot.create(:child_post)).to be_new_record
|
||||
end
|
||||
|
||||
it 'honors overridden to_create' do
|
||||
expect(FactoryBot.create(:child_user_with_trait).name).to eq 'override'
|
||||
expect(FactoryBot.create(:child_post_with_trait).name).to eq 'override'
|
||||
it "honors overridden to_create" do
|
||||
expect(FactoryBot.create(:child_user_with_trait).name).to eq "override"
|
||||
expect(FactoryBot.create(:child_post_with_trait).name).to eq "override"
|
||||
end
|
||||
|
||||
it 'honors inline trait to_create' do
|
||||
expect(FactoryBot.create(:child_user, :override_to_create).name).to eq 'override'
|
||||
expect(FactoryBot.create(:child_post, :override_to_create).name).to eq 'override'
|
||||
it "honors inline trait to_create" do
|
||||
expect(FactoryBot.create(:child_user, :override_to_create).name).to eq "override"
|
||||
expect(FactoryBot.create(:child_post, :override_to_create).name).to eq "override"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ describe "modifying factories" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User', name: :string, admin: :boolean, email: :string, login: :string)
|
||||
define_model("User", name: :string, admin: :boolean, email: :string, login: :string)
|
||||
|
||||
FactoryBot.define do
|
||||
sequence(:email) { |n| "user#{n}@example.com" }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe "modifying inherited factories with traits" do
|
||||
before do
|
||||
define_model('User', gender: :string, admin: :boolean, age: :integer)
|
||||
define_model("User", gender: :string, admin: :boolean, age: :integer)
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
trait(:female) { gender { "Female" } }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
describe "attribute overrides" do
|
||||
before do
|
||||
define_model('User', admin: :boolean)
|
||||
define_model('Post', title: :string,
|
||||
define_model("User", admin: :boolean)
|
||||
define_model("Post", title: :string,
|
||||
secure: :boolean,
|
||||
user_id: :integer) do
|
||||
belongs_to :user
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe 'setting private attributes' do
|
||||
it 'raises a NoMethodError' do
|
||||
define_class('User') do
|
||||
describe "setting private attributes" do
|
||||
it "raises a NoMethodError" do
|
||||
define_class("User") do
|
||||
private
|
||||
|
||||
attr_accessor :foo
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
describe 'sequences are evaluated in the correct context' do
|
||||
describe "sequences are evaluated in the correct context" do
|
||||
before do
|
||||
define_class("User") do
|
||||
attr_accessor :id
|
||||
|
||||
def awesome
|
||||
'aw yeah'
|
||||
"aw yeah"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'builds a sequence calling sprintf correctly' do
|
||||
it "builds a sequence calling sprintf correctly" do
|
||||
FactoryBot.define do
|
||||
factory :sequence_with_sprintf, class: User do
|
||||
sequence(:id) { |n| sprintf("foo%d", n) }
|
||||
end
|
||||
end
|
||||
|
||||
expect(FactoryBot.build(:sequence_with_sprintf).id).to eq 'foo1'
|
||||
expect(FactoryBot.build(:sequence_with_sprintf).id).to eq "foo1"
|
||||
end
|
||||
|
||||
it 'invokes the correct method on the instance' do
|
||||
it "invokes the correct method on the instance" do
|
||||
FactoryBot.define do
|
||||
factory :sequence_with_public_method, class: User do
|
||||
sequence(:id) { public_method(:awesome).call }
|
||||
end
|
||||
end
|
||||
|
||||
expect(FactoryBot.build(:sequence_with_public_method).id).to eq 'aw yeah'
|
||||
expect(FactoryBot.build(:sequence_with_public_method).id).to eq "aw yeah"
|
||||
end
|
||||
|
||||
it 'invokes a method with no arguments on the instance' do
|
||||
it "invokes a method with no arguments on the instance" do
|
||||
FactoryBot.define do
|
||||
factory :sequence_with_frozen, class: User do
|
||||
sequence(:id) { frozen? }
|
||||
|
@ -39,12 +39,12 @@ describe 'sequences are evaluated in the correct context' do
|
|||
expect(FactoryBot.build(:sequence_with_frozen).id).to be false
|
||||
end
|
||||
|
||||
it 'allows direct reference of a method in a sequence' do
|
||||
it "allows direct reference of a method in a sequence" do
|
||||
FactoryBot.define do
|
||||
factory :sequence_referencing_attribute_directly, class: User do
|
||||
sequence(:id) { |n| "#{awesome}#{n}" }
|
||||
end
|
||||
end
|
||||
expect(FactoryBot.build(:sequence_referencing_attribute_directly).id).to eq 'aw yeah1'
|
||||
expect(FactoryBot.build(:sequence_referencing_attribute_directly).id).to eq "aw yeah1"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,9 +2,9 @@ describe "a stubbed instance" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
define_model("User")
|
||||
|
||||
define_model('Post', user_id: :integer) do
|
||||
define_model("Post", user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
@ -33,8 +33,8 @@ describe "a stubbed instance overriding strategy" do
|
|||
include FactoryBot::Syntax::Methods
|
||||
|
||||
before do
|
||||
define_model('User')
|
||||
define_model('Post', user_id: :integer) do
|
||||
define_model("User")
|
||||
define_model("Post", user_id: :integer) do
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ describe "syntax methods within dynamic attributes" do
|
|||
expect(FactoryBot.attributes_for(:post)[:title]).to be_nil
|
||||
end
|
||||
|
||||
it 'allows syntax methods to be used when the block has an arity of 1' do
|
||||
it "allows syntax methods to be used when the block has an arity of 1" do
|
||||
FactoryBot.define do
|
||||
factory :post_using_block_with_variable, parent: :post do
|
||||
user { |_| build(:user) }
|
||||
|
|
|
@ -412,9 +412,9 @@ describe "making sure the factory is properly compiled the first time we want to
|
|||
|
||||
it "can honor traits on the very first call" do
|
||||
user = FactoryBot.build(:female_user, :admin, age: 30)
|
||||
expect(user.gender).to eq 'female'
|
||||
expect(user.gender).to eq "female"
|
||||
expect(user.age).to eq 30
|
||||
expect(user.role).to eq 'admin'
|
||||
expect(user.role).to eq "admin"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -675,11 +675,11 @@ describe "traits used in associations" do
|
|||
end
|
||||
|
||||
define_model("Order", creator_id: :integer) do
|
||||
belongs_to :creator, class_name: 'User'
|
||||
belongs_to :creator, class_name: "User"
|
||||
end
|
||||
|
||||
define_model("Post", author_id: :integer) do
|
||||
belongs_to :author, class_name: 'User'
|
||||
belongs_to :author, class_name: "User"
|
||||
end
|
||||
|
||||
FactoryBot.define do
|
||||
|
@ -692,15 +692,15 @@ describe "traits used in associations" do
|
|||
end
|
||||
|
||||
factory :post do
|
||||
association :author, factory: [:user, :admin], name: 'John Doe'
|
||||
association :author, factory: [:user, :admin], name: "John Doe"
|
||||
end
|
||||
|
||||
factory :comment do
|
||||
association :user, :admin, name: 'Joe Slick'
|
||||
association :user, :admin, name: "Joe Slick"
|
||||
end
|
||||
|
||||
factory :order do
|
||||
association :creator, :admin, factory: :user, name: 'Joe Creator'
|
||||
association :creator, :admin, factory: :user, name: "Joe Creator"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -708,18 +708,18 @@ describe "traits used in associations" do
|
|||
it "allows assigning traits for the factory of an association" do
|
||||
author = FactoryBot.create(:post).author
|
||||
expect(author).to be_admin
|
||||
expect(author.name).to eq 'John Doe'
|
||||
expect(author.name).to eq "John Doe"
|
||||
end
|
||||
|
||||
it "allows inline traits with the default association" do
|
||||
user = FactoryBot.create(:comment).user
|
||||
expect(user).to be_admin
|
||||
expect(user.name).to eq 'Joe Slick'
|
||||
expect(user.name).to eq "Joe Slick"
|
||||
end
|
||||
|
||||
it "allows inline traits with a specific factory for an association" do
|
||||
creator = FactoryBot.create(:order).creator
|
||||
expect(creator).to be_admin
|
||||
expect(creator.name).to eq 'Joe Creator'
|
||||
expect(creator.name).to eq "Joe Creator"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -105,7 +105,7 @@ describe "assigning values from a transient attribute" do
|
|||
FactoryBot.define do
|
||||
factory :user do
|
||||
transient do
|
||||
foo { Foo.new('id-of-foo', 'name-of-foo') }
|
||||
foo { Foo.new("id-of-foo", "name-of-foo") }
|
||||
end
|
||||
|
||||
foo_id { foo.id }
|
||||
|
@ -115,8 +115,8 @@ describe "assigning values from a transient attribute" do
|
|||
end
|
||||
|
||||
it "does not ignore an _id attribute that is an alias for a transient attribute" do
|
||||
user = FactoryBot.build(:user, foo: Foo.new('passed-in-id-of-foo', 'passed-in-name-of-foo'))
|
||||
expect(user.foo_id).to eq 'passed-in-id-of-foo'
|
||||
expect(user.foo_name).to eq 'passed-in-name-of-foo'
|
||||
user = FactoryBot.build(:user, foo: Foo.new("passed-in-id-of-foo", "passed-in-name-of-foo"))
|
||||
expect(user.foo_id).to eq "passed-in-id-of-foo"
|
||||
expect(user.foo_name).to eq "passed-in-name-of-foo"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
describe FactoryBot::Factory do
|
||||
before do
|
||||
@name = :user
|
||||
@class = define_class('User')
|
||||
@class = define_class("User")
|
||||
@factory = FactoryBot::Factory.new(@name)
|
||||
FactoryBot.register_factory(@factory)
|
||||
end
|
||||
|
@ -55,7 +55,7 @@ describe FactoryBot::Factory do
|
|||
describe "when overriding generated attributes with a hash" do
|
||||
before do
|
||||
@name = :name
|
||||
@value = 'The price is right!'
|
||||
@value = "The price is right!"
|
||||
@hash = { @name => @value }
|
||||
end
|
||||
|
||||
|
@ -92,7 +92,7 @@ describe FactoryBot::Factory do
|
|||
end
|
||||
|
||||
it "uses the passed in value for the alias" do
|
||||
expect(@result[:test_alias]).to eq 'new'
|
||||
expect(@result[:test_alias]).to eq "new"
|
||||
end
|
||||
|
||||
it "discards the predefined value for the attribute" do
|
||||
|
@ -160,7 +160,7 @@ describe FactoryBot::Factory, "with a name ending in s" do
|
|||
let(:name) { :business }
|
||||
let(:business_class) { Business }
|
||||
|
||||
before { define_class('Business') }
|
||||
before { define_class("Business") }
|
||||
subject { FactoryBot::Factory.new(name) }
|
||||
|
||||
its(:name) { should eq name }
|
||||
|
|
|
@ -26,7 +26,7 @@ describe "definition loading" do
|
|||
def self.in_directory_with_files(*files)
|
||||
before do
|
||||
@pwd = Dir.pwd
|
||||
@tmp_dir = File.join(File.dirname(__FILE__), 'tmp')
|
||||
@tmp_dir = File.join(File.dirname(__FILE__), "tmp")
|
||||
FileUtils.mkdir_p @tmp_dir
|
||||
Dir.chdir(@tmp_dir)
|
||||
|
||||
|
@ -43,30 +43,30 @@ describe "definition loading" do
|
|||
end
|
||||
|
||||
describe "with factories.rb" do
|
||||
in_directory_with_files 'factories.rb'
|
||||
in_directory_with_files "factories.rb"
|
||||
it_should_behave_like "finds definitions" do
|
||||
it { should load_definitions_from('factories.rb') }
|
||||
it { should load_definitions_from("factories.rb") }
|
||||
end
|
||||
end
|
||||
|
||||
%w(spec test).each do |dir|
|
||||
describe "with a factories file under #{dir}" do
|
||||
in_directory_with_files File.join(dir, 'factories.rb')
|
||||
in_directory_with_files File.join(dir, "factories.rb")
|
||||
it_should_behave_like "finds definitions" do
|
||||
it { should load_definitions_from("#{dir}/factories.rb") }
|
||||
end
|
||||
end
|
||||
|
||||
describe "with a factories file under #{dir}/factories" do
|
||||
in_directory_with_files File.join(dir, 'factories', 'post_factory.rb')
|
||||
in_directory_with_files File.join(dir, "factories", "post_factory.rb")
|
||||
it_should_behave_like "finds definitions" do
|
||||
it { should load_definitions_from("#{dir}/factories/post_factory.rb") }
|
||||
end
|
||||
end
|
||||
|
||||
describe "with several factories files under #{dir}/factories" do
|
||||
in_directory_with_files File.join(dir, 'factories', 'post_factory.rb'),
|
||||
File.join(dir, 'factories', 'person_factory.rb')
|
||||
in_directory_with_files File.join(dir, "factories", "post_factory.rb"),
|
||||
File.join(dir, "factories", "person_factory.rb")
|
||||
it_should_behave_like "finds definitions" do
|
||||
it { should load_definitions_from("#{dir}/factories/post_factory.rb") }
|
||||
it { should load_definitions_from("#{dir}/factories/person_factory.rb") }
|
||||
|
@ -74,8 +74,8 @@ describe "definition loading" do
|
|||
end
|
||||
|
||||
describe "with several factories files under #{dir}/factories in non-alphabetical order" do
|
||||
in_directory_with_files File.join(dir, 'factories', 'b.rb'),
|
||||
File.join(dir, 'factories', 'a.rb')
|
||||
in_directory_with_files File.join(dir, "factories", "b.rb"),
|
||||
File.join(dir, "factories", "a.rb")
|
||||
it "loads the files in the right order" do
|
||||
allow(FactoryBot).to receive(:load)
|
||||
wd = File.dirname(__FILE__)
|
||||
|
@ -90,9 +90,9 @@ describe "definition loading" do
|
|||
end
|
||||
|
||||
describe "with nested and unnested factories files under #{dir}" do
|
||||
in_directory_with_files File.join(dir, 'factories.rb'),
|
||||
File.join(dir, 'factories', 'post_factory.rb'),
|
||||
File.join(dir, 'factories', 'person_factory.rb')
|
||||
in_directory_with_files File.join(dir, "factories.rb"),
|
||||
File.join(dir, "factories", "post_factory.rb"),
|
||||
File.join(dir, "factories", "person_factory.rb")
|
||||
it_should_behave_like "finds definitions" do
|
||||
it { should load_definitions_from("#{dir}/factories.rb") }
|
||||
it { should load_definitions_from("#{dir}/factories/post_factory.rb") }
|
||||
|
@ -101,8 +101,8 @@ describe "definition loading" do
|
|||
end
|
||||
|
||||
describe "with deeply nested factory files under #{dir}" do
|
||||
in_directory_with_files File.join(dir, 'factories', 'subdirectory', 'post_factory.rb'),
|
||||
File.join(dir, 'factories', 'subdirectory', 'person_factory.rb')
|
||||
in_directory_with_files File.join(dir, "factories", "subdirectory", "post_factory.rb"),
|
||||
File.join(dir, "factories", "subdirectory", "person_factory.rb")
|
||||
it_should_behave_like "finds definitions" do
|
||||
it { should load_definitions_from("#{dir}/factories/subdirectory/post_factory.rb") }
|
||||
it { should load_definitions_from("#{dir}/factories/subdirectory/person_factory.rb") }
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require 'rspec'
|
||||
require 'rspec/its'
|
||||
require "rspec"
|
||||
require "rspec/its"
|
||||
|
||||
require "simplecov"
|
||||
|
||||
require 'factory_bot'
|
||||
require "factory_bot"
|
||||
require "timecop"
|
||||
|
||||
Dir["spec/support/**/*.rb"].each { |f| require File.expand_path(f) }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'active_record'
|
||||
require "active_record"
|
||||
|
||||
module DefineConstantMacros
|
||||
def define_class(path, base = Object, &block)
|
||||
|
@ -35,7 +35,7 @@ module DefineConstantMacros
|
|||
end
|
||||
|
||||
def constant_path(constant_name)
|
||||
names = constant_name.split('::')
|
||||
names = constant_name.split("::")
|
||||
class_name = names.pop
|
||||
namespace = names.reduce(Object) { |result, name| result.const_get(name) }
|
||||
[namespace, class_name]
|
||||
|
@ -75,8 +75,8 @@ RSpec.configure do |config|
|
|||
|
||||
config.before(:all) do
|
||||
ActiveRecord::Base.establish_connection(
|
||||
adapter: 'sqlite3',
|
||||
database: File.join(File.dirname(__FILE__), 'test.db'),
|
||||
adapter: "sqlite3",
|
||||
database: File.join(File.dirname(__FILE__), "test.db"),
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ module DeclarationMatchers
|
|||
[
|
||||
"expected declarations to include declaration of type #{@declaration_type}",
|
||||
@options ? "with options #{options}" : nil,
|
||||
].compact.join ' '
|
||||
].compact.join " "
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -14,7 +14,7 @@ RSpec::Matchers.define :delegate do |delegated_method|
|
|||
match do |instance|
|
||||
@instance = instance
|
||||
@args ||= []
|
||||
return_value = 'stubbed return value'
|
||||
return_value = "stubbed return value"
|
||||
method_on_target = @method_on_target || delegated_method
|
||||
stubbed_target = double("stubbed_target", method_on_target => return_value)
|
||||
allow(@instance).to receive(@target_method).and_return stubbed_target
|
||||
|
@ -28,10 +28,10 @@ RSpec::Matchers.define :delegate do |delegated_method|
|
|||
failure_message do
|
||||
if Class === @instance
|
||||
message = "expected #{@instance.name} "
|
||||
prefix = '.'
|
||||
prefix = "."
|
||||
else
|
||||
message = "expected #{@instance.class.name} "
|
||||
prefix = '#'
|
||||
prefix = "#"
|
||||
end
|
||||
message << "to delegate #{prefix}#{delegated_method} to #{prefix}#{@target_method}"
|
||||
if @method_on_target
|
||||
|
|
Loading…
Reference in New Issue