effective_test_bot 1.5.9 → 1.5.10

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: d7de769d60d59f161b3606b64719f254251dea7834310e440be28ea831263fa5
4
- data.tar.gz: 1979f907166f5a0b445e1498b50bd4476700db1f737b0dea7b92a6dad2277d76
3
+ metadata.gz: 5d6c35e391f98542191fd633aa5b1969e90657ceb2b5fe872e7735184c392a71
4
+ data.tar.gz: dcd72ecee5a4e73dfee52a068166010f54c1c30b96ca1305c88fbe824987d8ee
5
5
  SHA512:
6
- metadata.gz: '069bb7337b7bb695e4b98c849dc2a939dfe44e082a34ef9259b1b2b2ab50053f9b2fbb98b4190ed04ffc8d718c771c35396488753f02bee94f3e72d4d23d49b8'
7
- data.tar.gz: 762721642757acfdae3953a6de328a306fb798d445e03fcd76a4004fb02f28e67b771392ccf4646948f4d2ea8e1da7a9cbcba2204a24695057e1f2cb68eb6b9e
6
+ metadata.gz: 38f0da58d5f36f2e45121ddcdf1adbd8bd2f022eb9bec14311f5951b24f9bcddb21a54c33f64d789d3b3d02987d7cb140cde357302b4cf5c6501cb6f6c6260a0
7
+ data.tar.gz: 4b1adb6b0a0ce8408f40fb0090b7646099925f887b2c6e0910798bb8601123f5c8dd83d02534b60a2720bed76cd1bf6293e85aa42314389aadcf4c456081bb5f
@@ -1,3 +1,3 @@
1
1
  module EffectiveTestBot
2
- VERSION = '1.5.9'.freeze
2
+ VERSION = '1.5.10'.freeze
3
3
  end
@@ -253,13 +253,16 @@ module EffectiveTestBotAssertions
253
253
  # assert_email :new_user_sign_up
254
254
  # assert_email :new_user_sign_up, to: 'newuser@example.com'
255
255
  # assert_email from: 'admin@example.com'
256
- def assert_email(action = nil, perform: true, to: nil, from: nil, subject: nil, body: nil, message: nil, count: nil, &block)
256
+ def assert_email(action = nil, perform: true, to: nil, from: nil, subject: nil, body: nil, message: nil, count: nil, plain_layout: nil, html_layout: nil, &block)
257
257
  retval = nil
258
258
 
259
259
  # Clear the queue of any previous emails first
260
260
  if perform
261
261
  assert_email_perform_enqueued_jobs
262
262
  raise('expected empty mailer queue. unable to clear it.') unless (assert_email_perform_enqueued_jobs.to_i == 0)
263
+
264
+ ActionMailer::Base.deliveries.clear
265
+ raise('expected empty mailer deliveries. unable to clear it.') unless (ActionMailer::Base.deliveries.length.to_i == 0)
263
266
  end
264
267
 
265
268
  before = ActionMailer::Base.deliveries.length
@@ -277,7 +280,7 @@ module EffectiveTestBotAssertions
277
280
  end
278
281
  end
279
282
 
280
- if (action || to || from || subject || body).nil?
283
+ if (action || to || from || subject || body || plain_layout || html_layout).nil?
281
284
  assert ActionMailer::Base.deliveries.present?, message || "(assert_email) Expected email to have been delivered"
282
285
  return retval
283
286
  end
@@ -287,11 +290,23 @@ module EffectiveTestBotAssertions
287
290
  ActionMailer::Base.deliveries.each do |message|
288
291
  matches = true
289
292
 
293
+ html_body = message.parts.find { |part| part.content_type.start_with?('text/html') }.try(:body).to_s.presence
294
+ plain_body = message.parts.find { |part| part.content_type.start_with?('text/plain') }.try(:body).to_s.presence
295
+ message_body = message.body.to_s
296
+
290
297
  matches &&= (actions.include?(action.to_s)) if action
291
298
  matches &&= (Array(message.to).include?(to)) if to
292
299
  matches &&= (Array(message.from).include?(from)) if from
293
300
  matches &&= (message.subject == subject) if subject
294
- matches &&= (message.body == body) if body
301
+
302
+ if body && html_layout
303
+ matches &&= html_body.to_s.gsub("\r\n", '').gsub("\n", '').include?(">#{body}<")
304
+ elsif body
305
+ matches &&= (plain_body == body || message_body == body)
306
+ end
307
+
308
+ matches &&= (html_body.present? && html_body.include?('<meta')) if html_layout
309
+ matches &&= (html_body.blank? && plain_body.blank? && message_body.exclude?('<meta')) if plain_layout
295
310
 
296
311
  return retval if matches
297
312
  end
@@ -302,6 +317,8 @@ module EffectiveTestBotAssertions
302
317
  ("from: {from}" if from),
303
318
  ("subject: #{subject}" if subject),
304
319
  ("body: #{body}" if body),
320
+ ("an HTML layout" if html_layout),
321
+ ("no HTML layout" if plain_layout),
305
322
  ].compact.to_sentence
306
323
 
307
324
  assert false, message || "(assert_email) Expected email with #{expected} to have been delivered"
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.5.9
4
+ version: 1.5.10
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: 2024-05-07 00:00:00.000000000 Z
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails