Skip to content

Commit 6c1632a

Browse files
committed
Switch tests over to rspec, add basic github tests
1 parent dbe0838 commit 6c1632a

File tree

20 files changed

+374
-36
lines changed

20 files changed

+374
-36
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ jobs:
8484
- name: Run tests
8585
env:
8686
RAILS_ENV: test
87-
run: bin/rails db:test:prepare test test:system
87+
run: bin/rails db:test:prepare spec
8888

8989
- name: Keep screenshots from failed system tests
9090
uses: actions/upload-artifact@v4

.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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ group :development, :test do
4343

4444
# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
4545
gem "rubocop-rails-omakase", require: false
46+
47+
gem "capybara", require: "capybara"
48+
gem "selenium-webdriver"
49+
gem "rspec-rails", "~> 8.0.0"
50+
gem "faker"
51+
gem "factory_bot_rails"
4652
end
4753

4854
group :development do
@@ -55,12 +61,6 @@ group :development do
5561
gem "memory_profiler"
5662
end
5763

58-
group :test do
59-
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
60-
gem "capybara"
61-
gem "selenium-webdriver"
62-
end
63-
6464
# Application dependencies
6565
gem "version_sorter"
6666
gem "skylight", require: false

Gemfile.lock

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,18 @@ GEM
130130
ruby-statistics (>= 4.0.1)
131131
ruby2_keywords
132132
thor (>= 0.19, < 2)
133+
diff-lcs (1.6.1)
133134
drb (2.2.1)
134135
erubi (1.13.1)
135136
et-orbi (1.2.11)
136137
tzinfo
138+
factory_bot (6.5.1)
139+
activesupport (>= 6.1.0)
140+
factory_bot_rails (6.4.4)
141+
factory_bot (~> 6.5)
142+
railties (>= 5.0.0)
143+
faker (3.5.1)
144+
i18n (>= 1.8.11, < 2)
137145
ffi (1.17.2-aarch64-linux-musl)
138146
ffi (1.17.2-arm64-darwin)
139147
ffi (1.17.2-x64-mingw-ucrt)
@@ -294,6 +302,23 @@ GEM
294302
reline (0.6.1)
295303
io-console (~> 0.5)
296304
rexml (3.4.1)
305+
rspec-core (3.13.3)
306+
rspec-support (~> 3.13.0)
307+
rspec-expectations (3.13.4)
308+
diff-lcs (>= 1.2.0, < 2.0)
309+
rspec-support (~> 3.13.0)
310+
rspec-mocks (3.13.4)
311+
diff-lcs (>= 1.2.0, < 2.0)
312+
rspec-support (~> 3.13.0)
313+
rspec-rails (8.0.0)
314+
actionpack (>= 7.2)
315+
activesupport (>= 7.2)
316+
railties (>= 7.2)
317+
rspec-core (~> 3.13)
318+
rspec-expectations (~> 3.13)
319+
rspec-mocks (~> 3.13)
320+
rspec-support (~> 3.13)
321+
rspec-support (3.13.3)
297322
rubocop (1.75.3)
298323
json (~> 2.3)
299324
language_server-protocol (~> 3.17.0.2)
@@ -327,7 +352,7 @@ GEM
327352
ruby2_keywords (0.0.5)
328353
rubyzip (2.4.1)
329354
securerandom (0.4.1)
330-
selenium-webdriver (4.31.0)
355+
selenium-webdriver (4.32.0)
331356
base64 (~> 0.2)
332357
logger (~> 1.4)
333358
rexml (~> 3.2, >= 3.2.5)
@@ -410,6 +435,8 @@ DEPENDENCIES
410435
debug
411436
deep_merge
412437
derailed_benchmarks
438+
factory_bot_rails
439+
faker
413440
flamegraph
414441
github-markup
415442
importmap-rails
@@ -428,6 +455,7 @@ DEPENDENCIES
428455
rdiscount
429456
rdoc
430457
redcarpet
458+
rspec-rails (~> 8.0.0)
431459
rubocop-rails-omakase
432460
selenium-webdriver
433461
skylight

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")

config/routes.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@
4242
end
4343

