effective_test_bot 1.1.36 → 1.2.4
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 +4 -4
- data/lib/effective_test_bot.rb +18 -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 +11 -7
- data/test/support/effective_test_bot_test_helper.rb +20 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfb43e3e70877589f36e4686127e142207377f2f1232bc000dac2749c4d2e5bc
|
4
|
+
data.tar.gz: 48b700956d1bddf075d49abc9c9f4a4d9f32921d0e2bf4268c578518652f6f72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32190b5326ad994c3c2f8ab3eb186bdd47be93fe164649d349e764a2eec54653e4ad38b67d3a0025c6a82325e8a0f89f86093ae1ef8c5fde7fc2fd5544e791b0
|
7
|
+
data.tar.gz: e2e0c8e3e6c71d969d0cddfb6f925ab2747a803051745172d7e407b8b06231df2b5c14a1ed15b5c69dc32ad255de8885f72bbfe389c1382852659cbb61180d69
|
data/lib/effective_test_bot.rb
CHANGED
@@ -3,28 +3,26 @@ require 'effective_test_bot/engine'
|
|
3
3
|
require 'effective_test_bot/dsl'
|
4
4
|
require 'effective_test_bot/middleware'
|
5
5
|
require 'effective_test_bot/version'
|
6
|
+
require 'timecop'
|
6
7
|
|
7
8
|
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
|
9
|
+
mattr_accessor :passed_tests
|
10
|
+
|
11
|
+
def self.config_keys
|
12
|
+
[
|
13
|
+
:user,
|
14
|
+
:except, :only,
|
15
|
+
:fail_fast,
|
16
|
+
:form_fills,
|
17
|
+
:screenshots, :autosave_animated_gif_on_failure,
|
18
|
+
:tour_mode, :tour_mode_extreme,
|
19
|
+
:animated_gif_delay, :animated_gif_background_color,
|
20
|
+
:image_processing_class_name,
|
21
|
+
:backtrace_lines, :silence_skipped_routes
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
include EffectiveGem
|
28
26
|
|
29
27
|
# Test could be something like "crud_test", "crud_test (documents#new)", "documents", documents#new"
|
30
28
|
# 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
|
@@ -11,10 +11,12 @@ module EffectiveTestBotLoginHelper
|
|
11
11
|
def sign_in(user)
|
12
12
|
if user.kind_of?(String)
|
13
13
|
login_as(devise_user_class.find_by_email!(user))
|
14
|
-
elsif 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
|
@@ -34,7 +36,7 @@ module EffectiveTestBotLoginHelper
|
|
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
|
@@ -43,7 +45,7 @@ module EffectiveTestBotLoginHelper
|
|
43
45
|
def sign_up(email: Faker::Internet.email, password: Faker::Internet.password, **options)
|
44
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
|
@@ -52,12 +54,14 @@ module EffectiveTestBotLoginHelper
|
|
52
54
|
end
|
53
55
|
|
54
56
|
def current_user
|
55
|
-
|
56
|
-
|
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
|
57
61
|
end
|
58
62
|
|
59
63
|
def devise_user_class
|
60
|
-
User
|
64
|
+
(current_user_assigns_class || User)
|
61
65
|
end
|
62
66
|
|
63
67
|
end
|
@@ -68,6 +68,18 @@ 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
|
+
|
76
|
+
def with_time_travel(date, &block)
|
77
|
+
Timecop.travel(date)
|
78
|
+
retval = yield
|
79
|
+
Timecop.return
|
80
|
+
retval
|
81
|
+
end
|
82
|
+
|
71
83
|
def click_first(label)
|
72
84
|
click_link(label, match: :first)
|
73
85
|
end
|
@@ -93,6 +105,14 @@ module EffectiveTestBotTestHelper
|
|
93
105
|
key ? assigns[key.to_s] : assigns
|
94
106
|
end
|
95
107
|
|
108
|
+
def current_user_assigns_key
|
109
|
+
assigns.keys.find { |key| key.start_with?('current_') && key.end_with?('_user') } || 'current_user'
|
110
|
+
end
|
111
|
+
|
112
|
+
def current_user_assigns_class
|
113
|
+
current_user_assigns_key.sub('current_').gsub('_', '::').classify.safe_constantize
|
114
|
+
end
|
115
|
+
|
96
116
|
def access_denied_exception
|
97
117
|
return nil unless (page.evaluate_script('window.effective_test_bot.access_denied') rescue nil).present?
|
98
118
|
|
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.4
|
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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: timecop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: A shared library of rails model & system tests that should pass in every
|
126
140
|
Rails application.
|
127
141
|
email:
|