Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Commit

Permalink
Convert capybara integration tests into rails system tests
Browse files Browse the repository at this point in the history
  • Loading branch information
proglottis committed May 11, 2017
1 parent 122f3cb commit 1e3295f
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 84 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -18,6 +18,7 @@
.ruby-version
.ruby-gemset
.DS_Store
.byebug_history

/public/sitemap.xml.gz

Expand Down
5 changes: 4 additions & 1 deletion Gemfile
Expand Up @@ -3,6 +3,7 @@ source 'https://rubygems.org'
gem 'rails', '5.1.0'

gem 'pg'
gem 'puma', '~> 3.7'
gem 'sass-rails'
gem 'sprockets', '3.6.3' # remove when fixed: DEPRECATION WARNING: Sprockets method `register_engine` is deprecated.
gem 'coffee-rails'
Expand Down Expand Up @@ -35,7 +36,9 @@ gem 'capistrano-passenger'
group :test, :development do
gem 'listen'
gem 'minitest-spec-rails'
gem 'capybara_minitest_spec'
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'capybara', '~> 2.13.0'
gem 'selenium-webdriver'
gem 'factory_girl_rails', '~> 4.0'
end
gem 'spring', group: :development
24 changes: 18 additions & 6 deletions Gemfile.lock
Expand Up @@ -43,11 +43,13 @@ GEM
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.4.0)
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
airbrussh (1.1.1)
sshkit (>= 1.6.1, != 1.7.0)
arel (8.0.0)
builder (3.2.3)
byebug (9.0.6)
capistrano (3.6.1)
airbrussh (>= 1.0.0)
capistrano-harrow
Expand All @@ -63,16 +65,15 @@ GEM
capistrano-rails (1.1.8)
capistrano (~> 3.1)
capistrano-bundler (~> 1.1)
capybara (2.10.1)
capybara (2.13.0)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
capybara_minitest_spec (1.0.5)
capybara (>= 2)
minitest (>= 4)
childprocess (0.7.0)
ffi (~> 1.0, >= 1.0.11)
chronic (0.10.2)
coffee-rails (4.2.1)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -175,6 +176,8 @@ GEM
oauth2 (~> 1.0)
omniauth (~> 1.2)
pg (0.19.0)
public_suffix (2.0.5)
puma (3.8.2)
rack (2.0.1)
rack-test (0.6.3)
rack (>= 1.0)
Expand Down Expand Up @@ -210,6 +213,7 @@ GEM
record_tag_helper (1.0.0)
actionview (~> 5.x)
ref (2.0.0)
rubyzip (1.2.1)
sass (3.4.22)
sass-rails (5.0.6)
railties (>= 4.0.0, < 6)
Expand All @@ -220,6 +224,10 @@ GEM
sdoc (0.4.2)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
selenium-webdriver (3.4.0)
childprocess (~> 0.5)
rubyzip (~> 1.0)
websocket (~> 1.0)
sitemap_generator (5.2.0)
builder (~> 3.0)
spring (2.0.0)
Expand Down Expand Up @@ -247,6 +255,7 @@ GEM
thread_safe (~> 0.1)
uglifier (3.0.2)
execjs (>= 0.3.0, < 3)
websocket (1.2.4)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
Expand All @@ -260,11 +269,12 @@ PLATFORMS

DEPENDENCIES
active_model_serializers
byebug
capistrano (~> 3.6.1)
capistrano-bundler
capistrano-passenger
capistrano-rails
capybara_minitest_spec
capybara (~> 2.13.0)
coffee-rails
dalli
exception_notification (~> 4.0.0.rc1)
Expand All @@ -282,10 +292,12 @@ DEPENDENCIES
omniauth
omniauth-google-oauth2
pg
puma (~> 3.7)
rails (= 5.1.0)
record_tag_helper
sass-rails
sdoc (~> 0.4.0)
selenium-webdriver
sitemap_generator
spring
sprockets (= 3.6.3)
Expand Down
14 changes: 14 additions & 0 deletions test/application_system_test_case.rb
@@ -0,0 +1,14 @@
require "test_helper"

class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :chrome, screen_size: [1400, 1400]

def login_service
service = create(:service)
OmniAuth.config.add_mock("developer", "uid" => service.uid, "info" => {"name" => service.name, "email" => service.email})
visit session_path
click_link "Developer"
assert_text I18n.t('sessions.create.success', :provider => 'Developer')
service
end
end
@@ -1,6 +1,6 @@
require "test_helper"
require "application_system_test_case"

