effective_test_bot 1.1.34 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/effective_test_bot_controller_helper.rb +2 -2
- 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 +13 -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 +8 -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: 647d5dd319259ed9c24df5ffc927e84a8c10e8a5dba646c51a4b986ce4a770a1
|
4
|
+
data.tar.gz: 043afb956e64b693898b2c3d640b6498217f01781cf2fbba34d20e2a02587e80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31dd6ecaa5eaf1a2ace0a162c994e7bafd3c67eb0997cc924fdaa0bce2c74e79d00337cd5bbff05472ab8f0f76e7c70b30428326c96fef7f48dd5feb810ca05f
|
7
|
+
data.tar.gz: 5fa422b2fe60f3e4c9ad057e77ed6335c41d273b6ddb563db20b674d3f1363a1dfe2a08f4ed59b6256d16a04c601a44cd047677d2479c76bacbbeda1b6f5073f
|
@@ -58,10 +58,10 @@ module EffectiveTestBotControllerHelper
|
|
58
58
|
case object
|
59
59
|
when ActiveRecord::Base
|
60
60
|
assigns[key] = object.attributes
|
61
|
-
assigns[key][:errors] = object.errors.messages.
|
61
|
+
assigns[key][:errors] = object.errors.messages.select { |_, v| v.present? } if object.errors.present?
|
62
62
|
when (ActiveModel::Model rescue nil)
|
63
63
|
assigns[key] = object.respond_to?(:attributes) ? object.attributes : { present_but_not_serialized: true }
|
64
|
-
assigns[key][:errors] = object.errors.messages.
|
64
|
+
assigns[key][:errors] = object.errors.messages.select { |_, v| v.present? } if object.errors.present?
|
65
65
|
when TrueClass, FalseClass, NilClass, String, Symbol, Numeric
|
66
66
|
assigns[key] = object
|
67
67
|
else
|
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
|
@@ -10,13 +10,14 @@ module EffectiveTestBotAssertions
|
|
10
10
|
def assert_signed_in(message: 'Expected @current_user to be present when signed in')
|
11
11
|
visit(root_path)
|
12
12
|
assert_page_normal
|
13
|
-
|
13
|
+
|
14
|
+
assert assigns[current_user_assigns_key].present?, message
|
14
15
|
end
|
15
16
|
|
16
17
|
def assert_signed_out(message: 'Expected @current_user to be blank when signed out')
|
17
18
|
visit(root_path)
|
18
19
|
assert_page_normal
|
19
|
-
assert assigns[
|
20
|
+
assert assigns[current_user_assigns_key].blank?, message
|
20
21
|
end
|
21
22
|
|
22
23
|
def assert_no_exceptions(message: "(no_exceptions) Unexpected rails server exception:\n:exception:")
|
@@ -209,35 +210,39 @@ module EffectiveTestBotAssertions
|
|
209
210
|
|
210
211
|
def assert_no_email(&block)
|
211
212
|
before = ActionMailer::Base.deliveries.map { |mail| {to: mail.to, subject: mail.subject} }
|
212
|
-
yield
|
213
|
+
retval = yield
|
213
214
|
after = ActionMailer::Base.deliveries.map { |mail| {to: mail.to, subject: mail.subject} }
|
214
215
|
|
215
216
|
diff = (after - before)
|
216
217
|
|
217
218
|
assert diff.blank?, "(assert_no_email) #{diff.length} unexpected emails delivered: #{diff}"
|
219
|
+
retval
|
218
220
|
end
|
219
221
|
|
220
222
|
# assert_effective_log { click_on('download.txt') }
|
221
|
-
def assert_effective_log(status: nil)
|
223
|
+
def assert_effective_log(status: nil, &block)
|
222
224
|
raise('EffectiveLogging is not defined') unless defined?(EffectiveLogging)
|
223
225
|
raise('expected a block') unless block_given?
|
224
226
|
|
225
227
|
logs = (status.present? ? Effective::Log.where(status: status).all : Effective::Log.all)
|
226
228
|
|
227
229
|
before = logs.count
|
228
|
-
yield
|
230
|
+
retval = yield
|
229
231
|
after = logs.count
|
230
232
|
|
231
233
|
assert (after - before == 1), "(assert_effective_log) Expected one log to have been created"
|
234
|
+
retval
|
232
235
|
end
|
233
236
|
|
234
237
|
# assert_email :new_user_sign_up
|
235
238
|
# assert_email :new_user_sign_up, to: 'newuser@example.com'
|
236
239
|
# assert_email from: 'admin@example.com'
|
237
240
|
def assert_email(action = nil, to: nil, from: nil, subject: nil, body: nil, message: nil, count: nil, &block)
|
241
|
+
retval = nil
|
242
|
+
|
238
243
|
if block_given?
|
239
244
|
before = ActionMailer::Base.deliveries.length
|
240
|
-
yield
|
245
|
+
retval = yield
|
241
246
|
difference = (ActionMailer::Base.deliveries.length - before)
|
242
247
|
|
243
248
|
if count.present?
|
@@ -249,7 +254,7 @@ module EffectiveTestBotAssertions
|
|
249
254
|
|
250
255
|
if (action || to || from || subject || body).nil?
|
251
256
|
assert ActionMailer::Base.deliveries.present?, message || "(assert_email) Expected email to have been delivered"
|
252
|
-
return
|
257
|
+
return retval
|
253
258
|
end
|
254
259
|
|
255
260
|
actions = ActionMailer::Base.instance_variable_get(:@mailer_actions)
|
@@ -263,7 +268,7 @@ module EffectiveTestBotAssertions
|
|
263
268
|
matches &&= (message.subject == subject) if subject
|
264
269
|
matches &&= (message.body == body) if body
|
265
270
|
|
266
|
-
return if matches
|
271
|
+
return retval if matches
|
267
272
|
end
|
268
273
|
|
269
274
|
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
|
@@ -93,6 +93,14 @@ module EffectiveTestBotTestHelper
|
|
93
93
|
key ? assigns[key.to_s] : assigns
|
94
94
|
end
|
95
95
|
|
96
|
+
def current_user_assigns_key
|
97
|
+
assigns.keys.find { |key| key.start_with?('current_') && key.end_with?('_user') } || 'current_user'
|
98
|
+
end
|
99
|
+
|
100
|
+
def current_user_assigns_class
|
101
|
+
current_user_assigns_key.sub('current_').gsub('_', '::').classify.safe_constantize
|
102
|
+
end
|
103
|
+
|
96
104
|
def access_denied_exception
|
97
105
|
return nil unless (page.evaluate_script('window.effective_test_bot.access_denied') rescue nil).present?
|
98
106
|
|
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.2
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|