2019-10-29 12:06:40 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-08-18 18:10:07 +00:00
|
|
|
require 'rubocop_spec_helper'
|
2018-03-30 15:18:12 +00:00
|
|
|
|
|
|
|
require_relative '../../../../rubocop/cop/rspec/factories_in_migration_specs'
|
|
|
|
|
2021-01-07 18:10:38 +00:00
|
|
|
RSpec.describe RuboCop::Cop::RSpec::FactoriesInMigrationSpecs do
|
2018-03-30 15:18:12 +00:00
|
|
|
shared_examples 'an offensive factory call' do |namespace|
|
2021-01-21 15:08:36 +00:00
|
|
|
%i[build build_list create create_list attributes_for].each do |forbidden_method|
|
2018-03-30 15:18:12 +00:00
|
|
|
namespaced_forbidden_method = "#{namespace}#{forbidden_method}(:user)"
|
|
|
|
|
|
|
|
it "registers an offense for #{namespaced_forbidden_method}" do
|
|
|
|
expect_offense(<<-RUBY)
|
|
|
|
describe 'foo' do
|
|
|
|
let(:user) { #{namespaced_forbidden_method} }
|
|
|
|
#{'^' * namespaced_forbidden_method.size} Don't use FactoryBot.#{forbidden_method} in migration specs, use `table` instead.
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-26 12:24:25 +00:00
|
|
|
it_behaves_like 'an offensive factory call', ''
|
|
|
|
it_behaves_like 'an offensive factory call', 'FactoryBot.'
|
2018-03-30 15:18:12 +00:00
|
|
|
end
|