Skip to content

Commit dd7cbc8

Browse files
authored
Revert "Revert "FYST-2136 switch test runner to rspec & use postgresql as well"" (#35)
* Revert "Revert "FYST-2136 switch test runner to rspec & use postgresql as wel…" This reverts commit e7fe175. * Add libpq-dev to allow Docker build to find PostgreSQL client library * Add changes copied over from a new rails app generated with postgresql
1 parent e7fe175 commit dd7cbc8

19 files changed

Lines changed: 228 additions & 69 deletions

File tree

.github/workflows/ci.yml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ name: Run Linter and Tests
22

33
on:
44
pull_request:
5+
workflow_call:
56
push:
67
branches: [ main ]
7-
workflow_call:
8+
workflow_dispatch:
89

910
jobs:
1011
scan_ruby:
@@ -57,15 +58,22 @@ jobs:
5758
test:
5859
runs-on: ubuntu-latest
5960

60-
# services:
61-
# redis:
62-
# image: redis
63-
# ports:
64-
# - 6379:6379
65-
# options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
61+
services:
62+
postgres:
63+
image: postgres
64+
env:
65+
RAILS_ENV: test
66+
POSTGRES_USER: postgres
67+
POSTGRES_PASSWORD: postgres
68+
ports:
69+
- 5432:5432
70+
options: --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3
71+
6672
steps:
6773
- name: Install packages
68-
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config google-chrome-stable
74+
run: |
75+
sudo apt-get update && sudo apt-get install --no-install-recommends -y build-essential git libpq-dev libyaml-dev node-gyp pkg-config python-is-python3 google-chrome-stable
76+
sudo apt-get install -y libpq-dev
6977
7078
- name: Checkout code
7179
uses: actions/checkout@v4
@@ -79,13 +87,5 @@ jobs:
7987
- name: Run tests
8088
env:
8189
RAILS_ENV: test
82-
# REDIS_URL: redis://localhost:6379/0
83-
run: bin/rails db:test:prepare test test:system
84-
85-
- name: Keep screenshots from failed system tests
86-
uses: actions/upload-artifact@v4
87-
if: failure()
88-
with:
89-
name: screenshots
90-
path: ${{ github.workspace }}/tmp/screenshots
91-
if-no-files-found: ignore
90+
DATABASE_URL: postgres://postgres:postgres@localhost:5432
91+
run: RAILS_ENV=test bin/rails db:test:prepare spec

.rspec

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

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ WORKDIR /rails
1616

1717
# Install base packages
1818
RUN apt-get update -qq && \
19-
apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 && \
19+
apt-get install --no-install-recommends -y curl libjemalloc2 libvips postgresql-client && \
2020
rm -rf /var/lib/apt/lists /var/cache/apt/archives
2121

2222
# Set production environment
@@ -30,7 +30,7 @@ FROM base AS build
3030

3131
# Install packages needed to build gems
3232
RUN apt-get update -qq && \
33-
apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config && \
33+
apt-get install --no-install-recommends -y build-essential git libpq-dev libyaml-dev pkg-config && \
3434
rm -rf /var/lib/apt/lists /var/cache/apt/archives
3535

3636
# Install application gems

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ source "https://rubygems.org"
44
gem "rails", "~> 8.0.2"
55
# The modern asset pipeline for Rails [https://github.com/rails/propshaft]
66
gem "propshaft"
7-
# Use sqlite3 as the database for Active Record
8-
gem "sqlite3", ">= 2.1"
7+
gem "pg"
98
# Use the Puma web server [https://github.com/puma/puma]
109
gem "puma", ">= 5.0"
1110
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
@@ -50,6 +49,7 @@ group :development, :test do
5049

5150
# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
5251
gem "rubocop-rails-omakase", require: false
52+
gem "rspec-rails"
5353
end
5454

5555
group :development do

Gemfile.lock

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ GEM
122122
debug (1.10.0)
123123
irb (~> 1.10)
124124
reline (>= 0.3.8)
125+
diff-lcs (1.6.2)
125126
dotenv (3.1.8)
126127
drb (2.2.3)
127128
ed25519 (1.4.0)
@@ -246,6 +247,7 @@ GEM
246247
parser (3.3.8.0)
247248
ast (~> 2.4.1)
248249
racc
250+
pg (1.5.9)
249251
pp (0.6.2)
250252
prettyprint
251253
prettyprint (0.2.0)
@@ -312,6 +314,23 @@ GEM
312314
reline (0.6.1)
313315
io-console (~> 0.5)
314316
rexml (3.4.1)
317+
rspec-core (3.13.4)
318+
rspec-support (~> 3.13.0)
319+
rspec-expectations (3.13.5)
320+
diff-lcs (>= 1.2.0, < 2.0)
321+
rspec-support (~> 3.13.0)
322+
rspec-mocks (3.13.5)
323+
diff-lcs (>= 1.2.0, < 2.0)
324+
rspec-support (~> 3.13.0)
325+
rspec-rails (8.0.0)
326+
actionpack (>= 7.2)
327+
activesupport (>= 7.2)
328+
railties (>= 7.2)
329+
rspec-core (~> 3.13)
330+
rspec-expectations (~> 3.13)
331+
rspec-mocks (~> 3.13)
332+
rspec-support (~> 3.13)
333+
rspec-support (3.13.4)
315334
rubocop (1.75.7)
316335
json (~> 2.3)
317336
language_server-protocol (~> 3.17.0.2)
@@ -386,14 +405,6 @@ GEM
386405
fugit (~> 1.11.0)
387406
railties (>= 7.1)
388407
thor (~> 1.3.1)
389-
sqlite3 (2.7.0-aarch64-linux-gnu)
390-
sqlite3 (2.7.0-aarch64-linux-musl)
391-
sqlite3 (2.7.0-arm-linux-gnu)
392-
sqlite3 (2.7.0-arm-linux-musl)
393-
sqlite3 (2.7.0-arm64-darwin)
394-
sqlite3 (2.7.0-x86_64-darwin)
395-
sqlite3 (2.7.0-x86_64-linux-gnu)
396-
sqlite3 (2.7.0-x86_64-linux-musl)
397408
sshkit (1.24.0)
398409
base64
399410
logger
@@ -457,15 +468,16 @@ DEPENDENCIES
457468
importmap-rails
458469
jbuilder
459470
kamal
471+
pg
460472
propshaft
461473
puma (>= 5.0)
462474
rails (~> 8.0.2)
475+
rspec-rails
463476
rubocop-rails-omakase
464477
selenium-webdriver
465478
solid_cable
466479
solid_cache
467480
solid_queue
468-
sqlite3 (>= 2.1)
469481
stimulus-rails
470482
thruster
471483
turbo-rails

config/database.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
# SQLite. Versions 3.8.0 and up are supported.
2-
# gem install sqlite3
3-
#
4-
# Ensure the SQLite 3 gem is defined in your Gemfile
5-
# gem "sqlite3"
6-
#
71
default: &default
8-
adapter: sqlite3
2+
adapter: postgresql
3+
encoding: unicode
94
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
105
timeout: 5000
116

127
development:
138
<<: *default
14-
database: storage/development.sqlite3
9+
database: prior_year_access_development
10+
host: localhost
11+
port: 5432
1512

1613
# Warning: The database defined as "test" will be erased and
1714
# re-generated from your development database when you run "rake".
1815
# Do not set this db to the same as development or production.
1916
test:
2017
<<: *default
21-
database: storage/test.sqlite3
22-
18+
database: prior_year_access_test
19+
host: localhost
20+
port: 5432
2321

2422
# Store production database in the storage/ directory, which by default
2523
# is mounted as a persistent Docker volume in config/deploy.yml.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require "rails_helper"
2+
3+
RSpec.describe PagesController, type: :request do
4+
describe "/" do
5+
it "returns a successful response" do
6+
get first_page_url
7+
expect(response).to be_ok
8+
end
9+
end
10+
end

spec/rails_helper.rb

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

test/application_system_test_case.rb

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)