Skip to content

Commit

Permalink
Set up RSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahW91 committed Apr 27, 2018
1 parent 14f06dc commit ab1bfc7
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--require spec_helper
--require spec_helper
19 changes: 11 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ruby '2.3.3'
gem 'rails', '5.0.0'

# Postgres
gem 'pg', '~> 0.21' # Rails does not work with pg 1.0.0 (fixed in Rails 5.1.5)
gem 'pg', '~> 0.20.0' # Rails does not work with pg 1.0.0 (fixed in Rails 5.1.5), pg 0.21 gives constant deprecation warning: https://github.com/rails/rails/issues/29521
gem 'pg_search'

# Web server and background processing
Expand Down Expand Up @@ -63,24 +63,27 @@ group :development do
gem 'capistrano-rbenv', require: false
gem 'capistrano-sidekiq', require: false, github: 'seuros/capistrano-sidekiq'
gem 'capistrano3-puma', require: false, github: 'seuros/capistrano-puma' # TODO: remove github once fixed version is officially deployed
gem 'better_errors' # Better error page for Rack apps
gem 'bullet' # Checks for n+1 queries
gem 'binding_of_caller' # Extends features of better_errors
gem 'meta_request' # Supporting gem for Google Chrome Rails Panel
gem 'spring' # Spring speeds up development by keeping your application running in the background
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'yard' # Documentation generation tool
end

group :test do
gem 'capybara'
gem 'faker'
gem 'guard-rspec'
gem 'launchy'
gem 'simplecov'
gem 'selenium-webdriver' # TODO: Replace by phantom.js
end

