Skip to content

Commit

Permalink
refactor(Specs): spec config cleanup; upgrade to factory_bot; remove …
Browse files Browse the repository at this point in the history
…unnecessary gems; upgrade spec-related gems; fix deprecation warnings
  • Loading branch information
toastercup committed Aug 10, 2018
1 parent b566418 commit fee8c0a
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 69 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ unnecessary re-work if a problem and its potential solution are first discussed
* Fork on Github, then clone your repo:

```sh
git clone [email protected]:your-username/cortex.git
$ git clone [email protected]:your-username/cortex.git
```

* Follow the [setup instructions][setup]
Expand Down
11 changes: 5 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ group :development, :test do
gem 'rspec-rails'
gem 'guard-rspec', require: false
gem 'database_cleaner'
gem 'factory_girl_rails', '~> 4.8' # TODO: upgrade to factory_bot
gem 'faker', '~> 1.8'
gem 'factory_bot_rails', '~> 4.10'
gem 'faker', '~> 1.9'
gem 'phantomjs', '~> 2.1'
gem 'jasmine-rails', '~> 0.14'

Expand Down Expand Up @@ -76,7 +76,6 @@ end
group :test do
# Rspec
gem 'json_spec', '~> 1.1'
gem 'rspec-sidekiq', '~> 3.0'
gem 'shoulda-matchers', '~> 3.1'
gem "rspec_junit_formatter"

Expand All @@ -88,14 +87,14 @@ group :test do
gem 'poltergeist'

# Mocking/Faking
gem 'mocha', '~> 1.3', require: false
gem 'mocha', '~> 1.7', require: false
gem 'timecop', '~> 0.9'
gem 'email_spec'

# Javascript
gem 'guard-jasmine', '~> 2.1'
gem 'jasmine-core', '~> 2.8'
gem 'jasmine-core', '~> 2.99'

