Skip to content

Commit fee8c0a

Browse files
committed
refactor(Specs): spec config cleanup; upgrade to factory_bot; remove unnecessary gems; upgrade spec-related gems; fix deprecation warnings
1 parent b566418 commit fee8c0a

File tree

6 files changed

+102
-69
lines changed

6 files changed

+102
-69
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ unnecessary re-work if a problem and its potential solution are first discussed
88
* Fork on Github, then clone your repo:
99

1010
```sh
11-
git clone [email protected]:your-username/cortex.git
11+
$ git clone [email protected]:your-username/cortex.git
1212
```
1313

1414
* Follow the [setup instructions][setup]

Gemfile

+5-6
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ group :development, :test do
2929
gem 'rspec-rails'
3030
gem 'guard-rspec', require: false
3131
gem 'database_cleaner'
32-
gem 'factory_girl_rails', '~> 4.8' # TODO: upgrade to factory_bot
33-
gem 'faker', '~> 1.8'
32+
gem 'factory_bot_rails', '~> 4.10'
33+
gem 'faker', '~> 1.9'
3434
gem 'phantomjs', '~> 2.1'
3535
gem 'jasmine-rails', '~> 0.14'
3636

@@ -76,7 +76,6 @@ end
7676
group :test do
7777
# Rspec
7878
gem 'json_spec', '~> 1.1'
79-
gem 'rspec-sidekiq', '~> 3.0'
8079
gem 'shoulda-matchers', '~> 3.1'
8180
gem "rspec_junit_formatter"
8281

@@ -88,14 +87,14 @@ group :test do
8887
gem 'poltergeist'
8988

9089
# Mocking/Faking
91-
gem 'mocha', '~> 1.3', require: false
90+
gem 'mocha', '~> 1.7', require: false
9291
gem 'timecop', '~> 0.9'
9392
gem 'email_spec'
9493

9594
# Javascript
9695
gem 'guard-jasmine', '~> 2.1'
97-
gem 'jasmine-core', '~> 2.8'
96+
gem 'jasmine-core', '~> 2.99'
9897

9998
# Data
100-
gem 'elasticsearch-extensions', '~> 0.0.29'
99+
gem 'elasticsearch-extensions', '~> 0.0.30'
101100
end

Gemfile.lock