class ChallengesIntegrationTest < ActionDispatch::IntegrationTest
class ChallengesTest < ApplicationSystemTestCase
before do
@service = login_service
@tournament = create(:started_tournament)
Expand All @@ -17,17 +17,17 @@ class ChallengesIntegrationTest < ActionDispatch::IntegrationTest
visit tournament_path @tournament
all('a', :text => I18n.t('tournaments.show.challenge')).last.click
click_button I18n.t('helpers.submit.create')
must_have_content @rating1.user.name
must_have_content @rating2.user.name
assert_text @rating1.user.name
assert_text @rating2.user.name
end

it "must send challenge email" do
visit tournament_path @tournament
all('a', :text => I18n.t('tournaments.show.challenge')).last.click
click_button I18n.t('helpers.submit.create')
ActionMailer::Base.deliveries.length.must_equal 1
assert_equal 1, ActionMailer::Base.deliveries.length
email = ActionMailer::Base.deliveries.first
email.to.must_equal [@user2.email]
assert_equal [@user2.email], email.to
end
end

Expand Down
@@ -1,6 +1,6 @@
require "test_helper"
require "application_system_test_case"

class GamesIntegrationTest < ActionDispatch::IntegrationTest
class GamesTest < ApplicationSystemTestCase
before do
@service = login_service
@tournament = create(:started_tournament)
Expand All @@ -14,15 +14,17 @@ class GamesIntegrationTest < ActionDispatch::IntegrationTest
describe "creation" do
it "must be created" do
visit tournament_path @tournament
find('a.dropdown-toggle span.caret').click
click_link I18n.t('tournaments.show.log_a_game')
click_button I18n.t('helpers.submit.create')
must_have_content @rating1.user.name
must_have_content @rating2.user.name
must_have_content I18n.t('games.game_rank.unconfirmed')
assert_text @rating1.user.name
assert_text @rating2.user.name
assert_text I18n.t('games.game_rank.unconfirmed')
end

it "must send confirmation email" do
visit tournament_path @tournament
find('a.dropdown-toggle span.caret').click
click_link I18n.t('tournaments.show.log_a_game')
click_button I18n.t('helpers.submit.create')
ActionMailer::Base.deliveries.length.must_equal 1
Expand All @@ -41,7 +43,7 @@ class GamesIntegrationTest < ActionDispatch::IntegrationTest
it "must be confirmed" do
visit game_path @game
click_button I18n.t('games.show.confirm')
must_have_content I18n.t('games.game_rank.confirmed', :time => 'less than a minute')
assert_text I18n.t('games.game_rank.confirmed', :time => 'less than a minute')
end

describe "on final confirmation" do
Expand Down Expand Up @@ -78,13 +80,10 @@ class GamesIntegrationTest < ActionDispatch::IntegrationTest
end

it "must respond" do
must_have_content I18n.t('games.game_rank.confirmed', :time => 'less than a minute')
end

it "must send confirmation email" do
ActionMailer::Base.deliveries.length.must_equal 1
assert_text I18n.t('games.game_rank.confirmed', :time => 'less than a minute')
assert_equal 1, ActionMailer::Base.deliveries.length
email = ActionMailer::Base.deliveries.first
email.to.must_equal [@player2.user.email]
assert_equal [@player2.user.email], email.to
end
end

Expand All @@ -96,13 +95,10 @@ class GamesIntegrationTest < ActionDispatch::IntegrationTest
end

it "must respond" do
must_have_content I18n.t('games.game_rank.confirmed', :time => 'less than a minute')
end

it "must send confirmation email" do
ActionMailer::Base.deliveries.length.must_equal 1
assert_text I18n.t('games.game_rank.confirmed', :time => 'less than a minute')
assert_equal 1, ActionMailer::Base.deliveries.length
email = ActionMailer::Base.deliveries.first
email.to.must_equal [@player2.user.email]
assert_equal [@player2.user.email], email.to
end
end
end
Expand Down
@@ -1,6 +1,6 @@
require "test_helper"
require "application_system_test_case"

class InvitesIntegrationTest < ActionDispatch::IntegrationTest
class InvitesTest < ApplicationSystemTestCase
before do
@service = login_service
@tournament = create(:started_tournament)
Expand All @@ -17,15 +17,15 @@ class InvitesIntegrationTest < ActionDispatch::IntegrationTest
visit new_tournament_invite_path @tournament
fill_in Invite.human_attribute_name("email"), :with => "user@example.com"
click_button Invite.model_name.human
must_have_content @tournament.name
assert_text @tournament.name
Invite.last.email.must_equal "user@example.com"
end

