effective_test_bot 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/effective_test_bot.rb +43 -8
- data/lib/effective_test_bot/engine.rb +1 -0
- data/lib/effective_test_bot/version.rb +1 -1
- data/lib/generators/templates/effective_test_bot.rb +6 -1
- data/lib/tasks/effective_test_bot_tasks.rake +19 -0
- data/test/concerns/test_botable/base_dsl.rb +1 -1
- data/test/support/effective_test_bot_form_filler.rb +3 -10
- data/test/support/effective_test_bot_form_helper.rb +5 -6
- data/test/support/effective_test_bot_minitest_helper.rb +32 -0
- data/test/support/effective_test_bot_screenshots_helper.rb +5 -35
- data/test/test_bot/integration/application_test.rb +1 -3
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17d73d440defe13b300db9a9e3c40f2a53db6070
|
4
|
+
data.tar.gz: 500b99c205884123bf7b9ce81e62f824d246f9b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad2a4c20896abdd48fdee19c8667dbd56fe636912f71dc4dd53bcb973540bf6d57926ebe3db010a5b7e05fe58615395ccd875d736dc03fcdbd49b0f973373917
|
7
|
+
data.tar.gz: a5233b7717d68155472fe8abd6cce85bd4b1e1e5a26bb312f1aaa169d0d8599e62c628b0c43557244bc8780ee85d892482c9d7be7b287063ad8b22cdbee4a859
|
data/README.md
CHANGED
@@ -574,7 +574,7 @@ rake test:tour
|
|
574
574
|
rake test:tourv
|
575
575
|
```
|
576
576
|
|
577
|
-
### Fail
|
577
|
+
### Fail fast
|
578
578
|
|
579
579
|
Set `config.fail_fast = true` to exit immediately if there is a test failure.
|
580
580
|
|
@@ -586,6 +586,20 @@ rake test:bot FAILFAST=true
|
|
586
586
|
|
587
587
|
This functionality is provided thanks to [minitest-fail-fast](https://github.com/teoljungberg/minitest-fail-fast/)
|
588
588
|
|
589
|
+
### Failed tests only
|
590
|
+
|
591
|
+
Skip any previously passed tests by running the following:
|
592
|
+
|
593
|
+
```
|
594
|
+
rake test:bot:fails
|
595
|
+
```
|
596
|
+
|
597
|
+
or
|
598
|
+
|
599
|
+
```
|
600
|
+
rake test:bot FAILS=true
|
601
|
+
```
|
602
|
+
|
589
603
|
## License
|
590
604
|
|
591
605
|
MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
|
data/lib/effective_test_bot.rb
CHANGED
@@ -6,6 +6,7 @@ module EffectiveTestBot
|
|
6
6
|
mattr_accessor :except
|
7
7
|
mattr_accessor :only
|
8
8
|
mattr_accessor :fail_fast
|
9
|
+
mattr_accessor :form_fills
|
9
10
|
mattr_accessor :screenshots
|
10
11
|
mattr_accessor :autosave_animated_gif_on_failure
|
11
12
|
mattr_accessor :tour_mode
|
@@ -13,6 +14,8 @@ module EffectiveTestBot
|
|
13
14
|
mattr_accessor :animated_gif_delay
|
14
15
|
mattr_accessor :animated_gif_background_color
|
15
16
|
|
17
|
+
mattr_accessor :passed_tests # This isn't a config variable.
|
18
|
+
|
16
19
|
def self.setup
|
17
20
|
yield self
|
18
21
|
end
|
@@ -34,6 +37,10 @@ module EffectiveTestBot
|
|
34
37
|
test = test[(left+1)..(right-1)]
|
35
38
|
end
|
36
39
|
|
40
|
+
if failed_tests_only? && test.present? && passed_tests[test]
|
41
|
+
return true
|
42
|
+
end
|
43
|
+
|
37
44
|
value = "#{test} #{assertion}".strip # This is the format config.excepts is flattened into
|
38
45
|
test_prefix = test.split('#').first
|
39
46
|
|
@@ -53,16 +60,22 @@ module EffectiveTestBot
|
|
53
60
|
end
|
54
61
|
|
55
62
|
def self.autosave_animated_gif_on_failure?
|
56
|
-
screenshots && autosave_animated_gif_on_failure
|
63
|
+
screenshots? && autosave_animated_gif_on_failure
|
57
64
|
end
|
58
65
|
|
59
66
|
def self.fail_fast?
|
60
|
-
|
67
|
+
if (ENV['FAIL_FAST'] || ENV['FAILFAST']).present?
|
68
|
+
['true', '1'].include?((ENV['FAIL_FAST'] || ENV['FAILFAST']).to_s.downcase)
|
69
|
+
else
|
70
|
+
fail_fast == true
|
71
|
+
end
|
72
|
+
end
|
61
73
|
|
62
|
-
|
63
|
-
|
74
|
+
def self.failed_tests_only?
|
75
|
+
if (ENV['FAILS'] || ENV['FAIL']).present?
|
76
|
+
['true', '1'].include?((ENV['FAILS'] || ENV['FAIL']).to_s.downcase)
|
64
77
|
else
|
65
|
-
|
78
|
+
false
|
66
79
|
end
|
67
80
|
end
|
68
81
|
|
@@ -70,7 +83,7 @@ module EffectiveTestBot
|
|
70
83
|
if ENV['TOUR'].present?
|
71
84
|
['true', 'verbose', 'debug'].include?(ENV['TOUR'].to_s.downcase)
|
72
85
|
else
|
73
|
-
screenshots && (tour_mode != false)
|
86
|
+
screenshots? && (tour_mode != false)
|
74
87
|
end
|
75
88
|
end
|
76
89
|
|
@@ -79,7 +92,7 @@ module EffectiveTestBot
|
|
79
92
|
if ENV['TOUR'].present?
|
80
93
|
['extreme', 'debug'].include?(ENV['TOUR'].to_s.downcase)
|
81
94
|
else
|
82
|
-
screenshots && ['extreme', 'debug'].include?(tour_mode.to_s)
|
95
|
+
screenshots? && ['extreme', 'debug'].include?(tour_mode.to_s)
|
83
96
|
end
|
84
97
|
end
|
85
98
|
|
@@ -87,7 +100,25 @@ module EffectiveTestBot
|
|
87
100
|
if ENV['TOUR'].present?
|
88
101
|
['extreme', 'verbose', 'debug'].include?(ENV['TOUR'].to_s.downcase)
|
89
102
|
else
|
90
|
-
screenshots && ['extreme', 'verbose', 'debug'].include?(tour_mode.to_s)
|
103
|
+
screenshots? && ['extreme', 'verbose', 'debug'].include?(tour_mode.to_s)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.passed_tests
|
108
|
+
@@passed_tests ||= load_passed_tests
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.load_passed_tests
|
112
|
+
{}.tap do |tests|
|
113
|
+
(File.readlines(passed_tests_filename).each { |line| tests[line.chomp] = true } rescue nil)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.save_passed_test(name)
|
118
|
+
EffectiveTestBot.passed_tests[name] = true
|
119
|
+
|
120
|
+
File.open(passed_tests_filename, 'w') do |file|
|
121
|
+
passed_tests.each { |test_name, _| file.puts(test_name) }
|
91
122
|
end
|
92
123
|
end
|
93
124
|
|
@@ -136,4 +167,8 @@ module EffectiveTestBot
|
|
136
167
|
end.compact.sort
|
137
168
|
end
|
138
169
|
|
170
|
+
def self.passed_tests_filename
|
171
|
+
"#{Rails.root}/tmp/test_bot/passed_tests.txt"
|
172
|
+
end
|
173
|
+
|
139
174
|
end
|
@@ -20,6 +20,7 @@ module EffectiveTestBot
|
|
20
20
|
ActionDispatch::IntegrationTest.include EffectiveTestBotFormHelper
|
21
21
|
ActionDispatch::IntegrationTest.include EffectiveTestBotFormFiller
|
22
22
|
ActionDispatch::IntegrationTest.include EffectiveTestBotLoginHelper
|
23
|
+
ActionDispatch::IntegrationTest.include EffectiveTestBotMinitestHelper
|
23
24
|
ActionDispatch::IntegrationTest.include EffectiveTestBotScreenshotsHelper
|
24
25
|
ActionDispatch::IntegrationTest.include EffectiveTestBotTestHelper
|
25
26
|
|
@@ -20,6 +20,11 @@ if Rails.env.test?
|
|
20
20
|
# Exits immediately if there is a test failure
|
21
21
|
config.fail_fast = true
|
22
22
|
|
23
|
+
# Fill form fields with these values
|
24
|
+
# Based on the input name
|
25
|
+
# :email => 'somethign@soneone.com', 'user.last_name' => 'hlwerewr'
|
26
|
+
config.form_fills = {}
|
27
|
+
|
23
28
|
# Should capybara generate a series of *.png screenshots as it goes through the test?
|
24
29
|
# Disabling screenshots will also disable animated_gifs and touring
|
25
30
|
config.screenshots = true
|
@@ -33,7 +38,7 @@ if Rails.env.test?
|
|
33
38
|
# Also enabled the crud_test #tour type tests
|
34
39
|
#
|
35
40
|
# You can override this default by setting an ENV or calling
|
36
|
-
# `rake test:bot TOUR=true`
|
41
|
+
# `rake test:bot TOUR=true` or `rake test:bot TEST=posts TOUR=verbose`
|
37
42
|
#
|
38
43
|
# Valid values are true / false / :verbose
|
39
44
|
config.tour_mode = false
|
@@ -84,6 +84,25 @@ namespace :test do
|
|
84
84
|
|
85
85
|
puts 'No effective_test_bot tours present.' unless present
|
86
86
|
end
|
87
|
+
|
88
|
+
desc 'Runs effective_test_bot while skipping all previously passed tests'
|
89
|
+
task :fails do
|
90
|
+
ENV['FAILS'] ||= 'true'
|
91
|
+
Rake::Task['test:bot'].invoke
|
92
|
+
end
|
93
|
+
|
94
|
+
desc 'Runs effective_test_bot while skipping all previously passed tests'
|
95
|
+
task :fail do
|
96
|
+
ENV['FAILS'] ||= 'true'
|
97
|
+
Rake::Task['test:bot'].invoke
|
98
|
+
end
|
99
|
+
|
100
|
+
desc 'Runs effective_test_bot while skipping all previously passed tests'
|
101
|
+
task :failed do
|
102
|
+
ENV['FAILS'] ||= 'true'
|
103
|
+
Rake::Task['test:bot'].invoke
|
104
|
+
end
|
105
|
+
|
87
106
|
end # /namespace bot
|
88
107
|
|
89
108
|
desc 'loads test/fixtures/seeds.rb'
|
@@ -6,9 +6,7 @@ module EffectiveTestBotFormFiller
|
|
6
6
|
LETTERS = ('A'..'Z').to_a
|
7
7
|
|
8
8
|
# Fill a boostrap tabs based form
|
9
|
-
def fill_bootstrap_tabs_form(fills =
|
10
|
-
fills = HashWithIndifferentAccess.new(fills) unless fills.kind_of?(HashWithIndifferentAccess)
|
11
|
-
|
9
|
+
def fill_bootstrap_tabs_form(fills = {}, boostrap_tab_elements = nil)
|
12
10
|
tabs = boostrap_tab_elements || all("a[data-toggle='tab']")
|
13
11
|
|
14
12
|
# If there's only 1 tab, just fill it out
|
@@ -48,8 +46,7 @@ module EffectiveTestBotFormFiller
|
|
48
46
|
|
49
47
|
# Only fills in visible fields
|
50
48
|
# fill_form(:email => 'somethign@soneone.com', :password => 'blahblah', 'user.last_name' => 'hlwerewr')
|
51
|
-
def fill_form_fields(fills =
|
52
|
-
fills = HashWithIndifferentAccess.new(fills) unless fills.kind_of?(HashWithIndifferentAccess)
|
49
|
+
def fill_form_fields(fills = {})
|
53
50
|
|
54
51
|
save_test_bot_screenshot
|
55
52
|
|
@@ -118,7 +115,7 @@ module EffectiveTestBotFormFiller
|
|
118
115
|
#
|
119
116
|
# Operates on just string keys, no symbols here
|
120
117
|
|
121
|
-
def value_for_field(field, fills =
|
118
|
+
def value_for_field(field, fills = {})
|
122
119
|
field_name = [field.tag_name, field['type']].compact.join('_')
|
123
120
|
attributes = field['name'].to_s.gsub(']', '').split('[') # user[something_attributes][last_name] => ['user', 'something_attributes', 'last_name']
|
124
121
|
attribute = attributes.last.to_s
|
@@ -138,16 +135,12 @@ module EffectiveTestBotFormFiller
|
|
138
135
|
if classes.include?('date') # Let's assume this is a date input.
|
139
136
|
if attribute.include?('end') # Make sure end dates are after start dates
|
140
137
|
Faker::Date.forward(365).strftime('%Y-%m-%d')
|
141
|
-
elsif attribute.include?('closing')
|
142
|
-
Faker::Date.forward(30).strftime('%Y-%m-%d')
|
143
138
|
else
|
144
139
|
Faker::Date.backward(365).strftime('%Y-%m-%d')
|
145
140
|
end
|
146
141
|
elsif classes.include?('datetime')
|
147
142
|
if attribute.include?('end')
|
148
143
|
Faker::Date.forward(365).strftime('%Y-%m-%d %H:%m')
|
149
|
-
elsif attribute.include?('closing')
|
150
|
-
Faker::Date.forward(30).strftime('%Y-%m-%d %H:%m')
|
151
144
|
else
|
152
145
|
Faker::Date.backward(365).strftime('%Y-%m-%d %H:%m')
|
153
146
|
end
|
@@ -3,16 +3,15 @@ require 'timeout'
|
|
3
3
|
module EffectiveTestBotFormHelper
|
4
4
|
# Intelligently fills a form with Faker based randomish input
|
5
5
|
# Delegates the form fill logic to effective_test_bot_form_filler
|
6
|
-
def fill_form(
|
7
|
-
# The fills here are from a let!(:fills) { 'Something' } as defined in an _action test
|
8
|
-
fill_values = ((fills if defined?(fills)) || HashWithIndifferentAccess.new).merge(local_fills)
|
9
|
-
|
6
|
+
def fill_form(fills = {})
|
10
7
|
bootstrap_tabs = all("a[data-toggle='tab']")
|
11
8
|
|
9
|
+
form_fills = HashWithIndifferentAccess.new((EffectiveTestBot.form_fills || {}).merge(fills || {}))
|
10
|
+
|
12
11
|
if bootstrap_tabs.length > 1
|
13
|
-
fill_bootstrap_tabs_form(
|
12
|
+
fill_bootstrap_tabs_form(form_fills, bootstrap_tabs)
|
14
13
|
else
|
15
|
-
fill_form_fields(
|
14
|
+
fill_form_fields(form_fills)
|
16
15
|
end
|
17
16
|
true
|
18
17
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module EffectiveTestBotMinitestHelper
|
2
|
+
# This is run before every test
|
3
|
+
# def before_setup
|
4
|
+
# end
|
5
|
+
|
6
|
+
# This gets called after every test. Minitest hook for plugin developers
|
7
|
+
def after_teardown
|
8
|
+
if EffectiveTestBot.screenshots? && (@test_bot_screenshot_id || 0) > 0
|
9
|
+
save_test_bot_failure_gif if !passed? && EffectiveTestBot.autosave_animated_gif_on_failure?
|
10
|
+
save_test_bot_tour_gif if passed? && EffectiveTestBot.tour_mode?
|
11
|
+
end
|
12
|
+
|
13
|
+
if passed? && !EffectiveTestBot.passed_tests[current_test_name]
|
14
|
+
EffectiveTestBot.save_passed_test(current_test_name)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def current_test_name
|
21
|
+
@_current_test_name ||= (
|
22
|
+
if defined?(current_test) # test_bot class level methods set this variable
|
23
|
+
current_test
|
24
|
+
elsif @NAME.present? # minitest sets this variable
|
25
|
+
@NAME
|
26
|
+
else
|
27
|
+
Time.now.strftime('%Y-%m-%d-%H-%M-%S') # fallback
|
28
|
+
end.to_s
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -9,23 +9,6 @@ module EffectiveTestBotScreenshotsHelper
|
|
9
9
|
page.save_screenshot("#{current_test_temp_path}/#{current_test_screenshot_id}.png")
|
10
10
|
end
|
11
11
|
|
12
|
-
# This is run before every test
|
13
|
-
# def before_setup
|
14
|
-
# end
|
15
|
-
|
16
|
-
# This gets called after every test. Minitest hook for plugin developers
|
17
|
-
def after_teardown
|
18
|
-
return unless EffectiveTestBot.screenshots? && (@test_bot_screenshot_id || 0) > 0
|
19
|
-
|
20
|
-
if !passed? && EffectiveTestBot.autosave_animated_gif_on_failure?
|
21
|
-
save_test_bot_failure_gif
|
22
|
-
end
|
23
|
-
|
24
|
-
if passed? && EffectiveTestBot.tour_mode?
|
25
|
-
save_test_bot_tour_gif
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
12
|
def save_test_bot_failure_gif
|
30
13
|
Dir.mkdir(current_test_failure_path) unless File.exists?(current_test_failure_path)
|
31
14
|
full_path = (current_test_failure_path + '/' + current_test_failure_filename)
|
@@ -53,7 +36,6 @@ module EffectiveTestBotScreenshotsHelper
|
|
53
36
|
protected
|
54
37
|
|
55
38
|
def save_test_bot_gif(full_path)
|
56
|
-
|
57
39
|
png_images = @test_bot_screenshot_id.times.map do |x|
|
58
40
|
current_test_temp_path + '/' + format_screenshot_id(x+1) + '.png'
|
59
41
|
end
|
@@ -90,13 +72,15 @@ module EffectiveTestBotScreenshotsHelper
|
|
90
72
|
animation.write(full_path)
|
91
73
|
end
|
92
74
|
|
75
|
+
private
|
76
|
+
|
93
77
|
# There are 3 different paths we're working with
|
94
78
|
# current_test_temp_path: contains individually numbered .png screenshots produced by capybara
|
95
79
|
# current_test_tour_path: destination for .gifs of passing tests
|
96
80
|
# current_test_failure_path: destination for .gifs of failing tests
|
97
81
|
|
98
82
|
def current_test_temp_path
|
99
|
-
@_current_test_temp_path ||= "#{Rails.root}/tmp/test_bot/#{current_test_name}"
|
83
|
+
@_current_test_temp_path ||= "#{Rails.root}/tmp/test_bot/#{current_test_name.parameterize}"
|
100
84
|
end
|
101
85
|
|
102
86
|
def current_test_failure_path
|
@@ -105,7 +89,7 @@ module EffectiveTestBotScreenshotsHelper
|
|
105
89
|
|
106
90
|
def current_test_failure_filename
|
107
91
|
# Match Capybara-screenshots format-ish
|
108
|
-
"#{current_test_name}_failure_#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.gif"
|
92
|
+
"#{current_test_name.parameterize}_failure_#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.gif"
|
109
93
|
end
|
110
94
|
|
111
95
|
# Where the tour animated gif ends up
|
@@ -114,23 +98,9 @@ module EffectiveTestBotScreenshotsHelper
|
|
114
98
|
end
|
115
99
|
|
116
100
|
def current_test_tour_filename
|
117
|
-
"#{current_test_name}.gif"
|
101
|
+
"#{current_test_name.parameterize}.gif"
|
118
102
|
end
|
119
103
|
|
120
|
-
def current_test_name
|
121
|
-
@_current_test_name ||= (
|
122
|
-
if defined?(current_test) # test_bot class level methods set this variable
|
123
|
-
current_test
|
124
|
-
elsif @NAME.present? # minitest sets this variable
|
125
|
-
@NAME
|
126
|
-
else
|
127
|
-
Time.now.strftime('%Y-%m-%d-%H-%M-%S') # fallback
|
128
|
-
end.to_s.parameterize
|
129
|
-
)
|
130
|
-
end
|
131
|
-
|
132
|
-
private
|
133
|
-
|
134
104
|
# Auto incrementing counter
|
135
105
|
# The very first screenshot will be 01.png (tmp/test_bot/posts#new/01.png)
|
136
106
|
def current_test_screenshot_id
|
@@ -11,8 +11,6 @@ module TestBot
|
|
11
11
|
|
12
12
|
# Go through every route, and run an appropriate test suite on it
|
13
13
|
def initialize_tests
|
14
|
-
puts 'test_bot scanning....'
|
15
|
-
|
16
14
|
@test_bot_user = User.first
|
17
15
|
|
18
16
|
routes = Rails.application.routes.routes.to_a
|
@@ -68,7 +66,7 @@ module TestBot
|
|
68
66
|
page_test(path: "#{route.name}_path".to_sym, route: route, label: "#{route.name}_path")
|
69
67
|
|
70
68
|
else
|
71
|
-
puts "skipping #{route.name}_path | #{route.path.spec} | #{route.verb} | #{route.defaults[:controller]} | #{route.defaults[:action]}"
|
69
|
+
#puts "skipping #{route.name}_path | #{route.path.spec} | #{route.verb} | #{route.defaults[:controller]} | #{route.defaults[:action]}"
|
72
70
|
|
73
71
|
end # / Routes
|
74
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_test_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
@@ -253,6 +253,7 @@ files:
|
|
253
253
|
- test/support/effective_test_bot_form_filler.rb
|
254
254
|
- test/support/effective_test_bot_form_helper.rb
|
255
255
|
- test/support/effective_test_bot_login_helper.rb
|
256
|
+
- test/support/effective_test_bot_minitest_helper.rb
|
256
257
|
- test/support/effective_test_bot_screenshots_helper.rb
|
257
258
|
- test/support/effective_test_bot_test_helper.rb
|
258
259
|
- test/test_bot/integration/application_test.rb
|