effective_test_bot 0.5.10 → 0.5.11

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
  SHA1:
3
- metadata.gz: d50c75e5319b53cbe8c1e2961a84e9869d33618f
4
- data.tar.gz: 54f357016f40060d93dbda71279950c48949f1a4
3
+ metadata.gz: e716315d415bfb20ba64a443552660e343a2de2e
4
+ data.tar.gz: 42ffbf4212b65bcd964affd294ca9fb5d8eb37ae
5
5
  SHA512:
6
- metadata.gz: 5dbbb1b750b858eeec2e2a44e28ba0b64865200e7d2712d65ba97fc656dc634f56c46166034580755b39bf7c556e7eb1ddc07c3367abd95046549f126d71c249
7
- data.tar.gz: 41ae170c048e453be9192bf90a307ea5b55e972341d968800775a5db3bcbd604449efe14504ea44678c5e05096c41d3b31869f3d503802d1dac7f53c2aeb1ab6
6
+ metadata.gz: 15909967a589dbfde8b12a5e7f7075d8433bb4c92833e603438835f8961f96bd3b09889e565aa1eda32cc56fff65bdfe98ae708cbdd8f22306d03d22fb9a7a1d
7
+ data.tar.gz: f269d0c2095a982c2a4549dfa212b7669f010d61e0611aa6ab3c172b63ce6cc1ee85c427cc6e2238ca9de4af97700d8a78a87e5e08d846b6ee817e8474a42630
data/README.md CHANGED
@@ -107,6 +107,7 @@ The following assertions are added for use in any integration test:
107
107
  - `assert_assigns_errors` use after an intentionally invalid form submit to make sure your assigned rails object has errors, or a specific error.
108
108
  - `assert_no_assigns_errors` should be used after any form submit to make sure your assigned rails object has no errors. Prints out any errors if they exist.
109
109
  - `assert_current_path(path)` asserts the current page path.
110
+ - `assert_email(action)` asserts an email with the given action name was sent. Also supports `assert_email(to: email)` type syntax with to, from, subject, body.
110
111
  - `assert_flash`, optionally with the desired `:success`, `:error` key and/or message, makes sure the flash is set.
111
112
  - `assert_jquery_ujs_disable_with` makes sure all `input[type=submit]` elements on the page have the `data-disable-with` property set.
112
113
  - `assert_no_exceptions` checks for any exceptions in the last page request and gives a stacktrace if there was.
@@ -0,0 +1,8 @@
1
+ module EffectiveTestBotMailerHelper
2
+ # This is included to ActionMailer::Base an after_filter
3
+ # And allows the assert_email assertion to work
4
+ def assign_test_bot_mailer_info
5
+ message.instance_variable_set(:@mailer_class, self.class)
6
+ message.instance_variable_set(:@mailer_action, action_name)
7
+ end
8
+ end
@@ -51,9 +51,23 @@ module EffectiveTestBot
51
51
  end
52
52
  end
53
53
 
54
+ initializer 'effective_test_bot.email_logger' do |app|
55
+ if Rails.env.test?
56
+ ActiveSupport.on_load :action_mailer do
57
+ ActionMailer::Base.send :include, ::EffectiveTestBotMailerHelper
58
+
59
+ if ActionMailer::Base.respond_to?(:after_action)
60
+ ActionMailer::Base.send :after_action, :assign_test_bot_mailer_info
61
+ else
62
+ ActionMailer::Base.send :after_filter, :assign_test_bot_mailer_info
63
+ end
64
+ end
65
+ end
66
+ end
67
+
54
68
  initializer 'effective_test_bot.assign_assign_headers' do
55
- ActiveSupport.on_load :action_controller do
56
- if Rails.env.test?
69
+ if Rails.env.test?
70
+ ActiveSupport.on_load :action_controller do
57
71
  ActionController::Base.send :include, ::EffectiveTestBotControllerHelper
58
72
 
59
73
  if ActionController::Base.respond_to?(:before_action)
@@ -1,3 +1,3 @@
1
1
  module EffectiveTestBot
2
- VERSION = '0.5.10'.freeze
2
+ VERSION = '0.5.11'.freeze
3
3
  end
