-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FactoryBot.define do | ||
factory :scholar, class: Scholar do | ||
first_name { Faker::Name.first_name } | ||
last_name { Faker::Name.last_name } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Scholar, type: :model do | ||
describe "#name" do | ||
it "returns full name" do | ||
scholar = build(:scholar, first_name: "Foo") | ||
expect(scholar.name).to eq "Foo #{scholar.last_name}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# This file is copied to spec/ when you run 'rails generate rspec:install' | ||
ENV['RAILS_ENV'] ||= 'test' | ||
require File.expand_path('../../config/environment', __FILE__) | ||
# Prevent database truncation if the environment is production | ||
abort("The Rails environment is running in production mode!") if Rails.env.production? | ||
|
||
require 'spec_helper' | ||
require 'rspec/rails' | ||
|
||
# Requires supporting ruby files with custom matchers and macros, etc, | ||
# in spec/support/ and its subdirectories. | ||
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } | ||
|
||
# Checks for pending migration and applies them before tests are run. | ||
# If you are not using ActiveRecord, you can remove this line. | ||
ActiveRecord::Migration.maintain_test_schema! | ||
|
||
# Setting locale to false to avoid 'InvalidLocale' error in tests | ||
I18n.enforce_available_locales = false | ||
|
||
RSpec.configure do |config| | ||
config.include FactoryBot::Syntax::Methods | ||
|
||
# ## Mock Framework | ||
config.mock_with :rspec | ||
|
||
# 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 | ||
|
||
config.global_fixtures = :all | ||
|
||
# If true, the base class of anonymous controllers will be inferred | ||
# automatically. This will be the default behavior in future versions of | ||
# rspec-rails. | ||
config.infer_base_class_for_anonymous_controllers = false | ||
|
||
# Run specs in random order to surface order dependencies. If you find an | ||
# order dependency and want to debug it, you can fix the order by providing | ||
# the seed, which is printed after each run. | ||
# --seed 1234 | ||
config.order = "random" | ||
end | ||
|
||
# shoulda-matchers no longer installs itself into your test framework automatically | ||
# since upgrade to version 3.0.0 -> https://github.com/thoughtbot/shoulda-matchers/issues/384 | ||
Shoulda::Matchers.configure do |config| | ||
config.integrate do |with| | ||
with.test_framework :rspec | ||
with.library :rails | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration | ||
RSpec.configure do |config| | ||
# These two settings work together to allow you to limit a spec run | ||
# to individual examples or groups you care about by tagging them with | ||
# `:focus` metadata. When nothing is tagged with `:focus`, all examples | ||
# get run. | ||
config.filter_run :focus | ||
config.run_all_when_everything_filtered = true | ||
|
||
# Many RSpec users commonly either run the entire suite or an individual | ||
# file, and it's useful to allow more verbose output when running an | ||
# individual spec file. | ||
if config.files_to_run.one? | ||
# Use the documentation formatter for detailed output, | ||
# unless a formatter has already been configured | ||
# (e.g. via a command-line flag). | ||
config.default_formatter = "doc" | ||
end | ||
|
||
# Run specs in random order to surface order dependencies. If you find an | ||
# order dependency and want to debug it, you can fix the order by providing | ||
# the seed, which is printed after each run. | ||
# --seed 1234 | ||
config.order = :random | ||
|
||
# Seed global randomization in this process using the `--seed` CLI option. | ||
# Setting this allows you to use `--seed` to deterministically reproduce | ||
# test failures related to randomization by passing the same `--seed` value | ||
# as the one that triggered the failure. | ||
Kernel.srand config.seed | ||
|
||
# rspec-expectations config goes here. You can use an alternate | ||
# assertion/expectation library such as wrong or the stdlib/minitest | ||
# assertions if you prefer. | ||
config.expect_with :rspec do |expectations| | ||
# Enable only the newer, non-monkey-patching expect syntax. | ||
# For more details, see: | ||
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax | ||
expectations.syntax = :expect | ||
end | ||
|
||
# disable all monkey patching done by RSpec | ||
# stops exposing DSL globally | ||
# disables should and should_not syntax for rspec-expectations | ||
# disables stub, should_receive, and should_not_receive syntax for rspec-mocks | ||
config.disable_monkey_patching! | ||
|
||
# rspec-mocks config goes here. You can use an alternate test double | ||
# library (such as bogus or mocha) by changing the `mock_with` option here. | ||
config.mock_with :rspec do |mocks| | ||
# Enable only the newer, non-monkey-patching expect syntax. | ||
# For more details, see: | ||
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ | ||
mocks.syntax = :expect | ||
|
||
# Prevents you from mocking or stubbing a method that does not exist on | ||
# a real object. This is generally recommended. | ||
mocks.verify_partial_doubles = true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
RSpec.configure do |config| | ||
config.before(:suite) do | ||
DatabaseCleaner.clean_with(:truncation) | ||
end | ||
|
||
config.before(:each) do | ||
DatabaseCleaner.strategy = :transaction | ||
end | ||
|
||
config.before(:each, js: true) do | ||
DatabaseCleaner.strategy = :truncation, {except: keep_tables} | ||
end | ||
|
||
config.before(:each) do | ||
DatabaseCleaner.start | ||
end | ||
|
||
config.after(:each) do | ||
DatabaseCleaner.clean | ||
end | ||
end |