Skip to content

Commit

Permalink
Replace feature tests with Rails system tests
Browse files Browse the repository at this point in the history
* poltergeist is deprecated
* Rails 5 has good support for selenium
  • Loading branch information
manno committed Nov 30, 2021
1 parent cc6ba65 commit b42a3d4
Show file tree
Hide file tree
Showing 32 changed files with 302 additions and 271 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,13 @@ jobs:
sh -c "[ '$DB' != 'sqlite' ] || diff db/schema.rb db/schema.rb.original "
bundle exec rails db:test:prepare
bundle exec rails test
bundle exec rails test:system
env:
DB: ${{ matrix.db }}

- uses: actions/upload-artifact@v2
if: failure()
with:
name: screenshots-${{matrix.ruby_version}}-${{matrix.db}}
path: tmp/screenshots/*
retention-days: 5
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ group :test do
gem 'factory_bot_rails', '~> 6.2'
gem 'database_cleaner-active_record'
gem 'rails-controller-testing'
gem 'minitest-rails-capybara'
gem 'poltergeist'

gem 'capybara', '>= 3.26'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end

group :doc, optional: true do
Expand Down
57 changes: 26 additions & 31 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.7.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
aes_key_wrap (1.0.1)
airbrussh (1.4.0)
Expand Down Expand Up @@ -108,17 +108,18 @@ GEM
capistrano (~> 3.7)
capistrano-bundler
puma (~> 4.0)
capybara (3.32.2)
capybara (3.36.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.5)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (4.1.0)
chunky_png (1.4.0)
climate_control (0.2.0)
cliver (0.3.2)
cocoon (1.2.15)
coderay (1.1.3)
coffee-rails (5.0.0)
Expand Down Expand Up @@ -232,30 +233,17 @@ GEM
mail (2.6.6)
mime-types (>= 1.16, < 4)
marcel (1.0.1)
matrix (0.4.2)
method_source (1.0.0)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.0704)
mimemagic (0.3.10)
nokogiri (~> 1)
rake
mini_mime (1.0.2)
mini_portile2 (2.5.3)
mini_mime (1.1.2)
mini_portile2 (2.6.1)
minitest (5.14.4)
minitest-capybara (0.9.0)
capybara
minitest (~> 5.0)
rake
minitest-metadata (0.6.0)
minitest (>= 4.7, < 6.0)
minitest-rails (3.0.0)
minitest (~> 5.8)
railties (~> 5.0)
minitest-rails-capybara (3.0.2)
capybara (>= 2.7, <= 4)
minitest-capybara (~> 0.8)
minitest-metadata (~> 0.6)
minitest-rails (~> 3.0)
msgpack (1.4.2)
multi_json (1.15.0)
multi_xml (0.6.0)
Expand All @@ -266,8 +254,8 @@ GEM
net-ssh (>= 2.6.5, < 7.0.0)
net-ssh (6.1.0)
nio4r (2.5.8)
nokogiri (1.11.7)
mini_portile2 (~> 2.5.0)
nokogiri (1.12.5)
mini_portile2 (~> 2.6.1)
racc (~> 1.4)
oauth2 (1.4.7)
faraday (>= 0.8, < 2.0)
Expand Down Expand Up @@ -311,10 +299,6 @@ GEM
ast (~> 2.4.1)
pdf-core (0.1.6)
pg (1.2.3)
poltergeist (1.18.1)
capybara (>= 2.1, < 4)
cliver (~> 0.3.1)
websocket-driver (>= 0.2.0)
prawn (0.15.0)
pdf-core (~> 0.1.3)
ttfunk (~> 1.1.0)
Expand All @@ -329,13 +313,13 @@ GEM
pry (~> 0.13.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (4.0.5)
public_suffix (4.0.6)
puma (4.3.10)
nio4r (~> 2.0)
pundit (2.1.0)
activesupport (>= 3.0.0)
pyu-ruby-sasl (0.0.3.3)
racc (1.5.2)
racc (1.6.0)
rack (2.2.3)
rack-oauth2 (1.10.1)
activesupport
Expand Down Expand Up @@ -389,20 +373,22 @@ GEM
rb-kqueue (0.2.6)
ffi (>= 0.5.0)
redcarpet (3.5.1)
regexp_parser (1.7.1)
regexp_parser (2.1.1)
repost (0.3.8)
request_store (1.5.0)
rack (>= 1.4)
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.5)
ri_cal (0.8.8)
rqrcode (1.2.0)
chunky_png (~> 1.0)
rqrcode_core (~> 0.2)
rqrcode_core (0.2.0)
ruby2_keywords (0.0.4)
rubyntlm (0.6.2)
rubyzip (2.3.2)
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
Expand All @@ -415,6 +401,10 @@ GEM
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
scanf (1.0.0)
selenium-webdriver (4.1.0)
childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2)
simple_form (5.1.0)
actionpack (>= 5.2)
activemodel (>= 5.2)
Expand Down Expand Up @@ -459,6 +449,10 @@ GEM
public_suffix
warden (1.2.9)
rack (>= 2.0.9)
webdrivers (5.0.0)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0)
webfinger (1.1.0)
activesupport
httpclient (>= 2.4)
Expand All @@ -485,6 +479,7 @@ DEPENDENCIES
capistrano-rails
capistrano-rvm
capistrano3-puma
capybara (>= 3.26)
cocoon
coffee-rails
dalli
Expand All @@ -508,15 +503,13 @@ DEPENDENCIES
letter_opener
listen
localized_language_select!
minitest-rails-capybara
mysql2
nokogiri
omniauth-google-oauth2
omniauth-rails_csrf_protection
omniauth_openid_connect
paper_trail
pg
poltergeist
prawn (< 1.0)
prawn_rails
pry-byebug
Expand All @@ -535,11 +528,13 @@ DEPENDENCIES
rqrcode
sass-rails (< 6)
scanf
selenium-webdriver
simple_form
sqlite3
sucker_punch
transitions
uglifier
webdrivers
will_paginate
yard

Expand Down
14 changes: 7 additions & 7 deletions app/helpers/events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def fix_http_proto(url)
end

def showing_my_events?
params[:events]=='my'
params[:events] == 'my'
end

def event_start_time
Expand All @@ -23,7 +23,7 @@ def timeslots
end
slots
end

def timeslots_for_cfp
@conference.allowed_event_timeslots.map{|slots| [format_time_slots(slots), slots]}
end
Expand Down Expand Up @@ -73,12 +73,12 @@ def show_filters_pane?
end
false
end

def localized_filter_options(c, i18n_scope)
c = split_filter_string(c) if c.is_a? String
options = (c - ['',nil]).map{|v| [ if i18n_scope
options = (c - ['',nil]).map{|v| [ if i18n_scope
t(v, scope: i18n_scope, default: v)
else
else
v
end,
v] }.sort
Expand All @@ -87,7 +87,7 @@ def localized_filter_options(c, i18n_scope)
end
options
end

def split_filter_string(s)
return [''] if s==''
s.split('|', -1)
Expand All @@ -98,7 +98,7 @@ def filter_link(qname, text='')
class: [ 'show_events_modal', ('filter_icon' unless text.present?), params[qname].present? ] ,
data: { url: filter_modal_events_url(request.query_parameters.merge(which_filter: qname)) }
end

def get_op_and_val(str)
/^(?<op>[≤≥=]?)(?<val>.*)$/ =~ str
return op, val
Expand Down
17 changes: 17 additions & 0 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "test_helper"

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
include CapybaraHelper
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]

DatabaseCleaner.strategy = :truncation

def setup
DatabaseCleaner.start
I18n.locale = I18n.default_locale
end

def teardown
DatabaseCleaner.clean
end
end
13 changes: 0 additions & 13 deletions test/features/can_access_home_test.rb

This file was deleted.

49 changes: 0 additions & 49 deletions test/features/editing_event_review_test.rb

This file was deleted.

9 changes: 3 additions & 6 deletions test/support/capybara_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ def sign_in_user(user)
sign_in(user.email, 'frab123')
end

def visit_conference_settings_for(conference)
click_on 'Conferences'
within find('tr', text: conference.title) do
click_on 'Show'
end
find('ul.nav:eq(2)').click_link('Settings')
def sign_out
click_on 'Account'
click_on 'Logout'
end
end
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
require 'test_helper'
require 'application_system_test_case'

class BulkEditTest < FeatureTest
class BulkEditTest < ApplicationSystemTestCase
setup do
@conference = create(:three_day_conference_with_events_and_speakers)
@event = @conference.events.last
@event.update( event_type: 'podium')
@admin = create(:admin_user)
end

it 'can bulk edit', js: true do
test 'can bulk edit' do
sign_in_user(@admin)

visit "/#{@conference.acronym}/events"
click_on "odium" # podium or Podium

assert_content page, 'Listing 1 of 3'
find('a', text: 'Edit these events').trigger('click')
find('a', text: 'Edit these events').click

assert_content page, 'Edit 1 event:'
select 'Change event type'
find('form.bulk_edit_event_type').select 'Film', from: 'bulk_set_value'
find('form.bulk_edit_event_type').click_on 'Set'
accept_alert do
find('form.bulk_edit_event_type').click_on 'Set'
end

assert_content page, 'edit completed successfully'
assert_content page, 'yielded no results'
Expand Down
Loading

0 comments on commit b42a3d4

Please sign in to comment.