debian-mirror-gitlab/spec/factories_spec.rb

54 lines
1.5 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe 'factories' do
2021-01-03 14:25:43 +05:30
shared_examples 'factory' do |factory|
2016-06-02 11:05:42 +05:30
describe "#{factory.name} factory" do
2017-09-10 17:25:29 +05:30
it 'does not raise error when built' do
expect { build(factory.name) }.not_to raise_error
end
2016-06-02 11:05:42 +05:30
it 'does not raise error when created' do
2017-09-10 17:25:29 +05:30
expect { create(factory.name) }.not_to raise_error
2016-06-02 11:05:42 +05:30
end
2017-09-10 17:25:29 +05:30
factory.definition.defined_traits.map(&:name).each do |trait_name|
describe "linting #{trait_name} trait" do
skip 'does not raise error when created' do
expect { create(factory.name, trait_name) }.not_to raise_error
end
end
2016-06-02 11:05:42 +05:30
end
2014-09-02 18:07:02 +05:30
end
end
2021-01-03 14:25:43 +05:30
# FactoryDefault speed up specs by creating associations only once
# and reuse them in other factories.
#
# However, for some factories we cannot use FactoryDefault because the
# associations must be unique and cannot be reused.
skip_factory_defaults = %i[
fork_network_member
].to_set.freeze
without_fd, with_fd = FactoryBot.factories
.partition { |factory| skip_factory_defaults.include?(factory.name) }
context 'with factory defaults', factory_default: :keep do
let_it_be(:namespace) { create_default(:namespace) }
let_it_be(:project) { create_default(:project, :repository) }
let_it_be(:user) { create_default(:user) }
with_fd.each do |factory|
it_behaves_like 'factory', factory
end
end
context 'without factory defaults' do
without_fd.each do |factory|
it_behaves_like 'factory', factory
end
end
2014-09-02 18:07:02 +05:30
end