+39-41
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ GEM
8989
activerecord (>= 4.0.0, < 5.3)
9090
aws-eventstream (1.0.1)
9191
aws-partitions (1.97.0)
92-
aws-sdk-core (3.23.0)
92+
aws-sdk-core (3.24.0)
9393
aws-eventstream (~> 1.0)
9494
aws-partitions (~> 1.0)
9595
aws-sigv4 (~> 1.0)
@@ -108,7 +108,7 @@ GEM
108108
breadcrumbs_on_rails (3.0.1)
109109
builder (3.2.3)
110110
byebug (10.0.2)
111-
capybara (3.5.0)
111+
capybara (3.5.1)
112112
addressable
113113
mini_mime (>= 0.1.3)
114114
nokogiri (~> 1.8)
@@ -134,20 +134,20 @@ GEM
134134
concurrent-ruby (1.0.5)
135135
connection_pool (2.2.2)
136136
cortex-exceptions (0.0.4)
137-
cortex-plugins-core (3.0.0)
138-
aws-sdk-s3 (~> 1.5)
137+
cortex-plugins-core (3.1.0)
138+
aws-sdk-s3 (~> 1.17)
139139
cells (~> 4.1)
140140
cells-haml (~> 0.0)
141141
cells-rails (~> 0.0)
142142
fastimage (~> 2.1)
143-
image_optim (~> 0.25)
143+
image_optim (~> 0.26)
144144
image_optim_pack (~> 0.5)
145-
image_processing (~> 0.4)
145+
image_processing (~> 1.6)
146146
jsonb_accessor (~> 1.0)
147147
mimemagic (~> 0.3)
148148
mini_magick (~> 4.8)
149149
rails (>= 5)
150-
shrine (~> 2.7)
150+
shrine (~> 2.11)
151151
crass (1.0.4)
152152
database_cleaner (1.7.0)
153153
debug_inspector (0.0.3)
@@ -212,10 +212,9 @@ GEM
212212
elasticsearch-api (5.0.5)
213213
multi_json
214214
elasticsearch-dsl (0.1.6)
215-
elasticsearch-extensions (0.0.29)
215+
elasticsearch-extensions (0.0.30)
216216
ansi
217217
elasticsearch
218-
ruby-prof
219218
elasticsearch-model (5.1.0)
220219
activesupport (> 3)
221220
elasticsearch (~> 5)
@@ -232,10 +231,10 @@ GEM
232231
erubis (2.7.0)
233232
execjs (2.7.0)
234233
exifr (1.3.4)
235-
factory_girl (4.9.0)
234+
factory_bot (4.10.0)
236235
activesupport (>= 3.0.0)
237-
factory_girl_rails (4.9.0)
238-
factory_girl (~> 4.9.0)
236+
factory_bot_rails (4.10.0)
237+
factory_bot (~> 4.10.0)
239238
railties (>= 3.0.0)
240239
faker (1.9.1)
241240
i18n (>= 0.7)
@@ -291,7 +290,7 @@ GEM
291290
tilt
292291
hashie (3.5.7)
293292
htmlentities (4.3.4)
294-
i18n (1.0.1)
293+
i18n (1.1.0)
295294
concurrent-ruby (~> 1.0)
296295
ice_nine (0.11.2)
297296
image_optim (0.26.1)
@@ -303,7 +302,9 @@ GEM
303302
image_optim_pack (0.5.1)
304303
fspath (>= 2.1, < 4)
305304
image_optim (~> 0.19)
306-
image_processing (0.11.2)
305+
image_processing (1.6.0)
306+
mini_magick (~> 4.0)
307+
ruby-vips (>= 2.0.11, < 3)
307308
image_size (1.5.0)
308309
in_threads (1.5.0)
309310
jasmine (2.99.0)
@@ -348,7 +349,7 @@ GEM
348349
mini_racer (0.2.0)
349350
libv8 (>= 6.3)
350351
minitest (5.11.3)
351-
mocha (1.6.0)
352+
mocha (1.7.0)
352353
metaclass (~> 0.0.1)
353354
multi_json (1.13.1)
354355
multipart-post (2.0.0)
@@ -459,34 +460,32 @@ GEM
459460
actionpack (>= 4.2.0, < 5.3)
460461
railties (>= 4.2.0, < 5.3)
461462
rolify (5.2.0)
462-
rspec (3.7.0)
463-
rspec-core (~> 3.7.0)
464-
rspec-expectations (~> 3.7.0)
465-
rspec-mocks (~> 3.7.0)
466-
rspec-core (3.7.1)
467-
rspec-support (~> 3.7.0)
468-
rspec-expectations (3.7.0)
463+
rspec (3.8.0)
464+
rspec-core (~> 3.8.0)
465+
rspec-expectations (~> 3.8.0)
466+
rspec-mocks (~> 3.8.0)
467+
rspec-core (3.8.0)
468+
rspec-support (~> 3.8.0)
469+
rspec-expectations (3.8.1)
469470
diff-lcs (>= 1.2.0, < 2.0)
470-
rspec-support (~> 3.7.0)
471-
rspec-mocks (3.7.0)
471+
rspec-support (~> 3.8.0)
472+
rspec-mocks (3.8.0)
472473
diff-lcs (>= 1.2.0, < 2.0)
473-
rspec-support (~> 3.7.0)
474-
rspec-rails (3.7.2)
474+
rspec-support (~> 3.8.0)
475+
rspec-rails (3.8.0)
475476
actionpack (>= 3.0)
476477
activesupport (>= 3.0)
477478
railties (>= 3.0)
478-
rspec-core (~> 3.7.0)
479-
rspec-expectations (~> 3.7.0)
480-
rspec-mocks (~> 3.7.0)
481-
rspec-support (~> 3.7.0)
482-
rspec-sidekiq (3.0.3)
483-
rspec-core (~> 3.0, >= 3.0.0)
484-
sidekiq (>= 2.4.0)
485-
rspec-support (3.7.1)
479+
rspec-core (~> 3.8.0)
480+
rspec-expectations (~> 3.8.0)
481+
rspec-mocks (~> 3.8.0)
482+
rspec-support (~> 3.8.0)
483+
rspec-support (3.8.0)
486484
rspec_junit_formatter (0.4.1)
487485
rspec-core (>= 2, < 4, != 2.12.0)
488486
ruby-graphviz (1.2.3)
489-
ruby-prof (0.17.0)
487+
ruby-vips (2.0.13)
488+
ffi (~> 1.9)
490489
ruby_dep (1.5.0)
491490
sass (3.5.7)
492491
sass-listen (~> 4.0.0)
@@ -563,18 +562,18 @@ DEPENDENCIES
563562
cortex-plugins-core (~> 3.0)
564563
database_cleaner
565564
dotenv-rails
566-
elasticsearch-extensions (~> 0.0.29)
565+
elasticsearch-extensions (~> 0.0.30)
567566
email_spec
568-
factory_girl_rails (~> 4.8)
569-
faker (~> 1.8)
567+
factory_bot_rails (~> 4.10)
568+
faker (~> 1.9)
570569
guard-jasmine (~> 2.1)
571570
guard-rspec
572571
haml (~> 5.0)
573-
jasmine-core (~> 2.8)
572+
jasmine-core (~> 2.99)
574573
jasmine-rails (~> 0.14)
575574
json_spec (~> 1.1)
576575
mini_racer
577-
mocha (~> 1.3)
576+
mocha (~> 1.7)
578577
pg (>= 0.18, < 2.0)
579578
phantomjs (~> 2.1)
580579
poltergeist
@@ -586,7 +585,6 @@ DEPENDENCIES
586585
react_on_rails (= 9.0.3)
587586
redis-rails (~> 5.0)
588587
rspec-rails
589-
rspec-sidekiq (~> 3.0)
590588
rspec_junit_formatter
591589
sass-rails (~> 5.0)
592590
shoulda-matchers (~> 3.1)

