effective_test_bot 1.1.35 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/effective_test_bot.rb +17 -20
- data/lib/effective_test_bot/version.rb +1 -1
- data/test/support/effective_test_bot_assertions.rb +17 -8
- data/test/support/effective_test_bot_form_filler.rb +3 -2
- data/test/support/effective_test_bot_login_helper.rb +18 -9
- data/test/support/effective_test_bot_test_helper.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80ce8222bd314d35d85d3c6fd58620dbd5d8957cd4ece629467968ee3cbb7e5e
|
4
|
+
data.tar.gz: 322fcb891096428196ce8ce3c51a7692bfae9255c72db164b77aa137d39f31cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 486cf835958bdaae57dcb381ee604d05daecddde263189b090db4986c3a12fbe388c0f3d94a204fa8a211d8ff488694c816482e056ef1680657d56034f63b9c7
|
7
|
+
data.tar.gz: d66b36d8ede631896e0228970175bfc67f0b6e911f51613b39fb2dbfde56eafab957cc103b54086003f828a9364e7bd9d718b0c1fc3bc7fd3c22e0fd12080ceb
|
data/lib/effective_test_bot.rb
CHANGED
@@ -5,26 +5,23 @@ require 'effective_test_bot/middleware'
|
|
5
5
|
require 'effective_test_bot/version'
|
6
6
|
|
7
7
|
module EffectiveTestBot
|
8
|
-
mattr_accessor :
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def self.setup
|
26
|
-
yield self
|
27
|
-
end
|
8
|
+
mattr_accessor :passed_tests
|
9
|
+
|
10
|
+
def self.config_keys
|
11
|
+
[
|
12
|
+
:user,
|
13
|
+
:except, :only,
|
14
|
+
:fail_fast,
|
15
|
+
:form_fills,
|
16
|
+
:screenshots, :autosave_animated_gif_on_failure,
|
17
|
+
:tour_mode, :tour_mode_extreme,
|
18
|
+
:animated_gif_delay, :animated_gif_background_color,
|
19
|
+
:image_processing_class_name,
|
20
|
+
:backtrace_lines, :silence_skipped_routes
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
include EffectiveGem
|
28
25
|
|
29
26
|
# Test could be something like "crud_test", "crud_test (documents#new)", "documents", documents#new"
|
30
27
|
# Assertion will be page_title, or flash
|
@@ -1,4 +1,6 @@
|
|
1
1
|
module EffectiveTestBotAssertions
|
2
|
+
include ActiveJob::TestHelper if defined?(ActiveJob::TestHelper)
|
3
|
+
|
2
4
|
def assert_page_content(content, message: "(page_content) Expected page content :content: to be present")
|
3
5
|
assert page.has_text?(/#{Regexp.escape(content)}/i, wait: 0), message.sub(':content:', content)
|
4
6
|
end
|
@@ -10,13 +12,14 @@ module EffectiveTestBotAssertions
|
|
10
12
|
def assert_signed_in(message: 'Expected @current_user to be present when signed in')
|
11
13
|
visit(root_path)
|
12
14
|
assert_page_normal
|
13
|
-
|
15
|
+
|
16
|
+
assert assigns[current_user_assigns_key].present?, message
|
14
17
|
end
|
15
18
|
|
16
19
|
def assert_signed_out(message: 'Expected @current_user to be blank when signed out')
|
17
20
|
visit(root_path)
|
18
21
|
assert_page_normal
|
19
|
-
assert assigns[
|
22
|
+
assert assigns[current_user_assigns_key].blank?, message
|
20
23
|
end
|
21
24
|
|
22
25
|
def assert_no_exceptions(message: "(no_exceptions) Unexpected rails server exception:\n:exception:")
|
@@ -209,35 +212,41 @@ module EffectiveTestBotAssertions
|
|
209
212
|
|
210
213
|
def assert_no_email(&block)
|
211
214
|
before = ActionMailer::Base.deliveries.map { |mail| {to: mail.to, subject: mail.subject} }
|
212
|
-
yield
|
215
|
+
retval = yield
|
213
216
|
after = ActionMailer::Base.deliveries.map { |mail| {to: mail.to, subject: mail.subject} }
|
214
217
|
|
215
218
|
diff = (after - before)
|
216
219
|
|
217
220
|
assert diff.blank?, "(assert_no_email) #{diff.length} unexpected emails delivered: #{diff}"
|
221
|
+
retval
|
218
222
|
end
|
219
223
|
|
220
224
|
# assert_effective_log { click_on('download.txt') }
|
221
|
-
def assert_effective_log(status: nil)
|
225
|
+
def assert_effective_log(status: nil, &block)
|
222
226
|
raise('EffectiveLogging is not defined') unless defined?(EffectiveLogging)
|
223
227
|
raise('expected a block') unless block_given?
|
224
228
|
|
225
229
|
logs = (status.present? ? Effective::Log.where(status: status).all : Effective::Log.all)
|
226
230
|
|
227
231
|
before = logs.count
|
228
|
-
yield
|
232
|
+
retval = yield
|
229
233
|
after = logs.count
|
230
234
|
|
231
235
|
assert (after - before == 1), "(assert_effective_log) Expected one log to have been created"
|
236
|
+
retval
|
232
237
|
end
|
233
238
|
|
234
239
|
# assert_email :new_user_sign_up
|
235
240
|
# assert_email :new_user_sign_up, to: 'newuser@example.com'
|
236
241
|
# assert_email from: 'admin@example.com'
|
237
242
|
def assert_email(action = nil, to: nil, from: nil, subject: nil, body: nil, message: nil, count: nil, &block)
|
243
|
+
retval = nil
|
244
|
+
|
245
|
+
perform_enqueued_jobs if respond_to?(:perform_enqueued_jobs)
|
246
|
+
|
238
247
|
if block_given?
|
239
248
|
before = ActionMailer::Base.deliveries.length
|
240
|
-
yield
|
249
|
+
retval = yield
|
241
250
|
difference = (ActionMailer::Base.deliveries.length - before)
|
242
251
|
|
243
252
|
if count.present?
|
@@ -249,7 +258,7 @@ module EffectiveTestBotAssertions
|
|
249
258
|
|
250
259
|
if (action || to || from || subject || body).nil?
|
251
260
|
assert ActionMailer::Base.deliveries.present?, message || "(assert_email) Expected email to have been delivered"
|
252
|
-
return
|
261
|
+
return retval
|
253
262
|
end
|
254
263
|
|
255
264
|
actions = ActionMailer::Base.instance_variable_get(:@mailer_actions)
|
@@ -263,7 +272,7 @@ module EffectiveTestBotAssertions
|
|
263
272
|
matches &&= (message.subject == subject) if subject
|
264
273
|
matches &&= (message.body == body) if body
|
265
274
|
|
266
|
-
return if matches
|
275
|
+
return retval if matches
|
267
276
|
end
|
268
277
|
|
269
278
|
expected = [
|
@@ -9,7 +9,7 @@ module EffectiveTestBotFormFiller
|
|
9
9
|
tabs = all("a[data-toggle='tab']", wait: false)
|
10
10
|
|
11
11
|
# If there's only 1 tab, just fill it out
|
12
|
-
|
12
|
+
return fill_form_fields(fills) unless tabs.length > 1
|
13
13
|
|
14
14
|
# If there's more than one tab:
|
15
15
|
# We first fill in all fields that are outside of the tab-content
|
@@ -50,9 +50,10 @@ module EffectiveTestBotFormFiller
|
|
50
50
|
|
51
51
|
# Only fills in visible fields
|
52
52
|
# fill_form(:email => 'somethign@soneone.com', :password => 'blahblah', 'user.last_name' => 'hlwerewr')
|
53
|
-
def fill_form_fields(fills = {}
|
53
|
+
def fill_form_fields(fills = {})
|
54
54
|
save_test_bot_screenshot
|
55
55
|
|
56
|
+
debug = fills.delete(:debug)
|
56
57
|
seen = {}
|
57
58
|
|
58
59
|
5.times do
|
@@ -10,11 +10,13 @@ module EffectiveTestBotLoginHelper
|
|
10
10
|
# This is currently hardcoded to use the warden login_as test helper
|
11
11
|
def sign_in(user)
|
12
12
|
if user.kind_of?(String)
|
13
|
-
login_as(
|
14
|
-
elsif user.
|
13
|
+
login_as(devise_user_class.find_by_email!(user))
|
14
|
+
elsif user.class.name.end_with?('User')
|
15
15
|
raise 'user must be persisted' unless user.persisted?
|
16
16
|
user.reload
|
17
|
-
|
17
|
+
|
18
|
+
devise_scope = user.class.name.underscore.gsub('/', '_').to_sym
|
19
|
+
login_as(user, scope: devise_scope)
|
18
20
|
elsif user == false
|
19
21
|
true # Do nothing
|
20
22
|
else
|
@@ -28,31 +30,38 @@ module EffectiveTestBotLoginHelper
|
|
28
30
|
end
|
29
31
|
|
30
32
|
def sign_in_manually(user_or_email, password = nil)
|
31
|
-
visit new_user_session_path
|
33
|
+
visit (respond_to?(:new_user_session_path) ? new_user_session_path : '/users/sign_in')
|
32
34
|
|
33
35
|
email = (user_or_email.respond_to?(:email) ? user_or_email.email : user_or_email)
|
34
36
|
username = (user_or_email.respond_to?(:username) ? user_or_email.username : user_or_email)
|
35
37
|
login = (user_or_email.respond_to?(:login) ? user_or_email.login : user_or_email)
|
36
38
|
|
37
|
-
within('form
|
39
|
+
within('form[id^=new][id$=user]') do
|
38
40
|
fill_form(email: email, password: password, username: username, login: login)
|
39
41
|
submit_novalidate_form
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
45
|
def sign_up(email: Faker::Internet.email, password: Faker::Internet.password, **options)
|
44
|
-
visit new_user_registration_path
|
46
|
+
visit (respond_to?(:new_user_registration_path) ? new_user_registration_path : '/users/sign_up')
|
45
47
|
|
46
|
-
within('form
|
48
|
+
within('form[id^=new][id$=user]') do
|
47
49
|
fill_form({email: email, password: password, password_confirmation: password}.merge(options))
|
48
50
|
submit_novalidate_form
|
49
51
|
end
|
50
52
|
|
51
|
-
|
53
|
+
devise_user_class.find_by_email(email)
|
52
54
|
end
|
53
55
|
|
54
56
|
def current_user
|
55
|
-
|
57
|
+
user_id = assigns.dig(current_user_assigns_key, 'id')
|
58
|
+
return if user_id.blank?
|
59
|
+
|
60
|
+
devise_user_class.where(id: user_id).first
|
61
|
+
end
|
62
|
+
|
63
|
+
def devise_user_class
|
64
|
+
(current_user_assigns_class || User)
|
56
65
|
end
|
57
66
|
|
58
67
|
end
|
@@ -68,6 +68,11 @@ module EffectiveTestBotTestHelper
|
|
68
68
|
Array(all(selector).first).each { |field| within(field) { yield } }
|
69
69
|
end
|
70
70
|
|
71
|
+
def within_tab(name, &block)
|
72
|
+
first("a.nav-link#tab-#{name.parameterize}").click
|
73
|
+
within_first("div.tab-pane##{name.parameterize}") { yield }
|
74
|
+
end
|
75
|
+
|
71
76
|
def click_first(label)
|
72
77
|
click_link(label, match: :first)
|
73
78
|
end
|
@@ -93,6 +98,14 @@ module EffectiveTestBotTestHelper
|
|
93
98
|
key ? assigns[key.to_s] : assigns
|
94
99
|
end
|
95
100
|
|
101
|
+
def current_user_assigns_key
|
102
|
+
assigns.keys.find { |key| key.start_with?('current_') && key.end_with?('_user') } || 'current_user'
|
103
|
+
end
|
104
|
+
|
105
|
+
def current_user_assigns_class
|
106
|
+
current_user_assigns_key.sub('current_').gsub('_', '::').classify.safe_constantize
|
107
|
+
end
|
108
|
+
|
96
109
|
def access_denied_exception
|
97
110
|
return nil unless (page.evaluate_script('window.effective_test_bot.access_denied') rescue nil).present?
|
98
111
|
|
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.
|
4
|
+
version: 1.2.3
|
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: 2021-
|
11
|
+
date: 2021-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|