group :development, :test do
gem 'better_errors'
gem 'bullet' # Checks for n+1 queries
gem 'capybara'
gem 'database_cleaner'
gem 'launchy'
gem 'meta_request' # Supporting gem for Google Chrome Rails Panel
gem 'factory_bot_rails'
gem 'poltergeist'
gem 'rails_best_practices'
gem 'rspec-rails'
gem 'yard' # Documentation generation tool
end
54 changes: 45 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ GEM
coderay (>= 1.0.0)
erubi (>= 1.0.0)
rack (>= 0.9.0)
binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1)
bio (1.5.1)
bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1)
Expand Down Expand Up @@ -660,8 +662,6 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (>= 2.0, < 4.0)
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
chosen-rails (1.8.3)
coffee-rails (>= 3.2)
railties (>= 3.0)
Expand All @@ -683,6 +683,7 @@ GEM
connection_pool (2.2.1)
crass (1.0.4)
database_cleaner (1.7.0)
debug_inspector (0.0.3)
devise (4.4.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
Expand All @@ -694,10 +695,32 @@ GEM
erubi (1.7.1)
erubis (2.7.0)
execjs (2.7.0)
factory_bot (4.8.2)
activesupport (>= 3.0.0)
factory_bot_rails (4.8.2)
factory_bot (~> 4.8.2)
railties (>= 3.0.0)
faker (1.8.7)
i18n (>= 0.7)
ffi (1.9.23)
ffi (1.9.23-x86-mingw32)
formatador (0.2.5)
globalid (0.4.1)
activesupport (>= 4.2.0)
guard (2.14.2)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
lumberjack (>= 1.0.12, < 2.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-rspec (4.7.3)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
jbuilder (2.7.0)
Expand Down Expand Up @@ -727,6 +750,7 @@ GEM
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
lumberjack (1.0.13)
mail (2.7.0)
mini_mime (>= 0.1.1)
meta_request (0.6.0)
Expand All @@ -743,6 +767,7 @@ GEM
minitest (5.11.3)
multi_json (1.13.1)
mustermann (1.0.2)
nenv (0.3.0)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (4.2.0)
Expand All @@ -751,15 +776,18 @@ GEM
mini_portile2 (~> 2.3.0)
nokogiri (1.8.2-x86-mingw32)
mini_portile2 (~> 2.3.0)
notiffany (0.1.1)
nenv (~> 0.1)
shellany (~> 0.0)
orm_adapter (0.5.0)
paperclip (6.0.0)
activemodel (>= 4.2.0)
activesupport (>= 4.2.0)
mime-types
mimemagic (~> 0.3.0)
terrapin (~> 0.6.0)
pg (0.21.0)
pg (0.21.0-x86-mingw32)
pg (0.20.0)
pg (0.20.0-x86-mingw32)
pg_search (2.1.2)
activerecord (>= 4.2)
activesupport (>= 4.2)
Expand All @@ -768,6 +796,9 @@ GEM
capybara (~> 2.1)
cliver (~> 0.3.1)
websocket-driver (>= 0.2.0)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (3.0.2)
puma (3.11.4)
rack (2.0.4)
Expand Down Expand Up @@ -824,6 +855,10 @@ GEM
nokogiri
roo (>= 2.0.0, < 3)
spreadsheet (> 0.9.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)
Expand Down Expand Up @@ -861,10 +896,8 @@ GEM
railties (>= 4.0.0)
select2-rails (4.0.3)
thor (~> 0.14)
selenium-webdriver (3.11.0)
childprocess (~> 0.5)
rubyzip (~> 1.2)
sexp_processor (4.11.0)
shellany (0.0.1)
sidekiq (5.1.3)
concurrent-ruby (~> 1.0)
connection_pool (~> 2.2, >= 2.2.0)
Expand Down Expand Up @@ -943,6 +976,7 @@ DEPENDENCIES
aws-sdk
bcrypt (~> 3.1.7)
better_errors
binding_of_caller
bio
bootstrap-sass
bullet
Expand All @@ -958,6 +992,9 @@ DEPENDENCIES
coffee-rails (~> 4.2)
database_cleaner
devise
factory_bot_rails
faker
guard-rspec
jbuilder (~> 2.5)
jquery-datatables-rails!
jquery-fileupload-rails
Expand All @@ -968,7 +1005,7 @@ DEPENDENCIES
meta_request
mime-types
paperclip
pg (~> 0.21)
pg (~> 0.20.0)
pg_search
poltergeist
puma (~> 3.0)
Expand All @@ -981,7 +1018,6 @@ DEPENDENCIES
sass-rails (~> 5.0)
scenic
select2-rails
selenium-webdriver
sidekiq
sidekiq-limit_fetch
simple_form
Expand Down
9 changes: 8 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ module GBOLapp
class Application < Rails::Application

config.generators do |g|
g.test_framework :minitest
g.test_framework :rspec,
:fixtures => true,
:view_specs => false,
:helper_specs => false,
:routing_specs => false,
:controller_specs => true,
:request_specs => true
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
end

# Settings in config/environments/* take precedence over those specified here.
Expand Down
1 change: 1 addition & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test: &test
encoding: unicode
database: gbol_test
pool: 5
host: localhost
timeout: 5000
username: postgres
password: passwordpsql
Expand Down
1 change: 0 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@
config.paperclip_defaults = {
:storage => 'filesystem'
}

end
4 changes: 0 additions & 4 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

BetterErrors.editor = :subl

# ENV["REDISTOGO_URL"] = 'redis://redistogo:[email protected]:9618/'

Rails.application.configure do
config.active_support.test_order = :sorted
end
Expand Down
13 changes: 2 additions & 11 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@
t.string "revision", limit: 255
t.string "confirmation", limit: 255
t.text "comments"
t.decimal "latitude", precision: 15, scale: 6
t.decimal "longitude", precision: 15, scale: 6
t.decimal "latitude", precision: 15, scale: 5
t.decimal "longitude", precision: 15, scale: 5
end

create_table "individuals_projects", id: false, force: :cascade do |t|
Expand Down Expand Up @@ -618,15 +618,6 @@
add_foreign_key "plant_plates", "lab_racks"
add_foreign_key "shelves", "freezers"

create_view "taxa_matview", materialized: true, sql_definition: <<-SQL
SELECT f.name AS family,
o.name AS "order",
hot.name AS higher_order_taxon
FROM ((families f
JOIN orders o ON ((f.order_id = o.id)))
JOIN higher_order_taxa hot ON ((o.higher_order_taxon_id = hot.id)));
SQL

create_view "overview_all_taxa_matviews", materialized: true, sql_definition: <<-SQL
SELECT f.name AS family,
count(sp.family_id) AS species_cnt
Expand Down
7 changes: 7 additions & 0 deletions spec/factories/freezers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'faker'

FactoryBot.define do
factory :freezer do |f|
f.freezercode { Faker::Types.string }
end
end
29 changes: 29 additions & 0 deletions spec/models/freezer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'rails_helper'

RSpec.describe Freezer do
subject { FactoryBot.create(:freezer) }

it "is valid with valid attributes" do
should be_valid
end

it "is not valid without a freezercode" do
subject.freezercode = nil
should_not be_valid
end

it "has one lab" do
assc = described_class.reflect_on_association(:lab)
expect(assc.macro).to eq :belongs_to
end

it "has many lab racks" do
assc = described_class.reflect_on_association(:lab_racks)
expect(assc.macro).to eq :has_many
end

it "has many shelves" do
assc = described_class.reflect_on_association(:shelves)
expect(assc.macro).to eq :has_many
end
end
3 changes: 2 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
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 'rspec/capybara'

require 'capybara/rspec'
require 'capybara/poltergeist'

Capybara.javascript_driver = :poltergeist
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# it.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration

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

0 comments on commit ab1bfc7

Please sign in to comment.