Skip to content

Commit 81de3ae

Browse files
committed
Add RSpec, factory_bot gems
1 parent 51a2fb6 commit 81de3ae

File tree

5 files changed

+203
-45
lines changed

5 files changed

+203
-45
lines changed

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--require spec_helper

Gemfile

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,33 @@
11
source "https://rubygems.org"
22

3-
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
4-
gem "rails", "~> 8.0.0"
5-
# The modern asset pipeline for Rails [https://github.com/rails/propshaft]
3+
gem "bootsnap", require: false
4+
gem "cssbundling-rails"
5+
gem "devise", "~> 4.9"
6+
gem "jsonapi-serializer"
7+
gem "jsbundling-rails"
8+
gem "jbuilder"
9+
gem "kamal", require: false
610
gem "propshaft"
7-
# Use postgresql as the database for Active Record
811
gem "pg", "~> 1.1"
9-
# Use the Puma web server [https://github.com/puma/puma]
1012
gem "puma", ">= 5.0"
11-
# Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]
12-
gem "jsbundling-rails"
13-
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
14-
gem "turbo-rails"
15-
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
13+
gem "rails", "~> 8.0.0"
1614
gem "stimulus-rails"
17-
# Bundle and process CSS [https://github.com/rails/cssbundling-rails]
18-
gem "cssbundling-rails"
19-
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
20-
gem "jbuilder"
21-
22-
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
23-
# gem "bcrypt", "~> 3.1.7"
24-
25-
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
26-
gem "tzinfo-data", platforms: %i[ windows jruby ]
27-
28-
# Use the database-backed adapters for Rails.cache, Active Job, and Action Cable
2915
gem "solid_cache"
3016
gem "solid_queue"
3117
gem "solid_cable"
32-
33-
# Reduces boot times through caching; required in config/boot.rb
34-
gem "bootsnap", require: false
35-
36-
# Deploy this application anywhere as a Docker container [https://kamal-deploy.org]
37-
gem "kamal", require: false
38-
39-
# Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/]
18+
gem "turbo-rails"
19+
gem "tzinfo-data", platforms: %i[ windows jruby ]
4020
gem "thruster", require: false
4121

42-
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
43-
# gem "image_processing", "~> 1.2"
44-
4522
group :development, :test do
46-
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
4723
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
48-
49-
# Static analysis for security vulnerabilities [https://brakemanscanner.org/]
5024
gem "brakeman", require: false
51-
52-
# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
5325
gem "rubocop-rails-omakase", require: false
26+
gem "rspec-rails"
27+
gem "factory_bot_rails"
28+
gem "faker", "~> 3.5"
5429
end
5530

5631
group :development do
57-
# Use console on exceptions pages [https://github.com/rails/web-console]
5832
gem "web-console"
5933
end
60-
61-
gem "devise", "~> 4.9"
62-
63-
gem "jsonapi-serializer"
64-
65-
gem "faker", "~> 3.5"

Gemfile.lock

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,18 @@ GEM
101101
railties (>= 4.1.0)
102102
responders
103103
warden (~> 1.2.3)
104+
diff-lcs (1.5.1)
104105
dotenv (3.1.4)
105106
drb (2.2.1)
106107
ed25519 (1.3.0)
107108
erubi (1.13.0)
108109
et-orbi (1.2.11)
109110
tzinfo
111+
factory_bot (6.5.0)
112+
activesupport (>= 5.0.0)
113+
factory_bot_rails (6.4.4)
114+
factory_bot (~> 6.5)
115+
railties (>= 5.0.0)
110116
faker (3.5.1)
111117
i18n (>= 1.8.11, < 2)
112118
fugit (1.11.1)
@@ -244,6 +250,23 @@ GEM
244250
responders (3.1.1)
245251
actionpack (>= 5.2)
246252
railties (>= 5.2)
253+
rspec-core (3.13.2)
254+
rspec-support (~> 3.13.0)
255+
rspec-expectations (3.13.3)
256+
diff-lcs (>= 1.2.0, < 2.0)
257+
rspec-support (~> 3.13.0)
258+
rspec-mocks (3.13.2)
259+
diff-lcs (>= 1.2.0, < 2.0)
260+
rspec-support (~> 3.13.0)
261+
rspec-rails (7.1.0)
262+
actionpack (>= 7.0)
263+
activesupport (>= 7.0)
264+
railties (>= 7.0)
265+
rspec-core (~> 3.13)
266+
rspec-expectations (~> 3.13)
267+
rspec-mocks (~> 3.13)
268+
rspec-support (~> 3.13)
269+
rspec-support (3.13.2)
247270
rubocop (1.68.0)
248271
json (~> 2.3)
249272
language_server-protocol (>= 3.17.0)
@@ -340,6 +363,7 @@ DEPENDENCIES
340363
cssbundling-rails
341364
debug
342365
devise (~> 4.9)
366+
factory_bot_rails
343367
faker (~> 3.5)
344368
jbuilder
345369
jsbundling-rails
@@ -349,6 +373,7 @@ DEPENDENCIES
349373
propshaft
350374
puma (>= 5.0)
351375
rails (~> 8.0.0)
376+
rspec-rails
352377
rubocop-rails-omakase
353378
solid_cable
354379
solid_cache

spec/rails_helper.rb

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# This file is copied to spec/ when you run 'rails generate rspec:install'
2+
require 'spec_helper'
3+
ENV['RAILS_ENV'] ||= 'test'
4+
require_relative '../config/environment'
5+
# Prevent database truncation if the environment is production
6+
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?
10+
require 'rspec/rails'
11+
# Add additional requires below this line. Rails is not loaded until this point!
12+
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.
30+
begin
31+
ActiveRecord::Migration.maintain_test_schema!
32+
rescue ActiveRecord::PendingMigrationError => e
33+
abort e.to_s.strip
34+
end
35+
RSpec.configure do |config|
36+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
37+
config.fixture_paths = [
38+
Rails.root.join('spec/fixtures')
39+
]
40+
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.
44+
config.use_transactional_fixtures = true
45+
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.
67+
config.filter_rails_from_backtrace!
68+
# arbitrary gems may also be filtered via:
69+
# config.filter_gems_from_backtrace("gem name")
70+
end

spec/spec_helper.rb

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
2+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3+
# The generated `.rspec` file contains `--require spec_helper` which will cause
4+
# this file to always be loaded, without a need to explicitly require it in any
5+
# files.
6+
#
7+
# Given that it is always loaded, you are encouraged to keep this file as
8+
# light-weight as possible. Requiring heavyweight dependencies from this file
9+
# will add to the boot time of your test suite on EVERY test run, even for an
10+
# individual file that may not need all of that loaded. Instead, consider making
11+
# a separate helper file that requires the additional dependencies and performs
12+
# the additional setup, and require it from the spec files that actually need
13+
# it.
14+
#
15+
# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16+
RSpec.configure do |config|
17+
# rspec-expectations config goes here. You can use an alternate
18+
# assertion/expectation library such as wrong or the stdlib/minitest
19+
# assertions if you prefer.
20+
config.expect_with :rspec do |expectations|
21+
# This option will default to `true` in RSpec 4. It makes the `description`
22+
# and `failure_message` of custom matchers include text for helper methods
23+
# defined using `chain`, e.g.:
24+
# be_bigger_than(2).and_smaller_than(4).description
25+
# # => "be bigger than 2 and smaller than 4"
26+
# ...rather than:
27+
# # => "be bigger than 2"
28+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29+
end
30+
31+
# rspec-mocks config goes here. You can use an alternate test double
32+
# library (such as bogus or mocha) by changing the `mock_with` option here.
33+
config.mock_with :rspec do |mocks|
34+
# Prevents you from mocking or stubbing a method that does not exist on
35+
# a real object. This is generally recommended, and will default to
36+
# `true` in RSpec 4.
37+
mocks.verify_partial_doubles = true
38+
end
39+
40+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41+
# have no way to turn it off -- the option exists only for backwards
42+
# compatibility in RSpec 3). It causes shared context metadata to be
43+
# inherited by the metadata hash of host groups and examples, rather than
44+
# triggering implicit auto-inclusion in groups with matching metadata.
45+
config.shared_context_metadata_behavior = :apply_to_host_groups
46+
47+
# The settings below are suggested to provide a good initial experience
48+
# with RSpec, but feel free to customize to your heart's content.
49+
=begin
50+
# This allows you to limit a spec run to individual examples or groups
51+
# you care about by tagging them with `:focus` metadata. When nothing
52+
# is tagged with `:focus`, all examples get run. RSpec also provides
53+
# aliases for `it`, `describe`, and `context` that include `:focus`
54+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55+
config.filter_run_when_matching :focus
56+
57+
# Allows RSpec to persist some state between runs in order to support
58+
# the `--only-failures` and `--next-failure` CLI options. We recommend
59+
# you configure your source control system to ignore this file.
60+
config.example_status_persistence_file_path = "spec/examples.txt"
61+
62+
# Limits the available syntax to the non-monkey patched syntax that is
63+
# recommended. For more details, see:
64+
# https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
65+
config.disable_monkey_patching!
66+
67+
# Many RSpec users commonly either run the entire suite or an individual
68+
# file, and it's useful to allow more verbose output when running an
69+
# individual spec file.
70+
if config.files_to_run.one?
71+
# Use the documentation formatter for detailed output,
72+
# unless a formatter has already been configured
73+
# (e.g. via a command-line flag).
74+
config.default_formatter = "doc"
75+
end
76+
77+
# Print the 10 slowest examples and example groups at the
78+
# end of the spec run, to help surface which specs are running
79+
# particularly slow.
80+
config.profile_examples = 10
81+
82+
# Run specs in random order to surface order dependencies. If you find an
83+
# order dependency and want to debug it, you can fix the order by providing
84+
# the seed, which is printed after each run.
85+
# --seed 1234
86+
config.order = :random
87+
88+
# Seed global randomization in this process using the `--seed` CLI option.
89+
# Setting this allows you to use `--seed` to deterministically reproduce
90+
# test failures related to randomization by passing the same `--seed` value
91+
# as the one that triggered the failure.
92+
Kernel.srand config.seed
93+
=end
94+
end

0 commit comments

Comments
 (0)