4444
%W[#{} search/ list/ static/].each do |prefix|
45-
get "#{prefix}docs/:name(/*rest)", to: "yard#featured", as: prefix.blank? ? "yard_featured" : nil
46-
get "#{prefix}stdlib/:name(/*rest)", to: "yard#stdlib", as: prefix.blank? ? "yard_stdlib" : nil
47-
get "#{prefix}gems/:name(/*rest)", to: "yard#gems", as: prefix.blank? ? "yard_gems" : nil
48-
get "#{prefix}github/:username/:project(/*rest)", to: "yard#github", as: prefix.blank? ? "yard_github" : nil
45+
get "#{prefix}docs/:name(/*rest)", to: "yard#featured", as: prefix.blank? ? "yard_featured" : nil, format: false
46+
get "#{prefix}stdlib/:name(/*rest)", to: "yard#stdlib", as: prefix.blank? ? "yard_stdlib" : nil, format: false
47+
get "#{prefix}gems/:name(/*rest)", to: "yard#gems", as: prefix.blank? ? "yard_gems" : nil, format: false
48+
get "#{prefix}github/:username/:project(/*rest(.:format))", to: "yard#github", as: prefix.blank? ? "yard_github" : nil,
49+
constraints: { username: /[a-z0-9_\.-]+/i, project: /[a-z0-9_\.-]+/i }, format: false
4950
end
5051

51-
get "/js/*rest(.:format)", to: redirect("/assets/js/%{rest}.%{format}", status: 302)
52-
get "/css/*rest(.:format)", to: redirect("/assets/css/%{rest}.%{format}", status: 302)
53-
get "/images/*rest(.:format)", to: redirect("/assets/images/%{rest}.%{format}", status: 302)
52+
get "/js/*rest", to: redirect("/assets/js/%{rest}", status: 302), format: false
53+
get "/css/*rest", to: redirect("/assets/css/%{rest}", status: 302), format: false
54+
get "/images/*rest", to: redirect("/assets/images/%{rest}", status: 302), format: false
5455

5556
mount MissionControl::Jobs::Engine, at: "/jobs"
5657
end

lib/tasks/rubydoc.rake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace :rubydoc do
3333

3434
namespace :db do
3535
task :start do
36-
system "docker compose up -d >/dev/null 2>&1" if Rails.env.development?
36+
system "docker compose up -d >/dev/null 2>&1"
3737
end
3838
end
3939
end

spec/factories/libraries.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FactoryBot.define do
2+
factory :library do
3+
name { Faker::Internet.unique.username }
4+
versions { Faker::Number.between(from: 1, to: 10).to_i.times.map { Faker::Number.number(digits: 3).to_s.split("").join(".") } }
5+
6+
factory :gem do
7+
source { :remote_gem }
8+
end
9+
10+
factory :github do
11+
source { :github }
12+
owner { Faker::Internet.unique.username }
13+
versions { Faker::Number.between(from: 1, to: 10).to_i.times.map { Faker::Internet.unique.username } }
14+
end
15+
16+
factory :stdlib do
17+
source { :stdlib }
18+
end
19+
20+
factory :featured do
21+
source { :featured }
22+
end
23+
end
24+
end

spec/rails_helper.rb

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

spec/spec_helper.rb

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
config.before(type: :system) do
41+
driven_by :selenium, using: :headless_chrome, screen_size: [ 1200, 800 ]
42+
end
43+
44+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
45+
# have no way to turn it off -- the option exists only for backwards
46+
# compatibility in RSpec 3). It causes shared context metadata to be
47+
# inherited by the metadata hash of host groups and examples, rather than
48+
# triggering implicit auto-inclusion in groups with matching metadata.
49+
config.shared_context_metadata_behavior = :apply_to_host_groups
50+
51+
# The settings below are suggested to provide a good initial experience
52+
# with RSpec, but feel free to customize to your heart's content.
53+
=begin
54+
# This allows you to limit a spec run to individual examples or groups
55+
# you care about by tagging them with `:focus` metadata. When nothing
56+
# is tagged with `:focus`, all examples get run. RSpec also provides
57+
# aliases for `it`, `describe`, and `context` that include `:focus`
58+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
59+
config.filter_run_when_matching :focus
60+
61+
# Allows RSpec to persist some state between runs in order to support
62+
# the `--only-failures` and `--next-failure` CLI options. We recommend
63+
# you configure your source control system to ignore this file.
64+
config.example_status_persistence_file_path = "spec/examples.txt"
65+
66+
# Limits the available syntax to the non-monkey patched syntax that is
67+
# recommended. For more details, see:
68+
# https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
69+
config.disable_monkey_patching!
70+
71+
# Many RSpec users commonly either run the entire suite or an individual
72+
# file, and it's useful to allow more verbose output when running an
73+
# individual spec file.
74+
if config.files_to_run.one?
75+
# Use the documentation formatter for detailed output,
76+
# unless a formatter has already been configured
77+
# (e.g. via a command-line flag).
78+
config.default_formatter = "doc"
79+
end
80+
81+
# Print the 10 slowest examples and example groups at the
82+
# end of the spec run, to help surface which specs are running
83+
# particularly slow.
84+
config.profile_examples = 10
85+
86+
# Run specs in random order to surface order dependencies. If you find an
87+
# order dependency and want to debug it, you can fix the order by providing
88+
# the seed, which is printed after each run.
89+
# --seed 1234
90+
config.order = :random
91+
92+
# Seed global randomization in this process using the `--seed` CLI option.
93+
# Setting this allows you to use `--seed` to deterministically reproduce
94+
# test failures related to randomization by passing the same `--seed` value
95+
# as the one that triggered the failure.
96+
Kernel.srand config.seed
97+
=end
98+
end
99+
100+
def with_rubydoc_config(config)
101+
let(:original_config) { Rubydoc.config }
102+
before { Rubydoc.config = config }
103+
after { Rubydoc.config = original_config }
104+
yield
105+
end

0 commit comments

Comments
 (0)