Module: EffectiveTestBot
- Defined in:
- lib/effective_test_bot/middleware.rb,
lib/effective_test_bot.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: Generators
Classes: Engine, Middleware
Constant Summary
collapse
- VERSION =
'0.5.9'.freeze
Class Method Summary
collapse
Class Method Details
.autosave_animated_gif_on_failure? ⇒ Boolean
63
64
65
|
# File 'lib/effective_test_bot.rb', line 63
def self.autosave_animated_gif_on_failure?
screenshots? && autosave_animated_gif_on_failure
end
|
.excepts ⇒ Object
142
143
144
|
# File 'lib/effective_test_bot.rb', line 142
def self.excepts
@@excepts ||= flatten_and_sort(except)
end
|
.fail_fast? ⇒ Boolean
67
68
69
70
71
72
73
|
# File 'lib/effective_test_bot.rb', line 67
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
75
76
77
78
79
80
81
|
# File 'lib/effective_test_bot.rb', line 75
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’]
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/effective_test_bot.rb', line 160
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
|
.load_passed_tests ⇒ Object
112
113
114
115
116
|
# File 'lib/effective_test_bot.rb', line 112
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
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/effective_test_bot.rb', line 130
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
108
109
110
|
# File 'lib/effective_test_bot.rb', line 108
def self.passed_tests
@@passed_tests ||= load_passed_tests
end
|
.passed_tests_filename ⇒ Object
177
178
179
|
# File 'lib/effective_test_bot.rb', line 177
def self.passed_tests_filename
"#{passed_tests_path}/passed_tests.txt"
end
|
.passed_tests_path ⇒ Object
173
174
175
|
# File 'lib/effective_test_bot.rb', line 173
def self.passed_tests_path
"#{Rails.root}/tmp/test_bot"
end
|
.save_passed_test(name) ⇒ Object
118
119
120
121
122
123
124
125
126
|
# File 'lib/effective_test_bot.rb', line 118
def self.save_passed_test(name)
EffectiveTestBot.passed_tests[name] = true
Dir.mkdir(passed_tests_path) unless File.exists?(passed_tests_path)
File.open(passed_tests_filename, 'w') do |file|
passed_tests.each { |test_name, _| file.puts(test_name) }
end
end
|
.screenshots? ⇒ Boolean
If you call rake test:bot TOUR=false, then disable screenshots too
59
60
61
|
# File 'lib/effective_test_bot.rb', line 59
def self.screenshots?
screenshots == true
end
|
.setup {|_self| ... } ⇒ Object
20
21
22
|
# File 'lib/effective_test_bot.rb', line 20
def self.setup
yield self
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
27
28
29
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
|
# File 'lib/effective_test_bot.rb', line 27
def self.skip?(test, assertion = nil)
return false if (test || assertion).blank?
test = test.to_s
assertion = assertion.to_s
if test.include?('_test: (') 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 test_prefix = test.split('#').first
return true if excepts.any? { |except| [test, test_prefix, assertion, value].include?(except) }
return true if onlies.present? && onlies.find { |only| test.start_with?(only) }.blank?
false end
|
.tour_mode? ⇒ Boolean
83
84
85
86
87
88
89
|
# File 'lib/effective_test_bot.rb', line 83
def self.tour_mode?
if ENV['TOUR'].present?
['true', 'verbose', 'debug'].include?(ENV['TOUR'].to_s.downcase)
else
screenshots? && (tour_mode != false)
end
end
|
.tour_mode_extreme? ⇒ Boolean
form_filler will take a screenshot after every form field is filled
92
93
94
95
96
97
98
|
# File 'lib/effective_test_bot.rb', line 92
def self.tour_mode_extreme?
if ENV['TOUR'].present?
['extreme', 'debug'].include?(ENV['TOUR'].to_s.downcase)
else
screenshots? && ['extreme', 'debug'].include?(tour_mode.to_s)
end
end
|
.tour_mode_verbose? ⇒ Boolean
100
101
102
103
104
105
106
|
# File 'lib/effective_test_bot.rb', line 100
def self.tour_mode_verbose?
if ENV['TOUR'].present?
['extreme', 'verbose', 'debug'].include?(ENV['TOUR'].to_s.downcase)
else
screenshots? && ['extreme', 'verbose', 'debug'].include?(tour_mode.to_s)
end
end
|