@@ -13,22 +13,6 @@ module EffectiveTestBot
13
13
  run 'bundle exec rails generate minitest:install'
14
14
  end
15
15
 
16
- def explain_overwrite
17
- puts '[effective_test_bot] Successfully installed/detected: minitest'
18
- puts ""
19
- puts 'Starting effective_test_bot specific installation tasks:'
20
- puts ""
21
- puts "You will be prompted to overwrite the default minitest configuration"
22
- puts "files with those packaged inside the effective_test_bot gem."
23
- puts ""
24
- puts "If you have very specific existing minitest configuration,"
25
- puts "you should ensure it's under version control so you can revert if needed"
26
- puts ""
27
- puts "Otherwise, press 'Y' to all the following prompts to automatically configure"
28
- puts "minitest-rails and capybara-webkit based effective_test_bot test coverage"
29
- puts ""
30
- end
31
-
32
16
  def copy_initializer
33
17
  template "effective_test_bot.rb", "config/initializers/effective_test_bot.rb"
34
18
  end
@@ -49,9 +49,10 @@ Capybara::Webkit.configure { |config| config.allow_unknown_urls }
49
49
 
50
50
  Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
51
51
 
52
- # These two lines are needed as of minitest-reporters 1.1.2
52
+ # These three lines are needed as of minitest-reporters 1.1.2
53
53
  Rails.backtrace_cleaner.remove_silencers!
54
54
  Rails.backtrace_cleaner.add_silencer { |line| line =~ /minitest/ }
55
+ Rails.backtrace_cleaner.add_silencer { |line| line =~ /effective_test_bot/ }
55
56
 
56
57
  ###############################################
57
58
  ### Effective Test Bot specific stuff below ###
@@ -161,4 +161,37 @@ module EffectiveTestBotAssertions
161
161
  assert errors.present?, message || "(assigns_errors) Expected @#{key}.errors to be present"
162
162
  end
163
163
 
164
+ # assert_email :new_user_sign_up
165
+ # assert_email :new_user_sign_up, to: 'newuser@example.com'
166
+ # assert_email from: 'admin@example.com'
167
+ def assert_email(action = nil, to: nil, from: nil, subject: nil, body: nil, message: nil)
168
+
169
+ if (action || to || from || subject || body).nil?
170
+ assert ActionMailer::Base.deliveries.present?, message || "(assert_email) Expected email to have been delivered"
171
+ return
172
+ end
173
+
174
+ ActionMailer::Base.deliveries.each do |message|
175
+ matches = true
176
+
177
+ matches &&= (message.instance_variable_get(:@mailer_action) == action.to_s) if action
178
+ matches &&= (Array(message.to).include?(to)) if to
179
+ matches &&= (Array(message.from).include?(from)) if from
180
+ matches &&= (message.subject == subject) if subject
181
+ matches &&= (message.body == body) if body
182
+
183
+ return if matches
184
+ end
185
+
186
+ expected = [
187
+ ("action: #{action}" if action),
188
+ ("to: #{to}" if to),
189
+ ("from: {from}" if from),
190
+ ("subject: #{subject}" if subject),
191
+ ("body: #{body}" if body),
192
+ ].compact.to_sentence
193
+
194
+ assert false, message || "(assert_email) Expected email with #{expected} to have been delivered"
195
+ end
196
+
164
197
  end
@@ -253,7 +253,7 @@ module EffectiveTestBotFormFiller
253
253
  elsif fill_value.present?
254
254
  fill_values = Array(fill_value) # Allow an array of fill values to be passed
255
255
  (fill_values.include?(field['value']) || fill_values.include?(field.find(:xpath, '..').text))
256
- elsif field['required'].present?
256
+ elsif field['required'].nil? == false
257
257
  true
258
258
  elsif field['value'] == 'true'
259
259
  true
@@ -333,11 +333,30 @@ module EffectiveTestBotFormFiller
333
333
  def upload_effective_asset(field, file)
334
334
  uid = field['id']
335
335
 
