effective_test_bot 1.0.8 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/MIT-LICENSE +1 -1
- data/README.md +37 -23
- data/app/helpers/effective_test_bot_controller_helper.rb +1 -1
- data/config/application_system_test_case.rb +3 -13
- data/config/effective_test_bot.rb +13 -0
- data/config/test_helper.rb +17 -9
- data/lib/effective_test_bot.rb +10 -1
- data/lib/effective_test_bot/engine.rb +13 -3
- data/lib/effective_test_bot/version.rb +1 -1
- data/test/concerns/test_seedable/seed.rb +50 -0
- data/test/support/effective_test_bot_assertions.rb +32 -30
- data/test/support/effective_test_bot_minitest_helper.rb +1 -1
- data/test/support/effective_test_bot_screenshots_helper.rb +25 -4
- data/test/test_bot/system/environment_test.rb +11 -12
- data/test/test_botable/base_test.rb +6 -4
- data/test/test_botable/devise_test.rb +1 -1
- metadata +6 -26
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a58127dee25edf6d59d56186bdadc7c6b20b46008d78757e9f29471ab4c77d08
|
|
4
|
+
data.tar.gz: ac0be189890058266890718946bb912bf34105ff39720a92a9041ae16e8ab973
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e039db2969eb5f7f3e1cebaaddb2d20987c2bafd05fac9832addf84c8b76632debad04a4988c60d5e647436e8bd01c1548fc067095d288dedf9167c1690f413
|
|
7
|
+
data.tar.gz: 4e5ca33c5de04e4e0fab7831a855bf6254a1c1ad94d8fd9c4b3e4b22546c17e24405cf9d43bf8530ff878a91bc930c92d2bfaa1271d12d9c1b615ff2b6edc070
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -21,14 +21,18 @@ Turn on tour mode to programatically generate an animated .gif of every workflow
|
|
|
21
21
|
Make sure everything actually works.
|
|
22
22
|
|
|
23
23
|
|
|
24
|
-
##
|
|
24
|
+
## effective_test_bot 1.0
|
|
25
25
|
|
|
26
|
-
This is the
|
|
26
|
+
This is the 1.0 series of effective_test_bot.
|
|
27
27
|
|
|
28
28
|
This requires Rails 5.1+
|
|
29
29
|
|
|
30
30
|
Please check out [Effective TestBot Capybara-Webkit branch](https://github.com/code-and-effect/effective_test_bot/tree/capybara-webit) for more information using this gem with Capybara Webkit and Rails < 5.1.
|
|
31
31
|
|
|
32
|
+
This works with Rails 6.0.0.rc1 and parallelization.
|
|
33
|
+
|
|
34
|
+
See [effective_website](https://github.com/code-and-effect/effective_website) for a working rails website example that uses effective_test_bot.
|
|
35
|
+
|
|
32
36
|
## Getting Started
|
|
33
37
|
|
|
34
38
|
First, make sure your site is using [devise](https://github.com/plataformatec/devise) and that your application javascript includes [jQuery](http://jquery.com/) and rails' [jquery_ujs](https://github.com/rails/jquery-ujs).
|
|
@@ -49,7 +53,13 @@ Then you're ready to install `effective_test_bot`:
|
|
|
49
53
|
|
|
50
54
|
```ruby
|
|
51
55
|
group :test do
|
|
56
|
+
gem 'capybara'
|
|
57
|
+
gem 'selenium-webdriver'
|
|
58
|
+
gem 'webdrivers'
|
|
52
59
|
gem 'effective_test_bot'
|
|
60
|
+
|
|
61
|
+
# Optional. Only required if you want animated gifs.
|
|
62
|
+
gem 'rmagick'
|
|
53
63
|
end
|
|
54
64
|
```
|
|
55
65
|
|
|
@@ -73,28 +83,28 @@ Fixture or seed one user. At least one user -- ideally a fully priviledged admin
|
|
|
73
83
|
|
|
74
84
|
To create the initial user, please add it to either `test/fixtures/users.yml`, the `db/seeds.db` file or the effective_test_bot specific `test/fixtures/seeds.rb` file.
|
|
75
85
|
|
|
76
|
-
|
|
86
|
+
Finally, to test that your testing environment is set up correctly run and work through any issues with:
|
|
77
87
|
|
|
78
88
|
```
|
|
79
|
-
|
|
80
|
-
|
|
89
|
+
rails test:bot:environment
|
|
90
|
+
```
|
|
81
91
|
|
|
82
|
-
|
|
83
|
-
rails db:seed
|
|
92
|
+
You now have effective_test_bot configured and you're ready to go:
|
|
84
93
|
|
|
85
|
-
# Added by effective_test_bot. loads test/fixtures/seeds.rb. 'cause screw yaml.
|
|
86
|
-
rails test:load_fixture_seeds
|
|
87
94
|
```
|
|
95
|
+
rails test
|
|
96
|
+
rails test:system
|
|
88
97
|
|
|
89
|
-
|
|
98
|
+
rails test:bot
|
|
99
|
+
rails test:bot TEST=posts#index
|
|
90
100
|
|
|
91
|
-
|
|
101
|
+
rails test:bot:tour
|
|
92
102
|
|
|
93
|
-
|
|
94
|
-
rails test:bot:
|
|
95
|
-
```
|
|
103
|
+
rails test:bot:fails
|
|
104
|
+
rails test:bot:fails TOUR=true
|
|
96
105
|
|
|
97
|
-
|
|
106
|
+
rails test:bot:fail # Kind of weird with parallelization
|
|
107
|
+
```
|
|
98
108
|
|
|
99
109
|
## How to use this gem
|
|
100
110
|
|
|
@@ -155,8 +165,6 @@ You can pass a Hash of 'fills' to specify specific input values:
|
|
|
155
165
|
|
|
156
166
|
```ruby
|
|
157
167
|
# app/test/system/posts_test.rb
|
|
158
|
-
require 'application_system_test_case'
|
|
159
|
-
|
|
160
168
|
class PostTest < ApplicationSystemTestCase
|
|
161
169
|
test 'creating a new post' do
|
|
162
170
|
visit new_post_path
|
|
@@ -189,8 +197,6 @@ Clicks the first `input[type='submit']` field (or first submit field with the gi
|
|
|
189
197
|
Automatically checks for `assert_no_html5_form_validation_errors`, `assert_jquery_ujs_disable_with` and `assert_no_unpermitted_params`
|
|
190
198
|
|
|
191
199
|
```ruby
|
|
192
|
-
require 'application_system_test_case'
|
|
193
|
-
|
|
194
200
|
class PostTest < ApplicationSystemTestCase
|
|
195
201
|
test 'creating a new post' do
|
|
196
202
|
visit(new_post_path) and fill_form
|
|
@@ -260,8 +266,6 @@ A quick note on speed: You can speed up these test suites by fixturing, seeding
|
|
|
260
266
|
There are a few variations on the one-liner method:
|
|
261
267
|
|
|
262
268
|
```ruby
|
|
263
|
-
require 'application_system_test_case'
|
|
264
|
-
|
|
265
269
|
class PostTest < ApplicationSystemTestCase
|
|
266
270
|
# Runs all 9 crud_action tests against /posts
|
|
267
271
|
crud_test(resource: Post)
|
|
@@ -286,8 +290,6 @@ end
|
|
|
286
290
|
The individual test suites may also be used as part of a larger test:
|
|
287
291
|
|
|
288
292
|
```ruby
|
|
289
|
-
require 'application_system_test_case'
|
|
290
|
-
|
|
291
293
|
class PostTest < ApplicationSystemTestCase
|
|
292
294
|
test 'user may only update a post once' do
|
|
293
295
|
crud_action_test(test: :create_valid, resource: Post, user: User.first)
|
|
@@ -522,6 +524,15 @@ rails test:bot TEST=posts
|
|
|
522
524
|
|
|
523
525
|
# Test a specific controller and action
|
|
524
526
|
rails test:bot TEST=posts#index
|
|
527
|
+
|
|
528
|
+
# Only runs previously failed tests
|
|
529
|
+
rails test:bot:fails
|
|
530
|
+
|
|
531
|
+
# Only runs failed tests and stops after first failure
|
|
532
|
+
rails test:bot:fails
|
|
533
|
+
|
|
534
|
+
# Purges all screenshots and fails
|
|
535
|
+
rails test:bot:purge
|
|
525
536
|
```
|
|
526
537
|
|
|
527
538
|
## Animated gifs and screenshots
|
|
@@ -532,6 +543,7 @@ This method is already called by `fill_form` and `submit_form`.
|
|
|
532
543
|
|
|
533
544
|
To disable taking screenshots entirely set `config.screenshots = false` in the `config/initializers/effective_test_bot.rb` initializer file.
|
|
534
545
|
|
|
546
|
+
You must have `gem 'rmagick'` installed to use animated gifs.
|
|
535
547
|
|
|
536
548
|
### Tour mode
|
|
537
549
|
|
|
@@ -595,6 +607,8 @@ rails test:bot FAILFAST=true
|
|
|
595
607
|
|
|
596
608
|
This functionality is provided thanks to [minitest-fail-fast](https://github.com/teoljungberg/minitest-fail-fast/)
|
|
597
609
|
|
|
610
|
+
It's kind of busted with parallelization but mostly works.
|
|
611
|
+
|
|
598
612
|
### Failed tests only
|
|
599
613
|
|
|
600
614
|
Skip any previously passed tests by running the following:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module EffectiveTestBotControllerHelper
|
|
2
2
|
BODY_TAG = '</body>'
|
|
3
3
|
|
|
4
|
-
# This is included as an after_action in the controller
|
|
4
|
+
# This is included automatically as an after_action in the controller
|
|
5
5
|
def assign_test_bot_payload(payload = {})
|
|
6
6
|
payload.merge!({ response_code: response.code, assigns: test_bot_view_assigns, flash: flash.to_hash })
|
|
7
7
|
|
|
@@ -1,24 +1,14 @@
|
|
|
1
|
+
# Working as per Rails 6.0.0.rc1
|
|
1
2
|
require 'test_helper'
|
|
2
3
|
|
|
3
|
-
require 'capybara'
|
|
4
|
-
require 'selenium-webdriver'
|
|
5
|
-
|
|
6
|
-
Capybara.register_driver :effective_headless do |app|
|
|
7
|
-
options = Selenium::WebDriver::Chrome::Options.new
|
|
8
|
-
|
|
9
|
-
['headless', 'disable-gpu', 'window-size=1366x1366'].each { |arg| options.add_argument(arg) }
|
|
10
|
-
|
|
11
|
-
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
4
|
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
|
15
|
-
driven_by :
|
|
5
|
+
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
|
|
16
6
|
|
|
17
7
|
include Warden::Test::Helpers if defined?(Devise)
|
|
18
8
|
include EffectiveTestBot::DSL
|
|
19
9
|
end
|
|
20
10
|
|
|
21
|
-
# "Connection not rolling back" snippets
|
|
11
|
+
# "Connection not rolling back" snippets from previous rails versions
|
|
22
12
|
# These are some snippets that the internet has collected to fix test threading issues.
|
|
23
13
|
# They are unneeded with effective_test_bot. On my machine. But I leave them here as a reference.
|
|
24
14
|
# Try one or both if you are having issues passing rake test:bot:environment
|
|
@@ -52,6 +52,19 @@ if Rails.env.test?
|
|
|
52
52
|
# Valid values are true / false / :verbose
|
|
53
53
|
config.tour_mode = false
|
|
54
54
|
|
|
55
|
+
# Rmagick gem is required for animated gifs
|
|
56
|
+
#
|
|
57
|
+
# Include the following in your Gemfile:
|
|
58
|
+
# gem 'rmagick'
|
|
59
|
+
config.image_processing_class_name = 'Magick'
|
|
60
|
+
|
|
61
|
+
# FUTURE SUPPORT: ImageProcessing gem is required for animated gifs
|
|
62
|
+
# I'm not sure how to make an animated gif with this gem!
|
|
63
|
+
# gem 'image_processing'
|
|
64
|
+
# ImageProcessing::MiniMagick
|
|
65
|
+
# ImageProcessing::Vips
|
|
66
|
+
# config.image_processing_class_name = 'ImageProcessing::MiniMagick'
|
|
67
|
+
|
|
55
68
|
# How long to delay in between animated gif frames
|
|
56
69
|
# The last frame is applied animated_gif_frame_delay * 3
|
|
57
70
|
# 100 equals 1 second. (a bit on the slow side, but suitable for a demo)
|
data/config/test_helper.rb
CHANGED
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
ENV['RAILS_ENV'] ||= 'test'
|
|
2
2
|
require_relative '../config/environment'
|
|
3
|
-
|
|
4
3
|
require 'rails/test_help'
|
|
5
|
-
|
|
6
|
-
require 'minitest/reporters'
|
|
4
|
+
|
|
7
5
|
require 'minitest/fail_fast' if EffectiveTestBot.fail_fast?
|
|
6
|
+
require 'minitest/reporters'
|
|
7
|
+
require 'minitest/spec'
|
|
8
8
|
|
|
9
9
|
class ActiveSupport::TestCase
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
# Run tests in parallel with specified workers
|
|
11
|
+
parallelize(workers: :number_of_processors) if respond_to?(:parallelize)
|
|
12
|
+
|
|
13
|
+
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
|
14
|
+
fixtures :all
|
|
15
|
+
|
|
16
|
+
# Loads your db/seeds.rb and test/fixtures/seeds.rb before all tests run. Valid options are :all :db and :test
|
|
17
|
+
seeds :all
|
|
18
|
+
|
|
19
|
+
extend Minitest::Spec::DSL # For the let syntax
|
|
12
20
|
end
|
|
13
21
|
|
|
14
22
|
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
|
15
23
|
|
|
16
24
|
Rails.backtrace_cleaner.remove_silencers!
|
|
17
25
|
Rails.backtrace_cleaner.add_silencer { |line| line =~ /minitest/ }
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
# rails test:bot:seed
|
|
26
|
+
Rails.backtrace_cleaner.add_silencer { |line| line =~ /parallelization/ }
|
|
21
27
|
|
|
22
28
|
# rails test
|
|
23
29
|
# rails test:system
|
|
24
30
|
# rails test:bot:environment
|
|
25
31
|
# rails test:bot
|
|
32
|
+
# rails test:bot:fails
|
|
33
|
+
# rails test:bot:fail
|
|
26
34
|
|
|
27
35
|
# rails test:system TOUR=true
|
|
28
|
-
# rails test:bot TEST=posts#index
|
|
36
|
+
# rails test:bot TEST=posts#index
|
data/lib/effective_test_bot.rb
CHANGED
|
@@ -16,6 +16,7 @@ module EffectiveTestBot
|
|
|
16
16
|
mattr_accessor :tour_mode_extreme
|
|
17
17
|
mattr_accessor :animated_gif_delay
|
|
18
18
|
mattr_accessor :animated_gif_background_color
|
|
19
|
+
mattr_accessor :image_processing_class_name
|
|
19
20
|
mattr_accessor :backtrace_lines
|
|
20
21
|
mattr_accessor :silence_skipped_routes
|
|
21
22
|
|
|
@@ -64,8 +65,16 @@ module EffectiveTestBot
|
|
|
64
65
|
screenshots == true
|
|
65
66
|
end
|
|
66
67
|
|
|
68
|
+
def self.gifs?
|
|
69
|
+
image_processing_class.present?
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def self.image_processing_class
|
|
73
|
+
@@image_processing_class ||= image_processing_class_name.safe_constantize
|
|
74
|
+
end
|
|
75
|
+
|
|
67
76
|
def self.autosave_animated_gif_on_failure?
|
|
68
|
-
|
|
77
|
+
autosave_animated_gif_on_failure && gifs?
|
|
69
78
|
end
|
|
70
79
|
|
|
71
80
|
def self.fail_fast?
|
|
@@ -2,9 +2,10 @@ module EffectiveTestBot
|
|
|
2
2
|
class Engine < ::Rails::Engine
|
|
3
3
|
engine_name 'effective_test_bot'
|
|
4
4
|
|
|
5
|
-
config.autoload_paths += Dir["#{config.root}/test/test_botable
|
|
6
|
-
config.autoload_paths += Dir["#{config.root}/test/
|
|
7
|
-
config.autoload_paths += Dir["#{config.root}/test/
|
|
5
|
+
config.autoload_paths += Dir["#{config.root}/test/test_botable/", "#{config.root}/test/concerns/", "#{config.root}/test/support/"]
|
|
6
|
+
# config.autoload_paths += Dir["#{config.root}/test/test_botable/**/"]
|
|
7
|
+
# config.autoload_paths += Dir["#{config.root}/test/concerns/**/"]
|
|
8
|
+
# config.autoload_paths += Dir["#{config.root}/test/support/**/"]
|
|
8
9
|
|
|
9
10
|
# Set up our default configuration options.
|
|
10
11
|
initializer 'effective_test_bot.defaults', before: :load_config_initializers do |app|
|
|
@@ -38,5 +39,14 @@ module EffectiveTestBot
|
|
|
38
39
|
end
|
|
39
40
|
end
|
|
40
41
|
|
|
42
|
+
# Provide the seeds DSL in Ac
|
|
43
|
+
initializer 'effective_test_bot.test_case' do |app|
|
|
44
|
+
if Rails.env.test?
|
|
45
|
+
ActiveSupport.on_load :active_record do
|
|
46
|
+
ActiveSupport::TestCase.send :include, TestSeedable::Seed
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
41
51
|
end
|
|
42
52
|
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# This is automatically included into ActiveSupport::TestCase
|
|
2
|
+
# To give us the seeds :all dsl
|
|
3
|
+
module TestSeedable
|
|
4
|
+
module Seed
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
module ClassMethods
|
|
8
|
+
def seeds(seed = :all)
|
|
9
|
+
raise 'unexpected argument. try :all, :db, :test' unless [:all, :db, :test].include?(seed)
|
|
10
|
+
|
|
11
|
+
ActiveSupport::TestCase.class_eval do
|
|
12
|
+
case seed
|
|
13
|
+
when :all
|
|
14
|
+
def before_setup
|
|
15
|
+
@@_loaded_seeds ||= load_seeds(:all); super
|
|
16
|
+
end
|
|
17
|
+
when :db
|
|
18
|
+
def before_setup
|
|
19
|
+
@@_loaded_seeds ||= load_seeds(:db); super
|
|
20
|
+
end
|
|
21
|
+
when :test
|
|
22
|
+
def before_setup
|
|
23
|
+
@@_loaded_seeds ||= load_seeds(:test); super
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Instance Methods
|
|
31
|
+
def load_seeds(seed = :all)
|
|
32
|
+
db_seeds = "#{Rails.root}/db/seeds.rb"
|
|
33
|
+
test_seeds = "#{Rails.root}/test/fixtures/seeds.rb"
|
|
34
|
+
|
|
35
|
+
case seed
|
|
36
|
+
when :all
|
|
37
|
+
load(db_seeds) if File.exists?(db_seeds)
|
|
38
|
+
load(test_seeds) if File.exists?(test_seeds)
|
|
39
|
+
when :db
|
|
40
|
+
load(db_seeds) if File.exists?(db_seeds)
|
|
41
|
+
when :test
|
|
42
|
+
load(test_seeds) if File.exists?(test_seeds)
|
|
43
|
+
else
|
|
44
|
+
raise('unexpected seed argument. use :all, :db or :test')
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
true
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
module EffectiveTestBotAssertions
|
|
2
|
-
def assert_page_content(content, message
|
|
2
|
+
def assert_page_content(content, message: "(page_content) Expected page content :content: to be present")
|
|
3
3
|
assert page.has_text?(/#{Regexp.escape(content)}/i, wait: 0), message.sub(':content:', content)
|
|
4
4
|
end
|
|
5
5
|
|
|
6
|
-
def assert_no_page_content(content, message
|
|
6
|
+
def assert_no_page_content(content, message: "(page_content) Expected page content :content: to be blank")
|
|
7
7
|
assert page.has_no_text?(/#{Regexp.escape(content)}/i, wait: 0), message.sub(':content:', content)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def assert_signed_in(message
|
|
11
|
-
visit(root_path)
|
|
12
|
-
|
|
10
|
+
def assert_signed_in(message: 'Expected @current_user to be present when signed in')
|
|
11
|
+
visit(root_path)
|
|
12
|
+
assert_page_normal
|
|
13
|
+
assert assigns['current_user'].present?, message
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
def assert_signed_out(message
|
|
16
|
-
visit(root_path)
|
|
17
|
-
|
|
16
|
+
def assert_signed_out(message: 'Expected @current_user to be blank when signed out')
|
|
17
|
+
visit(root_path)
|
|
18
|
+
assert_page_normal
|
|
19
|
+
assert assigns['current_user'].blank?, message
|
|
18
20
|
end
|
|
19
21
|
|
|
20
|
-
def assert_no_exceptions(message
|
|
22
|
+
def assert_no_exceptions(message: "(no_exceptions) Unexpected rails server exception:\n:exception:")
|
|
21
23
|
# this file is created by EffectiveTestBot::Middleware when an exception is encountered in the rails app
|
|
22
24
|
file = File.join(Dir.pwd, 'tmp', 'test_bot', 'exception.txt')
|
|
23
25
|
return unless File.exist?(file)
|
|
@@ -28,7 +30,7 @@ module EffectiveTestBotAssertions
|
|
|
28
30
|
assert false, message.sub(':exception:', exception)
|
|
29
31
|
end
|
|
30
32
|
|
|
31
|
-
def assert_can_execute_javascript(message
|
|
33
|
+
def assert_can_execute_javascript(message: "Expected page.evaluate_script() to be successful")
|
|
32
34
|
error = nil; result = nil;
|
|
33
35
|
|
|
34
36
|
begin
|
|
@@ -40,15 +42,15 @@ module EffectiveTestBotAssertions
|
|
|
40
42
|
assert (result == '2'), "#{message}. Error was: #{error}"
|
|
41
43
|
end
|
|
42
44
|
|
|
43
|
-
def assert_jquery_present(message
|
|
45
|
+
def assert_jquery_present(message: "Expected jquery ($.fn.jquery) to be present")
|
|
44
46
|
assert((page.evaluate_script('$.fn.jquery') rescue nil).to_s.length > 0, message)
|
|
45
47
|
end
|
|
46
48
|
|
|
47
|
-
def assert_jquery_ujs_present(message
|
|
49
|
+
def assert_jquery_ujs_present(message: "Expected rails' jquery_ujs ($.rails) to be present")
|
|
48
50
|
assert((page.evaluate_script('$.rails') rescue nil).to_s.length > 0, message)
|
|
49
51
|
end
|
|
50
52
|
|
|
51
|
-
def assert_page_title(title = :any, message
|
|
53
|
+
def assert_page_title(title = :any, message: '(page_title) Expected page title to be present')
|
|
52
54
|
if title.present? && title != :any
|
|
53
55
|
assert_title(title) # Capybara TitleQuery, match this text
|
|
54
56
|
else
|
|
@@ -57,15 +59,15 @@ module EffectiveTestBotAssertions
|
|
|
57
59
|
end
|
|
58
60
|
end
|
|
59
61
|
|
|
60
|
-
def assert_form(selector, message
|
|
62
|
+
def assert_form(selector, message: "(form) Expected visible form with selector :selector: to be present")
|
|
61
63
|
assert all(selector).present?, message.sub(':selector:', selector)
|
|
62
64
|
end
|
|
63
65
|
|
|
64
|
-
def assert_submit_input(message
|
|
66
|
+
def assert_submit_input(message: "(submit_input) Expected one or more visible input[type='submit'] or button[type='submit'] to be present")
|
|
65
67
|
assert all("input[type='submit'],button[type='submit']").present?, message
|
|
66
68
|
end
|
|
67
69
|
|
|
68
|
-
def assert_authorization(message
|
|
70
|
+
def assert_authorization(message: '(authorization) Expected authorized access')
|
|
69
71
|
if response_code == 403
|
|
70
72
|
exception = access_denied_exception
|
|
71
73
|
|
|
@@ -80,18 +82,18 @@ module EffectiveTestBotAssertions
|
|
|
80
82
|
end
|
|
81
83
|
end
|
|
82
84
|
|
|
83
|
-
def assert_page_status(status = 200, message
|
|
85
|
+
def assert_page_status(status = 200, message: '(page_status) Expected :status: HTTP status code')
|
|
84
86
|
assert_equal status, response_code, message.sub(':status:', status.to_s)
|
|
85
87
|
end
|
|
86
88
|
|
|
87
|
-
def assert_current_path(path, message
|
|
89
|
+
def assert_current_path(path, message: '(current_path) Expected current_path to be :path:')
|
|
88
90
|
path = public_send(path) if path.kind_of?(Symbol)
|
|
89
91
|
assert_equal path, page.current_path, message.sub(':path:', path.to_s)
|
|
90
92
|
end
|
|
91
93
|
|
|
92
94
|
# assert_redirect '/about'
|
|
93
95
|
# assert_redirect '/about', '/about-us'
|
|
94
|
-
def assert_redirect(from_path, to_path = nil, message
|
|
96
|
+
def assert_redirect(from_path, to_path = nil, message: nil)
|
|
95
97
|
if to_path.present?
|
|
96
98
|
assert_equal to_path, page.current_path, message || "(redirect) Expected redirect from #{from_path} to #{to_path}"
|
|
97
99
|
else
|
|
@@ -99,12 +101,12 @@ module EffectiveTestBotAssertions
|
|
|
99
101
|
end
|
|
100
102
|
end
|
|
101
103
|
|
|
102
|
-
def assert_no_ajax_requests(message
|
|
104
|
+
def assert_no_ajax_requests(message: "(no_ajax_requests) :count: Unexpected AJAX requests present")
|
|
103
105
|
active = page.evaluate_script('$.active')
|
|
104
106
|
assert (active.blank? || active.zero?), message.sub(':count:', active.to_s)
|
|
105
107
|
end
|
|
106
108
|
|
|
107
|
-
def assert_no_active_jobs(message
|
|
109
|
+
def assert_no_active_jobs(message: "(no_active_jobs) :count: Unexpected ActiveJob jobs present")
|
|
108
110
|
jobs = if defined?(SuckerPunch)
|
|
109
111
|
SuckerPunch::Queue.all.length
|
|
110
112
|
else
|
|
@@ -114,7 +116,7 @@ module EffectiveTestBotAssertions
|
|
|
114
116
|
assert (jobs == 0), message.sub(':count:', jobs.to_s)
|
|
115
117
|
end
|
|
116
118
|
|
|
117
|
-
def assert_no_js_errors(message
|
|
119
|
+
def assert_no_js_errors(message: nil, strict: false)
|
|
118
120
|
error = page.driver.browser.manage.logs.get(:browser).first # headless_chrome
|
|
119
121
|
|
|
120
122
|
if strict == false
|
|
@@ -124,21 +126,21 @@ module EffectiveTestBotAssertions
|
|
|
124
126
|
assert error.blank?, message || "(no_js_errors) Unexpected javascript error:\n#{error}"
|
|
125
127
|
end
|
|
126
128
|
|
|
127
|
-
def assert_no_flash_errors(message
|
|
129
|
+
def assert_no_flash_errors(message: "(no_flash_errors) Unexpected flash error:\n:flash_errors:")
|
|
128
130
|
assert (!flash.key?('error') && !flash.key?('danger')), message.sub(':flash_errors:', flash.to_s)
|
|
129
131
|
end
|
|
130
132
|
|
|
131
133
|
# This must be run after submit_form()
|
|
132
134
|
# It ensures there are no HTML5 validation errors that would prevent the form from being submit
|
|
133
135
|
# Browsers seem to only consider visible fields, so we will to
|
|
134
|
-
def assert_no_html5_form_validation_errors(message
|
|
136
|
+
def assert_no_html5_form_validation_errors(message: nil)
|
|
135
137
|
errors = all(':invalid', visible: true).map { |field| field['name'] }
|
|
136
138
|
assert errors.blank?, message || "(no_html5_form_validation_errors) Unable to submit form, unexpected HTML5 validation error present on the following fields:\n#{errors.join("\n")}"
|
|
137
139
|
end
|
|
138
140
|
|
|
139
141
|
# Rails jquery-ujs data-disable-with
|
|
140
142
|
# = f.button :submit, 'Save', data: { disable_with: 'Saving...' }
|
|
141
|
-
def assert_jquery_ujs_disable_with(label = nil, message
|
|
143
|
+
def assert_jquery_ujs_disable_with(label = nil, message: nil)
|
|
142
144
|
submits = label.present? ? all("input[type='submit']", text: label) : all("input[type='submit']")
|
|
143
145
|
all_disabled_with = submits.all? { |submit| submit['data-disable-with'].present? }
|
|
144
146
|
|
|
@@ -148,7 +150,7 @@ module EffectiveTestBotAssertions
|
|
|
148
150
|
# assert_flash
|
|
149
151
|
# assert_flash :success
|
|
150
152
|
# assert_flash :error, 'there was a specific error'
|
|
151
|
-
def assert_flash(key = nil, value = nil, message
|
|
153
|
+
def assert_flash(key = nil, value = nil, message: nil)
|
|
152
154
|
if key.present? && value.present?
|
|
153
155
|
assert_equal value, flash[key.to_s], message || "(flash) Expected flash[#{key}] to equal #{value}. Instead, it was: #{value}"
|
|
154
156
|
elsif key.present?
|
|
@@ -161,7 +163,7 @@ module EffectiveTestBotAssertions
|
|
|
161
163
|
# assert_assigns
|
|
162
164
|
# assert_assigns :current_user
|
|
163
165
|
# assert_assigns :current_user, 'there should a current user'
|
|
164
|
-
def assert_assigns(key = nil, value = nil, message
|
|
166
|
+
def assert_assigns(key = nil, value = nil, message: nil)
|
|
165
167
|
if key.present? && value.present?
|
|
166
168
|
assert_equal value, assigns[key.to_s], message || "(assigns) Expected assigns[#{key}] to equal #{value}. Instead, it was: #{value}"
|
|
167
169
|
elsif key.present?
|
|
@@ -173,7 +175,7 @@ module EffectiveTestBotAssertions
|
|
|
173
175
|
|
|
174
176
|
# assert_no_assigns_errors
|
|
175
177
|
# assert_no_assigns_errors :post
|
|
176
|
-
def assert_no_assigns_errors(key = nil, message
|
|
178
|
+
def assert_no_assigns_errors(key = nil, message: nil)
|
|
177
179
|
if key.present?
|
|
178
180
|
errors = (assigns[key.to_s] || {})['errors']
|
|
179
181
|
assert errors.blank?, message || "(no_assigns_errors) Unexpected @#{key} rails validation errors:\n#{errors}"
|
|
@@ -186,7 +188,7 @@ module EffectiveTestBotAssertions
|
|
|
186
188
|
end
|
|
187
189
|
|
|
188
190
|
# assert_assigns_errors :post
|
|
189
|
-
def assert_assigns_errors(key, message
|
|
191
|
+
def assert_assigns_errors(key, message: nil)
|
|
190
192
|
errors = (assigns[key.to_s] || {})['errors']
|
|
191
193
|
assert errors.present?, message || "(assigns_errors) Expected @#{key}.errors to be present"
|
|
192
194
|
end
|
|
@@ -225,7 +227,7 @@ module EffectiveTestBotAssertions
|
|
|
225
227
|
assert false, message || "(assert_email) Expected email with #{expected} to have been delivered"
|
|
226
228
|
end
|
|
227
229
|
|
|
228
|
-
def assert_access_denied(message
|
|
230
|
+
def assert_access_denied(message: nil)
|
|
229
231
|
assert_equal 403, response_code, message || "Expected response code 403 when access denied, but it was: #{response_code || 'nil'}"
|
|
230
232
|
assert_content 'Access Denied'
|
|
231
233
|
assert_no_exceptions
|
|
@@ -7,7 +7,7 @@ module EffectiveTestBotMinitestHelper
|
|
|
7
7
|
def before_teardown
|
|
8
8
|
super
|
|
9
9
|
|
|
10
|
-
if EffectiveTestBot.
|
|
10
|
+
if EffectiveTestBot.gifs? && (@test_bot_screenshot_id || 0) > 0
|
|
11
11
|
if !passed? && EffectiveTestBot.autosave_animated_gif_on_failure?
|
|
12
12
|
save_test_bot_screenshot
|
|
13
13
|
save_test_bot_failure_gif
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
require 'RMagick'
|
|
2
|
-
|
|
3
1
|
module EffectiveTestBotScreenshotsHelper
|
|
4
|
-
include Magick
|
|
5
|
-
|
|
6
2
|
# Creates a screenshot based on the current test and the order in this test.
|
|
7
3
|
def debug_test_bot_screenshot
|
|
8
4
|
filepath = "#{current_test_temp_path}/#{current_test_screenshot_id}.png"
|
|
@@ -17,6 +13,9 @@ module EffectiveTestBotScreenshotsHelper
|
|
|
17
13
|
end
|
|
18
14
|
|
|
19
15
|
def save_test_bot_failure_gif
|
|
16
|
+
return unless EffectiveTestBot.screenshots?
|
|
17
|
+
return unless EffectiveTestBot.gifs?
|
|
18
|
+
|
|
20
19
|
Dir.mkdir(current_test_failure_path) unless File.exist?(current_test_failure_path)
|
|
21
20
|
full_path = (current_test_failure_path + '/' + current_test_failure_filename)
|
|
22
21
|
|
|
@@ -25,6 +24,9 @@ module EffectiveTestBotScreenshotsHelper
|
|
|
25
24
|
end
|
|
26
25
|
|
|
27
26
|
def save_test_bot_tour_gif
|
|
27
|
+
return unless EffectiveTestBot.screenshots?
|
|
28
|
+
return unless EffectiveTestBot.gifs?
|
|
29
|
+
|
|
28
30
|
Dir.mkdir(current_test_tour_path) unless File.exist?(current_test_tour_path)
|
|
29
31
|
full_path = (current_test_tour_path + '/' + current_test_tour_filename)
|
|
30
32
|
|
|
@@ -43,6 +45,15 @@ module EffectiveTestBotScreenshotsHelper
|
|
|
43
45
|
protected
|
|
44
46
|
|
|
45
47
|
def save_test_bot_gif(full_path)
|
|
48
|
+
case EffectiveTestBot.image_processing_class_name
|
|
49
|
+
when 'Magick'
|
|
50
|
+
save_test_bot_gif_with_rmagick(full_path)
|
|
51
|
+
else
|
|
52
|
+
save_test_bot_gif_with_image_processing(full_path)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def save_test_bot_gif_with_rmagick(full_path)
|
|
46
57
|
png_images = @test_bot_screenshot_id.times.map do |x|
|
|
47
58
|
current_test_temp_path + '/' + format_screenshot_id(x+1) + '.png'
|
|
48
59
|
end
|
|
@@ -79,6 +90,16 @@ module EffectiveTestBotScreenshotsHelper
|
|
|
79
90
|
animation.write(full_path)
|
|
80
91
|
end
|
|
81
92
|
|
|
93
|
+
def save_test_bot_gif_with_image_processing(full_path)
|
|
94
|
+
png_images = @test_bot_screenshot_id.times.map do |x|
|
|
95
|
+
current_test_temp_path + '/' + format_screenshot_id(x+1) + '.png'
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# png_images is an Array of file paths
|
|
99
|
+
|
|
100
|
+
raise('unsupported. Accepting PRs.')
|
|
101
|
+
end
|
|
102
|
+
|
|
82
103
|
private
|
|
83
104
|
|
|
84
105
|
# There are 3 different paths we're working with
|
|
@@ -2,8 +2,9 @@ require 'application_system_test_case'
|
|
|
2
2
|
|
|
3
3
|
module TestBot
|
|
4
4
|
class EnvironmentTest < ApplicationSystemTestCase
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
setup do
|
|
6
|
+
@@original_users_count ||= (defined?(User) ? User.unscoped.count : 0)
|
|
7
|
+
end
|
|
7
8
|
|
|
8
9
|
def self.test_order
|
|
9
10
|
:alpha
|
|
@@ -27,35 +28,33 @@ module TestBot
|
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
test '03: at least one user is present' do
|
|
30
|
-
assert (User.count > 0), 'please fixture or seed at least 1 user for effective_test_bot to function'
|
|
31
|
+
assert (User.unscoped.count > 0), 'please fixture or seed at least 1 user for effective_test_bot to function'
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
test '04: activerecord can save a resource' do
|
|
34
35
|
User.new(email: 'unique@testbot.com', password: '!Password123', password_confirmation: '!Password123').save(validate: false)
|
|
35
|
-
assert_equal (original_users_count + 1), User.count
|
|
36
|
+
assert_equal (@@original_users_count + 1), User.unscoped.count
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
test '05: database has rolled back' do
|
|
39
|
-
assert_equal original_users_count, User.count, 'the activerecord resource created in a previous test is still present'
|
|
40
|
+
assert_equal @@original_users_count, User.unscoped.count, 'the activerecord resource created in a previous test is still present'
|
|
40
41
|
end
|
|
41
42
|
|
|
42
43
|
test '06: capybara can sign_in' do
|
|
43
|
-
sign_in(User.first)
|
|
44
|
-
assert_signed_in
|
|
44
|
+
sign_in(User.unscoped.first)
|
|
45
|
+
assert_signed_in(message: 'capybara is unable to sign in via the warden devise helpers')
|
|
45
46
|
end
|
|
46
47
|
|
|
47
48
|
test '07: capybara session has reset' do
|
|
48
|
-
assert_signed_out
|
|
49
|
+
assert_signed_out(message: 'capybara should be signed out at the start of a new test')
|
|
49
50
|
end
|
|
50
51
|
|
|
51
52
|
test '08: capybara database connection is shared' do
|
|
52
53
|
user = User.new(email: 'unique@testbot.com', password: '!Password123', password_confirmation: '!Password123')
|
|
53
|
-
user.
|
|
54
|
-
user.login = 'unique-login' if user.respond_to?(:login)
|
|
55
|
-
user.save!
|
|
54
|
+
user.save!(validate: false)
|
|
56
55
|
|
|
57
56
|
without_screenshots { sign_in_manually(user, '!Password123') }
|
|
58
|
-
assert_signed_in("expected successful devise manual sign in with user created in this test.\nTry using one of the ActiveRecord shared_connection snippets in test/test_helper.rb")
|
|
57
|
+
assert_signed_in(message: "expected successful devise manual sign in with user created in this test.\nTry using one of the ActiveRecord shared_connection snippets in test/test_helper.rb")
|
|
59
58
|
end
|
|
60
59
|
|
|
61
60
|
test '09: capybara can execute javascript' do
|
|
@@ -53,25 +53,27 @@ module BaseTest
|
|
|
53
53
|
|
|
54
54
|
visit(new_path)
|
|
55
55
|
|
|
56
|
-
assert_authorization(hint)
|
|
56
|
+
assert_authorization(message: hint)
|
|
57
57
|
assert_no_exceptions
|
|
58
58
|
assert_page_status
|
|
59
59
|
|
|
60
|
-
assert_form("form#new_#{resource_name}", "TestBotError: Failed to find form#new_#{resource_name}. #{hint}") unless test_bot_skip?(:form)
|
|
60
|
+
assert_form("form#new_#{resource_name}", message: "TestBotError: Failed to find form#new_#{resource_name}. #{hint}") unless test_bot_skip?(:form)
|
|
61
61
|
|
|
62
62
|
within_if("form#new_#{resource_name}", !test_bot_skip?(:form)) do
|
|
63
|
-
assert_submit_input("TestBotError: Failed to find a visible input[type='submit'] on #{page.current_path}. #{hint}")
|
|
63
|
+
assert_submit_input(message: "TestBotError: Failed to find a visible input[type='submit'] on #{page.current_path}. #{hint}")
|
|
64
64
|
|
|
65
65
|
fill_form(resource_attributes)
|
|
66
66
|
submit_novalidate_form
|
|
67
67
|
|
|
68
|
-
assert_authorization(hint)
|
|
68
|
+
assert_authorization(message: hint)
|
|
69
69
|
assert_no_exceptions
|
|
70
70
|
assert_page_status
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
obj = resource_class.last
|
|
74
74
|
assert obj.present?, "TestBotError: Failed to create a resource after submitting form. Errors: #{(assigns[resource_name] || {})['errors']}\n#{hint}."
|
|
75
|
+
|
|
76
|
+
visit root_path
|
|
75
77
|
end
|
|
76
78
|
|
|
77
79
|
obj
|
|
@@ -17,7 +17,7 @@ module DeviseTest
|
|
|
17
17
|
assert_page_normal
|
|
18
18
|
assert_no_flash_errors unless test_bot_skip?(:no_flash_errors)
|
|
19
19
|
|
|
20
|
-
assert_signed_in('Expected @current_user to be present after sign up')
|
|
20
|
+
assert_signed_in(message: 'Expected @current_user to be present after sign up')
|
|
21
21
|
assert User.where(email: email).first.present?, "Expected user to be present after submitting sign up form at #{new_user_registration_path}"
|
|
22
22
|
assert_page_content(I18n.t('devise.registrations.signed_up')) unless test_bot_skip?(:page_content)
|
|
23
23
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: effective_test_bot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Code and Effect
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-05-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -31,9 +31,6 @@ dependencies:
|
|
|
31
31
|
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '2.15'
|
|
34
|
-
- - "<"
|
|
35
|
-
- !ruby/object:Gem::Version
|
|
36
|
-
version: '4.0'
|
|
37
34
|
type: :runtime
|
|
38
35
|
prerelease: false
|
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -41,11 +38,8 @@ dependencies:
|
|
|
41
38
|
- - ">="
|
|
42
39
|
- !ruby/object:Gem::Version
|
|
43
40
|
version: '2.15'
|
|
44
|
-
- - "<"
|
|
45
|
-
- !ruby/object:Gem::Version
|
|
46
|
-
version: '4.0'
|
|
47
41
|
- !ruby/object:Gem::Dependency
|
|
48
|
-
name:
|
|
42
|
+
name: selenium-webdriver
|
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
|
50
44
|
requirements:
|
|
51
45
|
- - ">="
|
|
@@ -59,7 +53,7 @@ dependencies:
|
|
|
59
53
|
- !ruby/object:Gem::Version
|
|
60
54
|
version: '0'
|
|
61
55
|
- !ruby/object:Gem::Dependency
|
|
62
|
-
name:
|
|
56
|
+
name: webdrivers
|
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
|
64
58
|
requirements:
|
|
65
59
|
- - ">="
|
|
@@ -128,20 +122,6 @@ dependencies:
|
|
|
128
122
|
- - ">="
|
|
129
123
|
- !ruby/object:Gem::Version
|
|
130
124
|
version: '0'
|
|
131
|
-
- !ruby/object:Gem::Dependency
|
|
132
|
-
name: rmagick
|
|
133
|
-
requirement: !ruby/object:Gem::Requirement
|
|
134
|
-
requirements:
|
|
135
|
-
- - ">="
|
|
136
|
-
- !ruby/object:Gem::Version
|
|
137
|
-
version: '0'
|
|
138
|
-
type: :runtime
|
|
139
|
-
prerelease: false
|
|
140
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
141
|
-
requirements:
|
|
142
|
-
- - ">="
|
|
143
|
-
- !ruby/object:Gem::Version
|
|
144
|
-
version: '0'
|
|
145
125
|
description: A shared library of rails model & system tests that should pass in every
|
|
146
126
|
Rails application.
|
|
147
127
|
email:
|
|
@@ -171,6 +151,7 @@ files:
|
|
|
171
151
|
- test/concerns/test_botable/page_dsl.rb
|
|
172
152
|
- test/concerns/test_botable/redirect_dsl.rb
|
|
173
153
|
- test/concerns/test_botable/wizard_dsl.rb
|
|
154
|
+
- test/concerns/test_seedable/seed.rb
|
|
174
155
|
- test/fixtures/documents._test
|
|
175
156
|
- test/fixtures/logo.png
|
|
176
157
|
- test/support/effective_test_bot_assertions.rb
|
|
@@ -208,8 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
208
189
|
- !ruby/object:Gem::Version
|
|
209
190
|
version: '0'
|
|
210
191
|
requirements: []
|
|
211
|
-
|
|
212
|
-
rubygems_version: 2.4.5.1
|
|
192
|
+
rubygems_version: 3.0.3
|
|
213
193
|
signing_key:
|
|
214
194
|
specification_version: 4
|
|
215
195
|
summary: A shared library of rails model & system tests that should pass in every
|