# Data
gem 'elasticsearch-extensions', '~> 0.0.29'
gem 'elasticsearch-extensions', '~> 0.0.30'
end
80 changes: 39 additions & 41 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ GEM
activerecord (>= 4.0.0, < 5.3)
aws-eventstream (1.0.1)
aws-partitions (1.97.0)
aws-sdk-core (3.23.0)
aws-sdk-core (3.24.0)
aws-eventstream (~> 1.0)
aws-partitions (~> 1.0)
aws-sigv4 (~> 1.0)
Expand All @@ -108,7 +108,7 @@ GEM
breadcrumbs_on_rails (3.0.1)
builder (3.2.3)
byebug (10.0.2)
capybara (3.5.0)
capybara (3.5.1)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand All @@ -134,20 +134,20 @@ GEM
concurrent-ruby (1.0.5)
connection_pool (2.2.2)
cortex-exceptions (0.0.4)
cortex-plugins-core (3.0.0)
aws-sdk-s3 (~> 1.5)
cortex-plugins-core (3.1.0)
aws-sdk-s3 (~> 1.17)
cells (~> 4.1)
cells-haml (~> 0.0)
cells-rails (~> 0.0)
fastimage (~> 2.1)
image_optim (~> 0.25)
image_optim (~> 0.26)
image_optim_pack (~> 0.5)
image_processing (~> 0.4)
image_processing (~> 1.6)
jsonb_accessor (~> 1.0)
mimemagic (~> 0.3)
mini_magick (~> 4.8)
rails (>= 5)
shrine (~> 2.7)
shrine (~> 2.11)
crass (1.0.4)
database_cleaner (1.7.0)
debug_inspector (0.0.3)
Expand Down Expand Up @@ -212,10 +212,9 @@ GEM
elasticsearch-api (5.0.5)
multi_json
elasticsearch-dsl (0.1.6)
elasticsearch-extensions (0.0.29)
elasticsearch-extensions (0.0.30)
ansi
elasticsearch
ruby-prof
elasticsearch-model (5.1.0)
activesupport (> 3)
elasticsearch (~> 5)
Expand All @@ -232,10 +231,10 @@ GEM
erubis (2.7.0)
execjs (2.7.0)
exifr (1.3.4)
factory_girl (4.9.0)
factory_bot (4.10.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.9.0)
factory_girl (~> 4.9.0)
factory_bot_rails (4.10.0)
factory_bot (~> 4.10.0)
railties (>= 3.0.0)
faker (1.9.1)
i18n (>= 0.7)
Expand Down Expand Up @@ -291,7 +290,7 @@ GEM
tilt
hashie (3.5.7)
htmlentities (4.3.4)
i18n (1.0.1)
i18n (1.1.0)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
image_optim (0.26.1)
Expand All @@ -303,7 +302,9 @@ GEM
image_optim_pack (0.5.1)
fspath (>= 2.1, < 4)
image_optim (~> 0.19)
image_processing (0.11.2)
image_processing (1.6.0)
mini_magick (~> 4.0)
ruby-vips (>= 2.0.11, < 3)
image_size (1.5.0)
in_threads (1.5.0)
jasmine (2.99.0)
Expand Down Expand Up @@ -348,7 +349,7 @@ GEM
mini_racer (0.2.0)
libv8 (>= 6.3)
minitest (5.11.3)
mocha (1.6.0)
mocha (1.7.0)
metaclass (~> 0.0.1)
multi_json (1.13.1)
multipart-post (2.0.0)
Expand Down Expand Up @@ -459,34 +460,32 @@ GEM
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
rolify (5.2.0)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-rails (3.7.2)
rspec-support (~> 3.8.0)
rspec-rails (3.8.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-support (~> 3.7.0)
rspec-sidekiq (3.0.3)
rspec-core (~> 3.0, >= 3.0.0)
sidekiq (>= 2.4.0)
rspec-support (3.7.1)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0)
ruby-graphviz (1.2.3)
ruby-prof (0.17.0)
ruby-vips (2.0.13)
ffi (~> 1.9)
ruby_dep (1.5.0)
sass (3.5.7)
sass-listen (~> 4.0.0)
Expand Down Expand Up @@ -563,18 +562,18 @@ DEPENDENCIES
cortex-plugins-core (~> 3.0)
database_cleaner
dotenv-rails
elasticsearch-extensions (~> 0.0.29)
elasticsearch-extensions (~> 0.0.30)
email_spec
factory_girl_rails (~> 4.8)
faker (~> 1.8)
factory_bot_rails (~> 4.10)
faker (~> 1.9)
guard-jasmine (~> 2.1)
guard-rspec
haml (~> 5.0)
jasmine-core (~> 2.8)
jasmine-core (~> 2.99)
jasmine-rails (~> 0.14)
json_spec (~> 1.1)
mini_racer
mocha (~> 1.3)
mocha (~> 1.7)
pg (>= 0.18, < 2.0)
phantomjs (~> 2.1)
poltergeist
Expand All @@ -586,7 +585,6 @@ DEPENDENCIES
react_on_rails (= 9.0.3)
redis-rails (~> 5.0)
rspec-rails
rspec-sidekiq (~> 3.0)
rspec_junit_formatter
sass-rails (~> 5.0)
shoulda-matchers (~> 3.1)
Expand Down
53 changes: 47 additions & 6 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
# 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', __FILE__)
require File.expand_path('../dummy/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 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
require 'mocha/api'
require 'net/http'
require 'email_spec'
require 'capybara/rspec'
require 'capybara/rails'
require 'capybara/poltergeist'

Capybara.javascript_driver = :poltergeist

Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, {js_errors: false})
end

include ActionDispatch::TestProcess

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
Expand All @@ -20,13 +34,13 @@
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }

RSpec.configure do |config|
# Ensure that if we are running js tests, we are using latest webpack assets
# This will use the defaults of :js and :server_rendering meta tags
ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)

# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"

Expand Down Expand Up @@ -54,4 +68,31 @@
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")

config.include Warden::Test::Helpers

config.include EmailSpec::Helpers
config.include EmailSpec::Matchers

config.include Devise::Test::ControllerHelpers, type: :controller

config.include RSpec::Rails::RequestExampleGroup, type: :request, file_path: /spec\/api/

config.before(:suite) do
DatabaseCleaner.strategy = :transaction
Capybara.current_driver = Capybara.javascript_driver
DatabaseCleaner.clean_with(:truncation)
end

config.before(:each) do
DatabaseCleaner.start
end

config.after(:each) do
DatabaseCleaner.clean
Warden.test_reset!
end

config.infer_base_class_for_anonymous_controllers = false
config.order = 'random'
end
22 changes: 7 additions & 15 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause
# this file to always be loaded, without a need to explicitly require it in any
# files.
#
# Given that it is always loaded, you are encouraged to keep this file as
# light-weight as possible. Requiring heavyweight dependencies from this file
# will add to the boot time of your test suite on EVERY test run, even for an
# individual file that may not need all of that loaded. Instead, consider making
# a separate helper file that requires the additional dependencies and performs
# the additional setup, and require it from the spec files that actually need
# it.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
require 'simplecov'
SimpleCov.start 'rails' do
add_filter do |source_file|
source_file.filename.include?("_spec.rb")
end
end

RSpec.configure do |config|
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
Expand Down
3 changes: 3 additions & 0 deletions spec/support/factory_bot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end

0 comments on commit fee8c0a

Please sign in to comment.