From cb8ce557aef280f9f11d0359924e93bbc8a6dacd Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Sat, 17 Jul 2021 16:28:32 -0500 Subject: [PATCH] Fix all the things! * Update factories * Switch to Firefox headless with Selenium * Fix shoulda setup --- Gemfile | 2 ++ Gemfile.lock | 11 +++++++++++ config/environments/test.rb | 2 ++ spec/factories/contacts.rb | 6 +++--- spec/factories/pages.rb | 6 +++--- spec/factories/photos.rb | 6 +++--- spec/factories/users.rb | 4 ++-- spec/models/category_spec.rb | 12 ++++++------ spec/models/contact_spec.rb | 2 +- spec/models/photo_spec.rb | 2 +- spec/spec_helper.rb | 19 ++++++++++++++++--- 11 files changed, 50 insertions(+), 22 deletions(-) diff --git a/Gemfile b/Gemfile index bf6fa30..ac9b1a4 100644 --- a/Gemfile +++ b/Gemfile @@ -54,7 +54,9 @@ group :test do gem "fivemat" gem "poltergeist" gem "shoulda" + gem "shoulda-matchers" gem "simplecov" + gem "webdrivers" end group :production do diff --git a/Gemfile.lock b/Gemfile.lock index 0b09647..40f442a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -79,6 +79,7 @@ GEM capybara-screenshot (1.0.25) capybara (>= 1.0, < 4) launchy + childprocess (3.0.0) cliver (0.3.2) coderay (1.1.3) coffee-rails (5.0.0) @@ -283,6 +284,7 @@ GEM ruby-progressbar (1.11.0) ruby_parser (3.16.0) sexp_processor (~> 4.15, >= 4.15.1) + rubyzip (2.3.2) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) sassc (2.4.0) @@ -294,6 +296,9 @@ GEM sprockets-rails tilt selectize-rails (0.12.6) + selenium-webdriver (3.142.7) + childprocess (>= 0.5, < 4.0) + rubyzip (>= 1.2.2) sexp_processor (4.15.3) shoulda (4.0.0) shoulda-context (~> 2.0) @@ -336,6 +341,10 @@ GEM unicode-display_width (2.0.0) warden (1.2.9) rack (>= 2.0.9) + webdrivers (4.6.0) + nokogiri (~> 1.6) + rubyzip (>= 1.3.0) + selenium-webdriver (>= 3.0, < 4.0) websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) @@ -380,12 +389,14 @@ DEPENDENCIES ruby_parser sass-rails shoulda + shoulda-matchers simple_form simplecov slugtastic standardrb uglifier unf + webdrivers RUBY VERSION ruby 2.7.2p137 diff --git a/config/environments/test.rb b/config/environments/test.rb index 9d3e754..76616a2 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -41,4 +41,6 @@ DanBarberPhoto::Application.configure do # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets config.assets.allow_debugging = true + + config.assets.check_precompiled_asset = false end diff --git a/spec/factories/contacts.rb b/spec/factories/contacts.rb index b4b166c..cbefa2d 100644 --- a/spec/factories/contacts.rb +++ b/spec/factories/contacts.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :contact do - email "test@danbarberphoto.com" - name "Dan Barber" - message "This is a message." + email { "test@danbarberphoto.com" } + name { "Dan Barber" } + message { "This is a message." } end end diff --git a/spec/factories/pages.rb b/spec/factories/pages.rb index c8018a7..ac370e5 100644 --- a/spec/factories/pages.rb +++ b/spec/factories/pages.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :page do - name "page" - title "Page" - content "This is a page." + name { "page" } + title { "Page" } + content { "This is a page." } end end diff --git a/spec/factories/photos.rb b/spec/factories/photos.rb index 45e68f3..8268ade 100644 --- a/spec/factories/photos.rb +++ b/spec/factories/photos.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :photo do - title "A Photo" - description "A lovely photo of a tree" - image Rails.root.join("spec/fixtures/photo.jpg") + title { "A Photo" } + description { "A lovely photo of a tree" } + image { Rails.root.join("spec/fixtures/photo.jpg") } end end diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 2d727fa..3c969db 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :user do - email "test@example.com" - password_digest "password" + email { "test@example.com" } + password_digest { "password" } end end diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index 1126ac6..460b95d 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -1,11 +1,11 @@ require "spec_helper" -describe Category do - it { should have_and_belong_to_many(:photos) } - it { should validate_presence_of(:name) } - it { should validate_presence_of(:slug) } - it { should validate_uniqueness_of(:name) } - it { should validate_uniqueness_of(:slug) } +describe Category, type: :model do + it { is_expected.to have_and_belong_to_many(:photos) } + it { is_expected.to validate_presence_of(:name) } + it { is_expected.to validate_presence_of(:slug) } + it { is_expected.to validate_uniqueness_of(:name) } + it { is_expected.to validate_uniqueness_of(:slug) } let(:category) { create(:category, name: "A Test Category") } diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index e261113..e138cf3 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" -describe Contact do +describe Contact, type: :model do it { is_expected.to validate_presence_of(:email) } it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_presence_of(:message) } diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index a29977d..76e97e2 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" -describe Photo do +describe Photo, type: :model do it { should have_and_belong_to_many(:categories) } it { should validate_presence_of(:image) } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 60fcd8f..ae1775d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,14 +3,20 @@ ENV["RAILS_ENV"] ||= "test" require File.expand_path("../../config/environment", __FILE__) require "rspec/rails" require "capybara/rspec" -require "capybara/poltergeist" # For code coverage require "simplecov" SimpleCov.start -# Use Poltergeist -Capybara.javascript_driver = :poltergeist +# Use Firefox headless +Capybara.register_driver :firefox_headless do |app| + options = ::Selenium::WebDriver::Firefox::Options.new + options.args << "--headless" + + Capybara::Selenium::Driver.new(app, browser: :firefox, options: options) +end + +Capybara.javascript_driver = :firefox_headless # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. @@ -70,3 +76,10 @@ RSpec.configure do |config| DatabaseCleaner.clean end end + +Shoulda::Matchers.configure do |config| + config.integrate do |with| + with.test_framework :rspec + with.library :rails + end +end