336
- begin
337
- field.set(file)
338
- rescue Capybara::Webkit::ClickFailed
339
- puts "file upload failed to click #{uid}"
340
- return
336
+ # In some apps, capybara can field.set(file) and it will will just work
337
+ # Sometimes we need to fallback to javascript to get a file uploaded
338
+ unless ((field.set(file) || true) rescue false)
339
+ files = Array(file)
340
+ uid = field['id']
341
+
342
+ js = "fileList = Array();"
343
+
344
+ files.each_with_index do |file, i|
345
+ # Generate a fake input selector
346
+ page.execute_script("if($('#effectiveAssetsPlaceholder#{i}').length == 0) {effectiveAssetsPlaceholder#{i} = window.$('<input/>').attr({id: 'effectiveAssetsPlaceholder#{i}', type: 'file'}).appendTo('body'); }")
347
+
348
+ # Attach file to the fake input selector through Capybara
349
+ page.document.attach_file("effectiveAssetsPlaceholder#{i}", files[i])
350
+
351
+ # Build up the fake js event
352
+ js = "#{js} fileList.push(effectiveAssetsPlaceholder#{i}.get(0).files[0]);"
353
+ end
354
+
355
+ # Trigger the fake drop event
356
+ page.execute_script("#{js} e = $.Event('drop'); e.originalEvent = {dataTransfer : { files : fileList } }; $('#s3_#{uid}').trigger(e);")
357
+
358
+ # Remove the file inputs we created
359
+ page.execute_script("$('input[id^=effectiveAssetsPlaceholder]').remove();")
341
360
  end
342
361
 
343
362
  # Wait till the Uploader bar goes away
@@ -13,6 +13,7 @@ module EffectiveTestBotLoginHelper
13
13
  login_as(User.find_by_email!(user))
14
14
  elsif user.kind_of?(User)
15
15
  raise 'user must be persisted' unless user.persisted?
16
+ user.reload
16
17
  login_as(user)
17
18
  elsif user == false
18
19
  true # Do nothing
@@ -39,11 +40,11 @@ module EffectiveTestBotLoginHelper
39
40
  end
40
41
  end
41
42
 
42
- def sign_up(email = Faker::Internet.email, password = Faker::Internet.password)
43
+ def sign_up(email: Faker::Internet.email, password: Faker::Internet.password, **options)
43
44
  visit new_user_registration_path
44
45
 
45
46
  within('form#new_user') do
46
- fill_form(email: email, password: password, password_confirmation: password)
47
+ fill_form({email: email, password: password, password_confirmation: password}.merge(options))
47
48
  submit_novalidate_form
48
49
  end
49
50
 
@@ -4,6 +4,12 @@ module EffectiveTestBotScreenshotsHelper
4
4
  include Magick
5
5
 
6
6
  # Creates a screenshot based on the current test and the order in this test.
7
+ def debug_test_bot_screenshot
8
+ filepath = "#{current_test_temp_path}/#{current_test_screenshot_id}.png"
9
+ page.save_screenshot(filepath)
10
+ puts filepath
11
+ end
12
+
7
13
  def save_test_bot_screenshot
8
14
  return unless EffectiveTestBot.screenshots?
9
15
  page.save_screenshot("#{current_test_temp_path}/#{current_test_screenshot_id}.png")
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: 0.5.10
4
+ version: 0.5.11
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: 2016-09-23 00:00:00.000000000 Z
11
+ date: 2016-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -246,6 +246,7 @@ files:
246
246
  - README.md
247
247
  - Rakefile
248
248
  - app/helpers/effective_test_bot_controller_helper.rb
249
+ - app/helpers/effective_test_bot_mailer_helper.rb
249
250
  - lib/effective_test_bot.rb
250
251
  - lib/effective_test_bot/engine.rb
251
252
  - lib/effective_test_bot/middleware.rb
@@ -299,7 +300,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
299
300
  version: '0'
300
301
  requirements: []
301
302
  rubyforge_project:
302
- rubygems_version: 2.5.1
303
+ rubygems_version: 2.4.5.1
303
304
  signing_key:
304
305
  specification_version: 4
305
306
  summary: A shared library of rails model & capybara-based feature tests that should