Skip to content
Open

Rspec #118

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ gem 'bootsnap', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
gem 'rspec', '~> 3.10.0'
gem 'rspec-rails', '~> 5.0.0'
end

group :development do
Expand Down
24 changes: 24 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ GEM
byebug (11.1.3)
concurrent-ruby (1.1.9)
crass (1.0.6)
diff-lcs (1.4.4)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
erubi (1.10.0)
Expand Down Expand Up @@ -121,6 +122,27 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-rails (5.0.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
railties (>= 5.2)
rspec-core (~> 3.10)
rspec-expectations (~> 3.10)
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.2)
ruby_dep (1.5.0)
spring (2.1.1)
spring-watcher-listen (2.0.1)
Expand Down Expand Up @@ -155,6 +177,8 @@ DEPENDENCIES
puma (~> 3.7)
rails (~> 5.2.0)
rest-client (>= 2.1.0.rc1, < 2.2)
rspec (~> 3.10.0)
rspec-rails (~> 5.0.0)
spring
spring-watcher-listen (~> 2.0.0)
sqlite3
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ Apium is an API to access all public Center for Digital Research in the Humaniti
**[Apium Documentation](docs/README.md)**

This project is licensed under the terms of the [MIT license](LICENSE.md).

## Run tests

Run tests with `rails spec` or `rspec`
40 changes: 40 additions & 0 deletions docs/adr/1_rspec_for_testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 1. Use rspec for testing

Date: October 2021

## Context

Prior to October 2021, there were very few tests for the API checking functionality of the `SearchItemReq` and `SearchItemRes` classes written in minitest.

## Decision

We will use rspec for our tests

### RSpec

Pros:

- `rspec-rails` imitates rails app file loading
- describe / context / it statements provide self-documentation of features and behavior
- well supported and used by many
- extremely powerful mocking / stubbing and request functionality

Cons:

- fairly heavy application
- documentation can be confusing

### Minitest

Pros:

- very lightweight library
- default for Rails

Cons:

- more basic in functionality

## Consequences

This change required us to migrate our existing tests from minitest to rspec. Additionally, this adds the dependency of rspec and several rspec-* libraries, rather than the built-in minitest. However, it will allow us to more thoroughly test the API in the future when we have time to think through and write tests!
9 changes: 9 additions & 0 deletions lib/tasks/spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
begin
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
rescue LoadError
# no rspec available
end
File renamed without changes.
64 changes: 64 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }

# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove these lines.
begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
puts e.to_s.strip
exit 1
end
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true

# You can uncomment this line to turn off ActiveRecord support entirely.
# config.use_active_record = false

# RSpec Rails can automatically mix in different behaviours to your tests
# based on their file location, for example enabling you to call `get` and
# `post` in specs under `spec/controllers`.
#
# You can disable this behaviour by removing the line below, and instead
# explicitly tag your specs with their type, e.g.:
#
# RSpec.describe UsersController, type: :controller do
# # ...
# end
#
# The different available types are documented in the features, such as in
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!

# Filter lines from Rails gems in backtraces.
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
end
Loading