effective_test_bot 1.1.32 → 1.2.0
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 +24 -5
- data/test/support/effective_test_bot_form_filler.rb +18 -3
- data/test/support/effective_test_bot_login_helper.rb +18 -9
- data/test/support/effective_test_bot_test_helper.rb +9 -1
- 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: e4b11fd2fb320e9749fb22973e5a83b3b66d40c4bc250f41c8e753f351b9ebf8
|
4
|
+
data.tar.gz: d9f59e7a13b07a2c0584009ad587dd018ab3a1f44e7515e74ae62e2a80b4087e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae3c9fe2c536236be682607375c9767e8cb752764d24cc766a0d56f53b08dade662bbe6fb4ffc45622fcf4ec6fdded9434135306cbb2d8b208b1e1aa8f69fb1a
|
7
|
+
data.tar.gz: ffef5bfd26a4708d87b328ebd9a9f5056c455a5380402c7825aa8f979bc8a1562a1ddfde1bcd1078fcc3a1615e0c2678a6e24c232f3a8335e2916f3d9fb7ec84
|
@@ -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:")
|
@@ -217,16 +218,34 @@ module EffectiveTestBotAssertions
|
|
217
218
|
assert diff.blank?, "(assert_no_email) #{diff.length} unexpected emails delivered: #{diff}"
|
218
219
|
end
|
219
220
|
|
221
|
+
# assert_effective_log { click_on('download.txt') }
|
222
|
+
def assert_effective_log(status: nil)
|
223
|
+
raise('EffectiveLogging is not defined') unless defined?(EffectiveLogging)
|
224
|
+
raise('expected a block') unless block_given?
|
225
|
+
|
226
|
+
logs = (status.present? ? Effective::Log.where(status: status).all : Effective::Log.all)
|
227
|
+
|
228
|
+
before = logs.count
|
229
|
+
yield
|
230
|
+
after = logs.count
|
231
|
+
|
232
|
+
assert (after - before == 1), "(assert_effective_log) Expected one log to have been created"
|
233
|
+
end
|
234
|
+
|
220
235
|
# assert_email :new_user_sign_up
|
221
236
|
# assert_email :new_user_sign_up, to: 'newuser@example.com'
|
222
237
|
# assert_email from: 'admin@example.com'
|
223
|
-
def assert_email(action = nil, to: nil, from: nil, subject: nil, body: nil, message: nil, &block)
|
238
|
+
def assert_email(action = nil, to: nil, from: nil, subject: nil, body: nil, message: nil, count: nil, &block)
|
224
239
|
if block_given?
|
225
240
|
before = ActionMailer::Base.deliveries.length
|
226
241
|
yield
|
227
|
-
|
242
|
+
difference = (ActionMailer::Base.deliveries.length - before)
|
228
243
|
|
229
|
-
|
244
|
+
if count.present?
|
245
|
+
assert (difference == count), "(assert_email) Expected #{count} email to have been delivered, but #{difference} were instead"
|
246
|
+
else
|
247
|
+
assert (difference > 0), "(assert_email) Expected at least one email to have been delivered"
|
248
|
+
end
|
230
249
|
end
|
231
250
|
|
232
251
|
if (action || to || from || subject || body).nil?
|
@@ -37,7 +37,7 @@ module EffectiveTestBotFormFiller
|
|
37
37
|
save_test_bot_screenshot
|
38
38
|
|
39
39
|
tab_href = '#' + tab['href'].to_s.split('#').last
|
40
|
-
|
40
|
+
within_if('div' + tab_href) { fill_form_fields(fills) }
|
41
41
|
end
|
42
42
|
|
43
43
|
# If there is no visible submits, go back to the first tab
|
@@ -193,8 +193,23 @@ module EffectiveTestBotFormFiller
|
|
193
193
|
save_test_bot_screenshot
|
194
194
|
end
|
195
195
|
|
196
|
-
if
|
197
|
-
|
196
|
+
if value == :unselect
|
197
|
+
return close_effective_select(field)
|
198
|
+
end
|
199
|
+
|
200
|
+
if field.all('option:enabled', wait: false).length == 0
|
201
|
+
return close_effective_select(field)
|
202
|
+
end
|
203
|
+
|
204
|
+
# Must be some options
|
205
|
+
Array(value).each do |value|
|
206
|
+
option = field.all("option:enabled[value=\"#{value}\"]", wait: false).first
|
207
|
+
option ||= field.all('option:enabled', wait: false).find { |field| field.text == value }
|
208
|
+
|
209
|
+
if option.present?
|
210
|
+
option.select_option
|
211
|
+
else
|
212
|
+
# This will most likely raise an error that it cant be found
|
198
213
|
field.select(value.to_s, match: :first, disabled: false)
|
199
214
|
end
|
200
215
|
end
|
@@ -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
|
@@ -57,7 +57,7 @@ module EffectiveTestBotTestHelper
|
|
57
57
|
|
58
58
|
# Calls capybara within do .. end if selector is present and bool is true
|
59
59
|
def within_if(selector, bool = true, &block)
|
60
|
-
(selector.
|
60
|
+
(all(selector).length > 0 && bool) ? within(first(selector)) { yield } : yield
|
61
61
|
end
|
62
62
|
|
63
63
|
def within_each(selector, &block)
|
@@ -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.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:
|
11
|
+
date: 2021-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|