spec/rails_helper.rb

+47-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
# This file is copied to spec/ when you run 'rails generate rspec:install'
22
require 'spec_helper'
33
ENV['RAILS_ENV'] ||= 'test'
4-
require File.expand_path('../../config/environment', __FILE__)
4+
require File.expand_path('../dummy/config/environment', __FILE__)
55
# Prevent database truncation if the environment is production
66
abort("The Rails environment is running in production mode!") if Rails.env.production?
77
require 'rspec/rails'
88
# Add additional requires below this line. Rails is not loaded until this point!
9+
require 'mocha/api'
10+
require 'net/http'
11+
require 'email_spec'
12+
require 'capybara/rspec'
13+
require 'capybara/rails'
14+
require 'capybara/poltergeist'
15+
16+
Capybara.javascript_driver = :poltergeist
17+
18+
Capybara.register_driver :poltergeist do |app|
19+
Capybara::Poltergeist::Driver.new(app, {js_errors: false})
20+
end
21+
22+
include ActionDispatch::TestProcess
923

1024
# Requires supporting ruby files with custom matchers and macros, etc, in
1125
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
@@ -20,13 +34,13 @@
2034
# directory. Alternatively, in the individual `*_spec.rb` files, manually
2135
# require only the support files necessary.
2236
#
23-
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
24-
25-
# Checks for pending migrations and applies them before tests are run.
26-
# If you are not using ActiveRecord, you can remove this line.
27-
ActiveRecord::Migration.maintain_test_schema!
37+
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
2838

2939
RSpec.configure do |config|
40+
# Ensure that if we are running js tests, we are using latest webpack assets
41+
# This will use the defaults of :js and :server_rendering meta tags
42+
ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
43+
3044
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
3145
config.fixture_path = "#{::Rails.root}/spec/fixtures"
3246

@@ -54,4 +68,31 @@
5468
config.filter_rails_from_backtrace!
5569
# arbitrary gems may also be filtered via:
5670
# config.filter_gems_from_backtrace("gem name")
71+
72+
config.include Warden::Test::Helpers
73+
74+
config.include EmailSpec::Helpers
75+
config.include EmailSpec::Matchers
76+
77+
config.include Devise::Test::ControllerHelpers, type: :controller
78+
79+
config.include RSpec::Rails::RequestExampleGroup, type: :request, file_path: /spec\/api/
80+
81+
config.before(:suite) do
82+
DatabaseCleaner.strategy = :transaction
83+
Capybara.current_driver = Capybara.javascript_driver
84+
DatabaseCleaner.clean_with(:truncation)
85+
end
86+
87+
config.before(:each) do
88+
DatabaseCleaner.start
89+
end
90+
91+
config.after(:each) do
92+
DatabaseCleaner.clean
93+
Warden.test_reset!
94+
end
95+
96+
config.infer_base_class_for_anonymous_controllers = false
97+
config.order = 'random'
5798
end

spec/spec_helper.rb

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
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 http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
1+
require 'simplecov'
2+
SimpleCov.start 'rails' do
3+
add_filter do |source_file|
4+
source_file.filename.include?("_spec.rb")
5+
end
6+
end
7+
168
RSpec.configure do |config|
179
# rspec-expectations config goes here. You can use an alternate
1810
# assertion/expectation library such as wrong or the stdlib/minitest

spec/support/factory_bot.rb

+3
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

0 commit comments

Comments
 (0)