Skip to content

Commit a1a4b13

Browse files
committed
Configure RSpec
1 parent e832bc5 commit a1a4b13

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ gem "ridgepole"
99

1010
group :development, :test do
1111
gem "debug"
12+
gem "rspec-rails"
1213
end
1314

1415
group :development do

Gemfile.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ GEM
8686
debug (1.9.0)
8787
irb (~> 1.10)
8888
reline (>= 0.3.8)
89+
diff-lcs (1.5.0)
8990
diffy (3.4.2)
9091
drb (2.2.0)
9192
ruby2_keywords
@@ -184,6 +185,23 @@ GEM
184185
ridgepole (2.0.1)
185186
activerecord (>= 6.1, < 7.2)
186187
diffy
188+
rspec-core (3.12.2)
189+
rspec-support (~> 3.12.0)
190+
rspec-expectations (3.12.3)
191+
diff-lcs (>= 1.2.0, < 2.0)
192+
rspec-support (~> 3.12.0)
193+
rspec-mocks (3.12.6)
194+
diff-lcs (>= 1.2.0, < 2.0)
195+
rspec-support (~> 3.12.0)
196+
rspec-rails (6.1.0)
197+
actionpack (>= 6.1)
198+
activesupport (>= 6.1)
199+
railties (>= 6.1)
200+
rspec-core (~> 3.12)
201+
rspec-expectations (~> 3.12)
202+
rspec-mocks (~> 3.12)
203+
rspec-support (~> 3.12)
204+
rspec-support (3.12.1)
187205
rubocop (1.59.0)
188206
json (~> 2.3)
189207
language_server-protocol (>= 3.17.0)
@@ -227,6 +245,7 @@ DEPENDENCIES
227245
puma (>= 5.0)
228246
rails (~> 7.1.2)
229247
ridgepole
248+
rspec-rails
230249
rubocop
231250
sprockets-rails
232251

spec/rails_helper.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
require 'rspec/rails'
8+
# Add additional requires below this line. Rails is not loaded until this point!
9+
10+
# Requires supporting ruby files with custom matchers and macros, etc, in
11+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
12+
# run as spec files by default. This means that files in spec/support that end
13+
# in _spec.rb will both be required and run as specs, causing the specs to be
14+
# run twice. It is recommended that you do not name files matching this glob to
15+
# end with _spec.rb. You can configure this pattern with the --pattern
16+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
17+
#
18+
# The following line is provided for convenience purposes. It has the downside
19+
# of increasing the boot-up time by auto-requiring all files in the support
20+
# directory. Alternatively, in the individual `*_spec.rb` files, manually
21+
# require only the support files necessary.
22+
#
23+
# Rails.root.glob('spec/support/**/*.rb').sort.each { |f| require f }
24+
25+
# Checks for pending migrations and applies them before tests are run.
26+
# If you are not using ActiveRecord, you can remove these lines.
27+
begin
28+
ActiveRecord::Migration.maintain_test_schema!
29+
rescue ActiveRecord::PendingMigrationError => e
30+
abort e.to_s.strip
31+
end
32+
RSpec.configure do |config|
33+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
34+
config.fixture_paths = [
35+
Rails.root.join('spec/fixtures')
36+
]
37+
38+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
39+
# examples within a transaction, remove the following line or assign false
40+
# instead of true.
41+
config.use_transactional_fixtures = true
42+
43+
# You can uncomment this line to turn off ActiveRecord support entirely.
44+
# config.use_active_record = false
45+
46+
# RSpec Rails can automatically mix in different behaviours to your tests
47+
# based on their file location, for example enabling you to call `get` and
48+
# `post` in specs under `spec/controllers`.
49+
#
50+
# You can disable this behaviour by removing the line below, and instead
51+
# explicitly tag your specs with their type, e.g.:
52+
#
53+
# RSpec.describe UsersController, type: :controller do
54+
# # ...
55+
# end
56+
#
57+
# The different available types are documented in the features, such as in
58+
# https://rspec.info/features/6-0/rspec-rails
59+
config.infer_spec_type_from_file_location!
60+
61+
# Filter lines from Rails gems in backtraces.
62+
config.filter_rails_from_backtrace!
63+
# arbitrary gems may also be filtered via:
64+
# config.filter_gems_from_backtrace("gem name")
65+
end

spec/spec_helper.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
RSpec.configure do |config|
2+
config.expect_with :rspec do |expectations|
3+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4+
end
5+
6+
config.mock_with :rspec do |mocks|
7+
mocks.verify_partial_doubles = true
8+
end
9+
10+
config.example_status_persistence_file_path = "spec/examples.txt"
11+
config.disable_monkey_patching!
12+
config.warnings = true
13+
if config.files_to_run.one?
14+
config.default_formatter = 'doc'
15+
end
16+
end

0 commit comments

Comments
 (0)