Module: EffectiveTestBot
- Includes:
- EffectiveGem
- Defined in:
- lib/effective_test_bot/middleware.rb,
lib/effective_test_bot.rb,
lib/effective_test_bot/dsl.rb,
lib/effective_test_bot/engine.rb,
lib/effective_test_bot/version.rb,
lib/generators/effective_test_bot/install_generator.rb
Overview
Watch for any rails server exceptions and write the stacktrace to ./tmp/test_bot/exception.txt This file is checked for by assert_no_exceptions
Defined Under Namespace
Modules: DSL, Generators Classes: Engine, Middleware
Constant Summary collapse
- VERSION =
'1.5.14'.freeze
Class Method Summary collapse
- .autosave_animated_gif_on_failure? ⇒ Boolean
- .config_keys ⇒ Object
- .excepts ⇒ Object
- .fail_fast? ⇒ Boolean
- .failed_tests_only? ⇒ Boolean
-
.flatten_and_sort(skips) ⇒ Object
We need to flatten any Hashes into ‘users#create_invalid’ => [‘assert_path’, ‘assert_page_title’], into this [‘users#create_invalid assert_path’ ‘users#create_invalid assert_page_title’].
- .gifs? ⇒ Boolean
- .image_processing_class ⇒ Object
- .load_passed_tests ⇒ Object
- .onlies ⇒ Object
- .passed_tests ⇒ Object
- .passed_tests_filename ⇒ Object
- .passed_tests_path ⇒ Object
- .save_passed_test(name) ⇒ Object
-
.screenshots? ⇒ Boolean
If you call rake test:bot TOUR=false, then disable screenshots too.
-
.skip?(test, assertion = nil) ⇒ Boolean
Test could be something like “crud_test”, “crud_test (documents#new)”, “documents”, documents#new“ Assertion will be page_title, or flash.
- .tour_mode? ⇒ Boolean
-
.tour_mode_extreme? ⇒ Boolean
form_filler will take a screenshot after every form field is filled.
Class Method Details
.autosave_animated_gif_on_failure? ⇒ Boolean
74 75 76 |
# File 'lib/effective_test_bot.rb', line 74 def self.autosave_animated_gif_on_failure? autosave_animated_gif_on_failure && gifs? end |
.config_keys ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/effective_test_bot.rb', line 11 def self.config_keys [ :user, :except, :only, :fail_fast, :form_fills, :screenshots, :autosave_animated_gif_on_failure, :tour_mode, :tour_mode_extreme, :animated_gif_delay, :animated_gif_background_color, :image_processing_class_name, :backtrace_lines, :silence_skipped_routes ] end |
.excepts ⇒ Object
152 153 154 |
# File 'lib/effective_test_bot.rb', line 152 def self.excepts @@excepts ||= flatten_and_sort(except) end |
.fail_fast? ⇒ Boolean
78 79 80 81 82 83 84 |
# File 'lib/effective_test_bot.rb', line 78 def self.fail_fast? if (ENV['FAIL_FAST'] || ENV['FAILFAST']).present? ['true', '1'].include?((ENV['FAIL_FAST'] || ENV['FAILFAST']).to_s.downcase) else fail_fast == true end end |
.failed_tests_only? ⇒ Boolean
86 87 88 89 90 91 92 |
# File 'lib/effective_test_bot.rb', line 86 def self.failed_tests_only? if (ENV['FAILS'] || ENV['FAIL']).present? ['true', '1'].include?((ENV['FAILS'] || ENV['FAIL']).to_s.downcase) else false end end |
.flatten_and_sort(skips) ⇒ Object
We need to flatten any Hashes into
'users#create_invalid' => ['assert_path', 'assert_page_title'],
into this [‘users#create_invalid assert_path’ ‘users#create_invalid assert_page_title’]
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/effective_test_bot.rb', line 170 def self.flatten_and_sort(skips) Array(skips).flat_map do |skip| case skip when Symbol skip.to_s when Hash skip.keys.product(skip.values.flatten).map { |p| p.join(' ') } else skip end end.compact.sort end |
.gifs? ⇒ Boolean
66 67 68 |
# File 'lib/effective_test_bot.rb', line 66 def self.gifs? screenshots? && image_processing_class.present? end |
.image_processing_class ⇒ Object
70 71 72 |
# File 'lib/effective_test_bot.rb', line 70 def self.image_processing_class @@image_processing_class ||= image_processing_class_name.safe_constantize end |
.load_passed_tests ⇒ Object
115 116 117 118 119 |
# File 'lib/effective_test_bot.rb', line 115 def self.load_passed_tests {}.tap do |tests| (File.readlines(passed_tests_filename).each { |line| tests[line.chomp] = true } rescue nil) end end |
.onlies ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/effective_test_bot.rb', line 140 def self.onlies @@onlines ||= begin flatten_and_sort( if ENV['TEST_BOT_TEST'].present? ENV['TEST_BOT_TEST'].to_s.gsub('[', '').gsub(']', '').split(',').map { |str| str.strip } else only end ) end end |
.passed_tests ⇒ Object
111 112 113 |
# File 'lib/effective_test_bot.rb', line 111 def self.passed_tests @@passed_tests ||= load_passed_tests end |
.passed_tests_filename ⇒ Object
187 188 189 |
# File 'lib/effective_test_bot.rb', line 187 def self.passed_tests_filename "#{passed_tests_path}/passed_tests.txt" end |
.passed_tests_path ⇒ Object
183 184 185 |
# File 'lib/effective_test_bot.rb', line 183 def self.passed_tests_path "#{Rails.root}/tmp/test_bot" end |
.save_passed_test(name) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/effective_test_bot.rb', line 121 def self.save_passed_test(name) return if EffectiveTestBot.passed_tests[name] == true EffectiveTestBot.passed_tests[name] = true # Make test pass directory. These can inconsistently fail when doing parallel tests unless Dir.exist?("#{Rails.root}/tmp") (Dir.mkdir("#{Rails.root}/tmp") rescue false) end unless Dir.exist?("#{Rails.root}/tmp/test_bot") (Dir.mkdir("#{Rails.root}/tmp/test_bot") rescue false) end File.open(passed_tests_filename, 'a') { |file| file.puts(name) } end |
.screenshots? ⇒ Boolean
If you call rake test:bot TOUR=false, then disable screenshots too
62 63 64 |
# File 'lib/effective_test_bot.rb', line 62 def self.screenshots? screenshots == true end |
.skip?(test, assertion = nil) ⇒ Boolean
Test could be something like “crud_test”, “crud_test (documents#new)”, “documents”, documents#new“ Assertion will be page_title, or flash
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/effective_test_bot.rb', line 30 def self.skip?(test, assertion = nil) return false if (test || assertion).blank? test = test.to_s assertion = assertion.to_s # If I get passed a method_name, "crud_test: (posts#create_invalid)" extract the inner test name from it # I dunno why this is needed really, but it might help someone one day. if test.include?('_test: (') # This is how the BaseDsl test_bot_method_name formats the test names. left = test.index('(') || -1 right = test.rindex(')') || (test.length+1) test = test[(left+1)..(right-1)] end if failed_tests_only? && test.present? && passed_tests[test] return true end value = "#{test} #{assertion}".strip # This is the format config.excepts is flattened into test_prefix = test.split('#').first # Excepts are defined in the app's config/initializers/effective_test_bot.rb file return true if excepts.any? { |except| [test, test_prefix, assertion, value].include?(except) } # Onlies are defined in the same config file, or on the command like rake test:bot TEST=posts#new # It doesn't match just 'flash' or 'page_title' assertions return true if onlies.present? && onlies.find { |only| test.start_with?(only) }.blank? false # Don't skip this test end |
.tour_mode? ⇒ Boolean
94 95 96 97 98 99 100 |
# File 'lib/effective_test_bot.rb', line 94 def self.tour_mode? if ENV['TOUR'].present? ENV['TOUR'].to_s != 'false' else gifs? && (tour_mode != false) end end |
.tour_mode_extreme? ⇒ Boolean
form_filler will take a screenshot after every form field is filled
103 104 105 106 107 108 109 |
# File 'lib/effective_test_bot.rb', line 103 def self.tour_mode_extreme? if ENV['TOUR'].present? ['extreme', 'debug'].include?(ENV['TOUR'].to_s.downcase) else gifs? && ['extreme', 'debug'].include?(tour_mode.to_s) end end |