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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48c18bd23b31a9fbc1ea45a86275fffe86d1ed4178d6b639fab958de45092b0a
4
- data.tar.gz: 184a735e80bfa2e483236fae17f04d62be01e3e5ca0303eb7c5effcce59b0245
3
+ metadata.gz: e4b11fd2fb320e9749fb22973e5a83b3b66d40c4bc250f41c8e753f351b9ebf8
4
+ data.tar.gz: d9f59e7a13b07a2c0584009ad587dd018ab3a1f44e7515e74ae62e2a80b4087e
5
5
  SHA512:
6
- metadata.gz: a28cb45fb1f5b3be46bb380aba5ade362d0376d8495a0b10467cac6a0cb728c27f68a0066cd45df94b3757f630be3853f71da7c7c6497094f23c2c385af0104f
7
- data.tar.gz: b7bc9f3512a1fcadcc7170b5a08b2bae79fe948091bffe84f03991f60dbf1321d615b30f3759d344c94e8184482a17104722ad555be5b751ae7d7352121c8e73
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.delete_if { |_, v| v.blank? } if object.errors.present?
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.delete_if { |_, v| v.blank? } if object.errors.present?
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
@@ -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 :user
9
- mattr_accessor :except
10
- mattr_accessor :only
11
- mattr_accessor :fail_fast
12
- mattr_accessor :form_fills
13
- mattr_accessor :screenshots
14
- mattr_accessor :autosave_animated_gif_on_failure
15
- mattr_accessor :tour_mode
16
- mattr_accessor :tour_mode_extreme
17
- mattr_accessor :animated_gif_delay
18
- mattr_accessor :animated_gif_background_color
19
- mattr_accessor :image_processing_class_name
20
- mattr_accessor :backtrace_lines
21
- mattr_accessor :silence_skipped_routes
22
-
23
- mattr_accessor :passed_tests # This isn't a config variable.
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,3 +1,3 @@
1
1
  module EffectiveTestBot
2
- VERSION = '1.1.32'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
@@ -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
- assert assigns['current_user'].present?, message
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['current_user'].blank?, message
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
- after = ActionMailer::Base.deliveries.length
242
+ difference = (ActionMailer::Base.deliveries.length - before)
228
243
 
229
- assert (after - before == 1), "(assert_email) Expected one email to have been delivered"
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
- within('div' + tab_href) { fill_form_fields(fills) }
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 field.all('option:enabled', wait: false).length > 0 && value != :unselect
197
- Array(value).each do |value|
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(User.find_by_email!(user))
14
- elsif user.kind_of?(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
- login_as(user)
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#new_user') do
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#new_user') do
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
- User.find_by_email(email)
53
+ devise_user_class.find_by_email(email)
52
54
  end
53
55
 
54
56
  def current_user
55
- User.where(id: assigns['current_user']['id']).first if (assigns['current_user'] && assigns['current_user']['id'])
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.present? && bool) ? within(first(selector)) { yield } : yield
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.1.32
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: 2020-12-17 00:00:00.000000000 Z
11
+ date: 2021-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails