effective_test_bot 1.2.0 → 1.2.5

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: e4b11fd2fb320e9749fb22973e5a83b3b66d40c4bc250f41c8e753f351b9ebf8
4
- data.tar.gz: d9f59e7a13b07a2c0584009ad587dd018ab3a1f44e7515e74ae62e2a80b4087e
3
+ metadata.gz: fd91036d4b959a1a59934248064b1c42b6bb6e9cf8558b6809b9621fc67aed76
4
+ data.tar.gz: e5bba54a9961847859d1e02963442d4065e75308336a97609eeb351ac9ab671c
5
5
  SHA512:
6
- metadata.gz: ae3c9fe2c536236be682607375c9767e8cb752764d24cc766a0d56f53b08dade662bbe6fb4ffc45622fcf4ec6fdded9434135306cbb2d8b208b1e1aa8f69fb1a
7
- data.tar.gz: ffef5bfd26a4708d87b328ebd9a9f5056c455a5380402c7825aa8f979bc8a1562a1ddfde1bcd1078fcc3a1615e0c2678a6e24c232f3a8335e2916f3d9fb7ec84
6
+ metadata.gz: 574c821e54abc360af9b1f4f11990b8db8f06685a5c25f096621e8933e34a77829134ae9e06eb5836b171d9ba90a34289e7718566986cdd254af7097b0a1f628
7
+ data.tar.gz: 6b3f2fd19df1a688cb2fb1bcfa79a2f7c3baf0a5832fdf80796cc1c7cec842314eb99ad03a64d922ce22f8a5d56795ff8f235d27d05675aa7b7988c9e811573d
@@ -3,6 +3,7 @@ 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
9
  mattr_accessor :passed_tests
@@ -1,3 +1,3 @@
1
1
  module EffectiveTestBot
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.2.5'.freeze
3
3
  end
@@ -1,4 +1,5 @@
1
1
  module EffectiveTestBotAssertions
2
+
2
3
  def assert_page_content(content, message: "(page_content) Expected page content :content: to be present")
3
4
  assert page.has_text?(/#{Regexp.escape(content)}/i, wait: 0), message.sub(':content:', content)
4
5
  end
@@ -210,35 +211,43 @@ module EffectiveTestBotAssertions
210
211
 
211
212
  def assert_no_email(&block)
212
213
  before = ActionMailer::Base.deliveries.map { |mail| {to: mail.to, subject: mail.subject} }
213
- yield
214
+ retval = yield
214
215
  after = ActionMailer::Base.deliveries.map { |mail| {to: mail.to, subject: mail.subject} }
215
216
 
216
217
  diff = (after - before)
217
218
 
218
219
  assert diff.blank?, "(assert_no_email) #{diff.length} unexpected emails delivered: #{diff}"
220
+ retval
219
221
  end
220
222
 
221
223
  # assert_effective_log { click_on('download.txt') }
222
- def assert_effective_log(status: nil)
224
+ def assert_effective_log(status: nil, &block)
223
225
  raise('EffectiveLogging is not defined') unless defined?(EffectiveLogging)
224
226
  raise('expected a block') unless block_given?
225
227
 
226
228
  logs = (status.present? ? Effective::Log.where(status: status).all : Effective::Log.all)
227
229
 
228
230
  before = logs.count
229
- yield
231
+ retval = yield
230
232
  after = logs.count
231
233
 
232
234
  assert (after - before == 1), "(assert_effective_log) Expected one log to have been created"
235
+ retval
233
236
  end
234
237
 
238
+ #include ActiveJob::TestHelper if defined?(ActiveJob::TestHelper)
239
+
235
240
  # assert_email :new_user_sign_up
236
241
  # assert_email :new_user_sign_up, to: 'newuser@example.com'
237
242
  # assert_email from: 'admin@example.com'
238
- def assert_email(action = nil, to: nil, from: nil, subject: nil, body: nil, message: nil, count: nil, &block)
243
+ def assert_email(action = nil, perform: nil, to: nil, from: nil, subject: nil, body: nil, message: nil, count: nil, &block)
244
+ retval = nil
245
+
239
246
  if block_given?
240
247
  before = ActionMailer::Base.deliveries.length
241
- yield
248
+ perform_enqueued_jobs if perform && respond_to?(:perform_enqueued_jobs)
249
+ retval = yield
250
+
242
251
  difference = (ActionMailer::Base.deliveries.length - before)
243
252
 
244
253
  if count.present?
@@ -246,11 +255,13 @@ module EffectiveTestBotAssertions
246
255
  else
247
256
  assert (difference > 0), "(assert_email) Expected at least one email to have been delivered"
248
257
  end
258
+ else
259
+ perform_enqueued_jobs if perform && respond_to?(:perform_enqueued_jobs)
249
260
  end
250
261
 
251
262
  if (action || to || from || subject || body).nil?
252
263
  assert ActionMailer::Base.deliveries.present?, message || "(assert_email) Expected email to have been delivered"
253
- return
264
+ return retval
254
265
  end
255
266
 
256
267
  actions = ActionMailer::Base.instance_variable_get(:@mailer_actions)
@@ -264,7 +275,7 @@ module EffectiveTestBotAssertions
264
275
  matches &&= (message.subject == subject) if subject
265
276
  matches &&= (message.body == body) if body
266
277
 
267
- return if matches
278
+ return retval if matches
268
279
  end
269
280
 
270
281
  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
- (fill_form_fields(fills) and return) unless tabs.length > 1
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 = {}, debug: false)
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
@@ -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
@@ -98,7 +110,7 @@ module EffectiveTestBotTestHelper
98
110
  end
99
111
 
100
112
  def current_user_assigns_class
101
- current_user_assigns_key.sub('current_').gsub('_', '::').classify.safe_constantize
113
+ current_user_assigns_key.sub('current_', '').gsub('_', '::').classify.safe_constantize
102
114
  end
103
115
 
104
116
  def access_denied_exception
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.2.0
4
+ version: 1.2.5
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-02-25 00:00:00.000000000 Z
11
+ date: 2021-03-29 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: