Skip to content

Commit 6d1943b

Browse files
authored
Setup testing framework 7 (#32)
2 parents 1c25485 + 1a7e469 commit 6d1943b

File tree

8 files changed

+247
-0
lines changed

8 files changed

+247
-0
lines changed

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ group :development, :test do
4949

5050
# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
5151
gem "rubocop-rails-omakase", require: false
52+
53+
gem "rspec-rails"
54+
gem "factory_bot_rails"
5255
end
5356

5457
group :development do
@@ -60,4 +63,5 @@ group :test do
6063
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
6164
gem "capybara"
6265
gem "selenium-webdriver"
66+
gem "shoulda-matchers"
6367
end

Gemfile.lock

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ GEM
7777
ast (2.4.2)
7878
base64 (0.2.0)
7979
bcrypt_pbkdf (1.1.1)
80+
bcrypt_pbkdf (1.1.1-arm64-darwin)
81+
bcrypt_pbkdf (1.1.1-x86_64-darwin)
8082
benchmark (0.4.0)
8183
bigdecimal (3.1.9)
8284
bindex (0.8.1)
@@ -101,12 +103,18 @@ GEM
101103
debug (1.10.0)
102104
irb (~> 1.10)
103105
reline (>= 0.3.8)
106+
diff-lcs (1.5.1)
104107
dotenv (3.1.7)
105108
drb (2.2.1)
106109
ed25519 (1.3.0)
107110
erubi (1.13.1)
108111
et-orbi (1.2.11)
109112
tzinfo
113+
factory_bot (6.5.1)
114+
activesupport (>= 6.1.0)
115+
factory_bot_rails (6.4.4)
116+
factory_bot (~> 6.5)
117+
railties (>= 5.0.0)
110118
fugit (1.11.1)
111119
et-orbi (~> 1, >= 1.2.11)
112120
raabro (~> 1.4)
@@ -250,6 +258,23 @@ GEM
250258
reline (0.6.0)
251259
io-console (~> 0.5)
252260
rexml (3.4.0)
261+
rspec-core (3.13.2)
262+
rspec-support (~> 3.13.0)
263+
rspec-expectations (3.13.3)
264+
diff-lcs (>= 1.2.0, < 2.0)
265+
rspec-support (~> 3.13.0)
266+
rspec-mocks (3.13.2)
267+
diff-lcs (>= 1.2.0, < 2.0)
268+
rspec-support (~> 3.13.0)
269+
rspec-rails (7.1.0)
270+
actionpack (>= 7.0)
271+
activesupport (>= 7.0)
272+
railties (>= 7.0)
273+
rspec-core (~> 3.13)
274+
rspec-expectations (~> 3.13)
275+
rspec-mocks (~> 3.13)
276+
rspec-support (~> 3.13)
277+
rspec-support (3.13.2)
253278
rubocop (1.71.0)
254279
json (~> 2.3)
255280
language_server-protocol (>= 3.17.0)
@@ -287,6 +312,8 @@ GEM
287312
rexml (~> 3.2, >= 3.2.5)
288313
rubyzip (>= 1.2.2, < 3.0)
289314
websocket (~> 1.0)
315+
shoulda-matchers (6.4.0)
316+
activesupport (>= 5.2.0)
290317
solid_cable (3.0.7)
291318
actioncable (>= 7.2)
292319
activejob (>= 7.2)
@@ -360,15 +387,18 @@ DEPENDENCIES
360387
brakeman
361388
capybara
362389
debug
390+
factory_bot_rails
363391
importmap-rails
364392
jbuilder
365393
kamal
366394
pg (~> 1.1)
367395
propshaft
368396
puma (>= 5.0)
369397
rails (~> 8.0.1)
398+
rspec-rails
370399
rubocop-rails-omakase
371400
selenium-webdriver
401+
shoulda-matchers
372402
solid_cable
373403
solid_cache
374404
solid_queue

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,15 @@ SkillRX is one of many projects initiated and run by Ruby for Good. You can find
1010

1111
# Welcome Contributors!
1212
Thank you for checking out our work. We are in the process of setting up the repository, roadmap, values, and contribution guidelines for the project. We will be adding issues and putting out a call for contributions soon.
13+
14+
# Testing
15+
16+
This project uses:
17+
* `rspec` for testing
18+
* `shoulda-matchers` for expectations
19+
* `factory_bot` for making records
20+
21+
To run tests execute
22+
```
23+
bin/rspec
24+
```

bin/rspec

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'rspec' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12+
13+
bundle_binstub = File.expand_path("bundle", __dir__)
14+
15+
if File.file?(bundle_binstub)
16+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
17+
load(bundle_binstub)
18+
else
19+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21+
end
22+
end
23+
24+
require "rubygems"
25+
require "bundler/setup"
26+
27+
load Gem.bin_path("rspec-core", "rspec")

spec/rails_helper.rb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each(&method(:require))
36+
RSpec.configure do |config|
37+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
38+
config.fixture_paths = [
39+
Rails.root.join('spec/fixtures')
40+
]
41+
42+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
43+
# examples within a transaction, remove the following line or assign false
44+
# instead of true.
45+
config.use_transactional_fixtures = true
46+
47+
# You can uncomment this line to turn off ActiveRecord support entirely.
48+
# config.use_active_record = false
49+
50+
# RSpec Rails uses metadata to mix in different behaviours to your tests,
51+
# for example enabling you to call `get` and `post` in request specs. e.g.:
52+
#
53+
# RSpec.describe UsersController, type: :request do
54+
# # ...
55+
# end
56+
#
57+
# The different available types are documented in the features, such as in
58+
# https://rspec.info/features/7-0/rspec-rails
59+
#
60+
# You can also this infer these behaviours automatically by location, e.g.
61+
# /spec/models would pull in the same behaviour as `type: :model` but this
62+
# behaviour is considered legacy and will be removed in a future version.
63+
#
64+
# To enable this behaviour uncomment the line below.
65+
# config.infer_spec_type_from_file_location!
66+
67+
# Filter lines from Rails gems in backtraces.
68+
config.filter_rails_from_backtrace!
69+
# arbitrary gems may also be filtered via:
70+
# config.filter_gems_from_backtrace("gem name")
71+
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

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

spec/support/shoulda.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Shoulda::Matchers.configure do |config|
2+
config.integrate do |with|
3+
with.test_framework :rspec
4+
with.library :rails
5+
end
6+
end

0 commit comments

Comments
 (0)