From 543ef33e85ecc4e4482f85dbc64179df48569368 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Wed, 12 Sep 2018 21:38:40 -0400 Subject: [PATCH] Trying out headless Firefox instead of PhantomJS --- Gemfile | 3 ++- Gemfile.lock | 22 +++++++++++-------- app/controllers/tags_controller.rb | 1 + config/environments/test.rb | 2 +- spec/features/user_manages_image_tags_spec.rb | 4 ++-- spec/rails_helper.rb | 10 +++++++-- 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Gemfile b/Gemfile index 609bb61..f7ae0a7 100644 --- a/Gemfile +++ b/Gemfile @@ -29,9 +29,10 @@ end group :test do gem "capybara" + gem "geckodriver-helper" gem "launchy" - gem "poltergeist" gem "rspec-rails" + gem "selenium-webdriver" gem "shoulda-matchers" gem "webmock" end diff --git a/Gemfile.lock b/Gemfile.lock index 082211e..e6b7f81 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -44,6 +44,8 @@ GEM tzinfo (~> 1.1) addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) + archive-zip (0.11.0) + io-like (~> 0.3.0) arel (9.0.0) better_errors (2.5.0) coderay (>= 1.0.0) @@ -59,7 +61,8 @@ GEM rack (>= 1.6.0) rack-test (>= 0.6.3) xpath (~> 3.1) - cliver (0.3.2) + childprocess (0.9.0) + ffi (~> 1.0, >= 1.0.11) coderay (1.1.2) concurrent-ruby (1.0.5) crack (0.4.3) @@ -87,6 +90,8 @@ GEM faraday (0.12.2) multipart-post (>= 1.2, < 3) ffi (1.9.25) + geckodriver-helper (0.21.0) + archive-zip (~> 0.7) globalid (0.4.1) activesupport (>= 4.2.0) hashdiff (0.3.7) @@ -102,6 +107,7 @@ GEM http_parser.rb (0.6.0) i18n (1.1.0) concurrent-ruby (~> 1.0) + io-like (0.3.0) jwt (1.5.6) launchy (2.4.3) addressable (~> 2.3) @@ -139,10 +145,6 @@ GEM oauth2 (~> 1.1) omniauth (~> 1.2) pg (1.1.3) - poltergeist (1.18.1) - capybara (>= 2.1, < 4) - cliver (~> 0.3.1) - websocket-driver (>= 0.2.0) pry (0.11.3) coderay (~> 1.1.0) method_source (~> 0.9.0) @@ -171,8 +173,6 @@ GEM nokogiri (>= 1.6) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) - rails-ujs (0.1.0) - railties (>= 3.1) railties (5.2.1) actionpack (= 5.2.1) activesupport (= 5.2.1) @@ -201,6 +201,7 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.0) + rubyzip (1.2.2) safe_yaml (1.0.4) sass (3.5.7) sass-listen (~> 4.0.0) @@ -215,6 +216,9 @@ GEM tilt (>= 1.1, < 3) sdoc (1.0.0) rdoc (>= 5.0) + selenium-webdriver (3.14.0) + childprocess (~> 0.5) + rubyzip (~> 1.2) shoulda-matchers (3.1.2) activesupport (>= 4.0.0) simple_form (4.0.1) @@ -261,18 +265,18 @@ DEPENDENCIES delayed_job_active_record dotenv-rails dragonfly + geckodriver-helper http launchy omniauth-github pg - poltergeist pry puma rails (= 5.2.1) - rails-ujs rspec-rails sass-rails sdoc + selenium-webdriver shoulda-matchers simple_form uglifier diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 919e6fc..89bc752 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -4,6 +4,7 @@ class TagsController < ApplicationController def create image = @current_user.images.find(params[:image_id]) tag = params[:tag] + if !image.tags.include?(tag) image.tags << tag image.save diff --git a/config/environments/test.rb b/config/environments/test.rb index 856450e..edb380f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -24,7 +24,7 @@ MyImages::Application.configure do config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment. - config.action_controller.allow_forgery_protection = false + config.action_controller.allow_forgery_protection = true # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the diff --git a/spec/features/user_manages_image_tags_spec.rb b/spec/features/user_manages_image_tags_spec.rb index 44263b5..725c6f3 100644 --- a/spec/features/user_manages_image_tags_spec.rb +++ b/spec/features/user_manages_image_tags_spec.rb @@ -18,7 +18,7 @@ feature "user manages image tags by visitng images show page" do end end - scenario "and can click the link to delete a tag" do + scenario "and can click the link to delete a tag", js: true do tags = ["one", "two"] user = User.create(uid: "123") Image.create( @@ -37,7 +37,7 @@ feature "user manages image tags by visitng images show page" do expect(page).to_not have_content(tags.first) end - scenario "user can add a tag to the list of tags" do + scenario "user can add a tag to the list of tags", js: true do tags = ["one", "two"] user = User.create(uid: "123") new_tag = "new tag" diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 9c4e682..583fe13 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -9,7 +9,6 @@ end require "rspec/rails" require "shoulda/matchers" require "capybara/rspec" -require "capybara/poltergeist" Dir[Rails.root.join("spec", "support", "**", "*.rb")].each { |f| require f } @@ -20,7 +19,14 @@ rescue ActiveRecord::PendingMigrationError => e exit 1 end -Capybara.javascript_driver = :poltergeist +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 RSpec.configure do |config| config.fixture_path = "#{::Rails.root}/spec/fixtures"