it "must send invite email" do
visit new_tournament_invite_path @tournament
fill_in Invite.human_attribute_name("email"), :with => "user@example.com"
click_button Invite.model_name.human
must_have_content @tournament.name
assert_text @tournament.name
ActionMailer::Base.deliveries.length.must_equal 1
email = ActionMailer::Base.deliveries.first
email.to.must_equal ["user@example.com"]
Expand All @@ -39,16 +39,16 @@ class InvitesIntegrationTest < ActionDispatch::IntegrationTest

it "must show invite page" do
visit tournament_invite_path @tournament, @invite
must_have_content @tournament.name
must_have_button I18n.t("helpers.submit.invite.update")
must_have_link I18n.t("helpers.cancel_link")
assert_text @tournament.name
assert_button I18n.t("helpers.submit.invite.update")
assert_link I18n.t("helpers.cancel_link")
end

it "must join player" do
visit tournament_invite_path @tournament, @invite
click_button I18n.t("helpers.submit.invite.update")
must_have_content @tournament.name
must_have_content @user.name
assert_text @tournament.name
assert_text @user.name
end
end

Expand Down
@@ -1,6 +1,6 @@
require "test_helper"
require "application_system_test_case"

class SessionsIntegrationTest < ActionDispatch::IntegrationTest
class SessionsTest < ApplicationSystemTestCase
before do
@omniauth = OmniAuth.config.add_mock('developer', "info" => {"name" => "Bob Bobson", "email" => "bob@bob.com"})
end
Expand All @@ -14,20 +14,20 @@ class SessionsIntegrationTest < ActionDispatch::IntegrationTest
it "must authenticate" do
visit session_path
click_link "Developer"
must_have_content I18n.translate('sessions.create.success', :provider => 'Developer')
assert_text I18n.translate('sessions.create.success', :provider => 'Developer')
end

it "must redirect back after authentication" do
visit games_path
click_link "Developer"
must_have_content Game.model_name.human.pluralize
assert_text Game.model_name.human.pluralize
end

it "must update info after authentication" do
@omniauth['info']['image'] = 'http://localhost:3000'
visit session_path
click_link "Developer"
must_have_content I18n.translate('sessions.create.success', :provider => 'Developer')
assert_text I18n.translate('sessions.create.success', :provider => 'Developer')
@service.reload.image_url.must_equal 'http://localhost:3000'
end
end
Expand All @@ -36,26 +36,24 @@ class SessionsIntegrationTest < ActionDispatch::IntegrationTest
it "must show new account creation" do
visit session_path
click_link "Developer"
must_have_content @omniauth["provider"].humanize
must_have_content @omniauth["uid"]
must_have_content @omniauth["info"]["name"]
must_have_content @omniauth["info"]["email"]
must_have_button I18n.translate('sessions.new.confirm')
must_have_button I18n.translate('helpers.cancel_link')
assert_text @omniauth["provider"].humanize
assert_text @omniauth["uid"]
assert_text @omniauth["info"]["name"]
assert_text @omniauth["info"]["email"]
end

it "must authenticate" do
visit session_path
click_link "Developer"
click_button I18n.translate('sessions.new.confirm')
must_have_content I18n.translate('sessions.create.success', :provider => 'Developer')
assert_text I18n.translate('sessions.create.success', :provider => 'Developer')
end

it "must redirect on cancel" do
visit session_path
click_link "Developer"
click_button I18n.translate('helpers.cancel_link')
must_have_content I18n.translate('sessions.create.canceled', :provider => 'Developer')
assert_text I18n.translate('sessions.create.canceled', :provider => 'Developer')
end
end

Expand All @@ -64,21 +62,21 @@ class SessionsIntegrationTest < ActionDispatch::IntegrationTest
OmniAuth.config.mock_auth[:developer] = :invalid_credentials
visit session_path
click_link "Developer"
must_have_content I18n.translate('sessions.failure.invalid')
assert_text I18n.translate('sessions.failure.invalid')
end

it "must display time out" do
OmniAuth.config.mock_auth[:developer] = :timeout
visit session_path
click_link "Developer"
must_have_content I18n.translate('sessions.failure.timed_out')
assert_text I18n.translate('sessions.failure.timed_out')
end

it "must display unknown error" do
OmniAuth.config.mock_auth[:developer] = :something_else
visit session_path
click_link "Developer"
must_have_content I18n.translate('sessions.failure.unknown')
assert_text I18n.translate('sessions.failure.unknown')
end
end

Expand All @@ -88,7 +86,7 @@ class SessionsIntegrationTest < ActionDispatch::IntegrationTest
click_link "Developer"
click_button I18n.translate('sessions.new.confirm')
visit logout_path
must_have_content I18n.translate('sessions.destroy.success')
assert_text I18n.translate('sessions.destroy.success')
end
end
end

0 comments on commit 1e3295f

Please sign in to comment.