Skip to content

Commit 4a2864a

Browse files
committed
Add shoulda matchers, and config factory bot
1 parent 81de3ae commit 4a2864a

File tree

4 files changed

+16
-49
lines changed

4 files changed

+16
-49
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ group :development, :test do
2626
gem "rspec-rails"
2727
gem "factory_bot_rails"
2828
gem "faker", "~> 3.5"
29+
gem "shoulda-matchers"
2930
end
3031

3132
group :development do

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ GEM
297297
rubocop-rails
298298
ruby-progressbar (1.13.0)
299299
securerandom (0.3.2)
300+
shoulda-matchers (6.4.0)
301+
activesupport (>= 5.2.0)
300302
solid_cable (3.0.2)
301303
actioncable (>= 7.2)
302304
activejob (>= 7.2)
@@ -375,6 +377,7 @@ DEPENDENCIES
375377
rails (~> 8.0.0)
376378
rspec-rails
377379
rubocop-rails-omakase
380+
shoulda-matchers
378381
solid_cable
379382
solid_cache
380383
solid_queue

spec/rails_helper.rb

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,29 @@
22
require 'spec_helper'
33
ENV['RAILS_ENV'] ||= 'test'
44
require_relative '../config/environment'
5-
# Prevent database truncation if the environment is production
65
abort("The Rails environment is running in production mode!") if Rails.env.production?
7-
# Uncomment the line below in case you have `--require rails_helper` in the `.rspec` file
8-
# that will avoid rails generators crashing because migrations haven't been run yet
9-
# return unless Rails.env.test?
106
require 'rspec/rails'
11-
# Add additional requires below this line. Rails is not loaded until this point!
7+
require_relative 'support/factory_bot'
128

13-
# Requires supporting ruby files with custom matchers and macros, etc, in
14-
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
15-
# run as spec files by default. This means that files in spec/support that end
16-
# in _spec.rb will both be required and run as specs, causing the specs to be
17-
# run twice. It is recommended that you do not name files matching this glob to
18-
# end with _spec.rb. You can configure this pattern with the --pattern
19-
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
20-
#
21-
# The following line is provided for convenience purposes. It has the downside
22-
# of increasing the boot-up time by auto-requiring all files in the support
23-
# directory. Alternatively, in the individual `*_spec.rb` files, manually
24-
# require only the support files necessary.
25-
#
26-
# Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }
27-
28-
# Checks for pending migrations and applies them before tests are run.
29-
# If you are not using ActiveRecord, you can remove these lines.
309
begin
3110
ActiveRecord::Migration.maintain_test_schema!
3211
rescue ActiveRecord::PendingMigrationError => e
3312
abort e.to_s.strip
3413
end
14+
3515
RSpec.configure do |config|
36-
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
3716
config.fixture_paths = [
3817
Rails.root.join('spec/fixtures')
3918
]
4019

41-
# If you're not using ActiveRecord, or you'd prefer not to run each of your
42-
# examples within a transaction, remove the following line or assign false
43-
# instead of true.
4420
config.use_transactional_fixtures = true
4521

46-
# You can uncomment this line to turn off ActiveRecord support entirely.
47-
# config.use_active_record = false
48-
49-
# RSpec Rails uses metadata to mix in different behaviours to your tests,
50-
# for example enabling you to call `get` and `post` in request specs. e.g.:
51-
#
52-
# RSpec.describe UsersController, type: :request do
53-
# # ...
54-
# end
55-
#
56-
# The different available types are documented in the features, such as in
57-
# https://rspec.info/features/7-0/rspec-rails
58-
#
59-
# You can also this infer these behaviours automatically by location, e.g.
60-
# /spec/models would pull in the same behaviour as `type: :model` but this
61-
# behaviour is considered legacy and will be removed in a future version.
62-
#
63-
# To enable this behaviour uncomment the line below.
64-
# config.infer_spec_type_from_file_location!
65-
66-
# Filter lines from Rails gems in backtraces.
6722
config.filter_rails_from_backtrace!
68-
# arbitrary gems may also be filtered via:
69-
# config.filter_gems_from_backtrace("gem name")
23+
end
24+
25+
Shoulda::Matchers.configure do |config|
26+
config.integrate do |with|
27+
with.test_framework :rspec
28+
with.library :rails
29+
end
7030
end

spec/support/factory_bot.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RSpec.configure do |config|
2+
config.include FactoryBot::Syntax::Methods
3+
end

0 commit comments

Comments
 (0)