debian-mirror-gitlab/spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb

33 lines
1 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2020-07-28 23:09:34 +05:30
require 'fast_spec_helper'
2018-05-09 12:01:36 +05:30
require 'rubocop'
require 'rubocop/rspec/support'
require_relative '../../../../rubocop/cop/rspec/factories_in_migration_specs'
2020-07-28 23:09:34 +05:30
RSpec.describe RuboCop::Cop::RSpec::FactoriesInMigrationSpecs, type: :rubocop do
2018-05-09 12:01:36 +05:30
include CopHelper
subject(:cop) { described_class.new }
shared_examples 'an offensive factory call' do |namespace|
%i[build build_list create create_list].each do |forbidden_method|
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-12-04 20:38:33 +05:30
it_behaves_like 'an offensive factory call', ''
it_behaves_like 'an offensive factory call', 'FactoryBot.'
2018-05-09 12:01:36 +05:30
end