Skip to content

Commit

Permalink
add RSpec setup with required config
Browse files Browse the repository at this point in the history
  • Loading branch information
rna committed Dec 21, 2020
1 parent 9ba54a1 commit bc16553
Show file tree
Hide file tree
Showing 25 changed files with 278 additions and 145 deletions.
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--require spec_helper
--color
--format documentation
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,13 @@ gem 'newrelic_rpm'
gem "activeadmin", "~> 2.2.0"
#gem "meta_search", '>= 1.1.0.pre'
#gem "therubyracer", "~> 0.11.2"
group :development, :test do
gem 'rspec-rails'
end

group :test do
gem 'database_cleaner'
gem 'factory_bot_rails'
gem 'faker'
gem 'shoulda-matchers'
end
36 changes: 35 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ GEM
commonjs (0.2.7)
concurrent-ruby (1.1.5)
crass (1.0.4)
database_cleaner (1.8.5)
devise (4.6.2)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 6.0)
responders
warden (~> 1.2.3)
diff-lcs (1.4.4)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.7.5)
Expand All @@ -88,6 +90,13 @@ GEM
erubi (1.8.0)
erubis (2.7.0)
execjs (2.7.0)
factory_bot (5.2.0)
activesupport (>= 4.2.0)
factory_bot_rails (5.2.0)
factory_bot (~> 5.2.0)
railties (>= 4.2.0)
faker (2.12.0)
i18n (>= 1.6, < 2)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
ffi (1.11.1)
Expand Down Expand Up @@ -234,6 +243,23 @@ GEM
responders (3.0.0)
actionpack (>= 5.0)
railties (>= 5.0)
rspec-core (3.10.0)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-rails (4.0.1)
actionpack (>= 4.2)
activesupport (>= 4.2)
railties (>= 4.2)
rspec-core (~> 3.9)
rspec-expectations (~> 3.9)
rspec-mocks (~> 3.9)
rspec-support (~> 3.9)
rspec-support (3.10.0)
ruby_dep (1.5.0)
ruby_parser (3.13.1)
sexp_processor (~> 4.9)
Expand All @@ -249,6 +275,8 @@ GEM
sentry-raven (2.11.0)
faraday (>= 0.7.6, < 1.0)
sexp_processor (4.12.1)
shoulda-matchers (4.4.1)
activesupport (>= 4.2.0)
simple_oauth (0.3.1)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -296,13 +324,17 @@ GEM

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
activeadmin (~> 2.2.0)
bootsnap (~> 1.4, >= 1.4.4)
byebug (~> 11.0.1)
database_cleaner
devise (~> 4.6.2)
dotenv-rails (~> 2.7, >= 2.7.4)
factory_bot_rails
faker
haml-rails (~> 2.0.1)
listen (~> 3.1, >= 3.1.5)
newrelic_rpm
Expand All @@ -314,7 +346,9 @@ DEPENDENCIES
pygmentize (~> 0.0.3)
rails (= 5.2.3)
redcarpet (~> 1.17.2)
rspec-rails
sentry-raven (~> 2.11)
shoulda-matchers
twitter (~> 6.2.0)
twitter-bootstrap-rails (~> 4.0.0)
uglifier (>= 1.0.3)
Expand All @@ -323,4 +357,4 @@ RUBY VERSION
ruby 2.4.0p0

BUNDLED WITH
2.0.2
2.2.2
59 changes: 30 additions & 29 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,70 +15,71 @@
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "active_admin_comments", id: :integer, default: -> { "nextval('admin_notes_id_seq'::regclass)" }, force: :cascade do |t|
t.string "resource_id", limit: 255, null: false
t.string "resource_type", limit: 255, null: false
t.integer "author_id"
t.string "author_type", limit: 255
create_table "active_admin_comments", force: :cascade do |t|
t.string "resource_id", null: false
t.string "resource_type", null: false
t.string "author_type"
t.bigint "author_id"
t.text "body"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "namespace", limit: 255
t.string "namespace"
t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id"
t.index ["namespace"], name: "index_active_admin_comments_on_namespace"
t.index ["resource_type", "resource_id"], name: "index_admin_notes_on_resource_type_and_resource_id"
t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id"
end

create_table "admin_users", id: :serial, force: :cascade do |t|
t.string "email", limit: 255, default: "", null: false
t.string "encrypted_password", limit: 255, default: "", null: false
t.string "reset_password_token", limit: 255
create_table "admin_users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip", limit: 255
t.string "last_sign_in_ip", limit: 255
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_admin_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true
end

create_table "letters", id: :serial, force: :cascade do |t|
create_table "letters", force: :cascade do |t|
t.text "description"
t.integer "user_id"
t.bigint "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_letters_on_user_id"
end

create_table "likes", id: :serial, force: :cascade do |t|
t.integer "user_id"
t.integer "letter_id"
create_table "likes", force: :cascade do |t|
t.bigint "user_id"
t.bigint "letter_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["letter_id"], name: "index_likes_on_letter_id"
t.index ["user_id"], name: "index_likes_on_user_id"
end

create_table "users", id: :serial, force: :cascade do |t|
t.string "email", limit: 255, default: ""
t.string "encrypted_password", limit: 255, default: ""
create_table "users", force: :cascade do |t|
t.string "email", default: ""
t.string "encrypted_password", default: ""
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip", limit: 255
t.string "last_sign_in_ip", limit: 255
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name", limit: 255
t.string "twitter_oauth", limit: 255
t.string "twitter_handle", limit: 255
t.string "twitter_description", limit: 255
t.string "website", limit: 255
t.string "image", limit: 255
t.string "name"
t.string "twitter_oauth"
t.string "twitter_handle"
t.string "twitter_description"
t.string "website"
t.string "image"
t.string "provider"
t.string "uid"
t.index ["provider"], name: "index_users_on_provider"
Expand Down
12 changes: 12 additions & 0 deletions spec/controllers/letters_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'rails_helper'

RSpec.describe LettersController, type: :controller do
describe 'POST #create' do
context 'without authentication' do
it 'should redirect' do
post :create, params: {description: 'Ruby is awesome'}
expect(response.status).to eq(302)
end
end
end
end
92 changes: 92 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# 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'

# require database cleaner at the top level
require 'database_cleaner'

Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end

RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :controller
end

# 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")
# add `FactoryBot` methods
config.include FactoryBot::Syntax::Methods

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

config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
end
Loading

0 comments on commit bc16553

Please sign in to comment.