effective_test_bot 0.5.9 → 0.5.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/effective_test_bot.rb +1 -0
- data/lib/effective_test_bot/engine.rb +7 -2
- data/lib/effective_test_bot/version.rb +1 -1
- data/lib/generators/templates/effective_test_bot.rb +3 -0
- data/lib/generators/templates/test_helper.rb +40 -18
- data/test/test_bot/integration/application_test.rb +33 -7
- data/test/test_botable/base_test.rb +8 -4
- data/test/test_botable/wizard_test.rb +7 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d50c75e5319b53cbe8c1e2961a84e9869d33618f
|
4
|
+
data.tar.gz: 54f357016f40060d93dbda71279950c48949f1a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dbbb1b750b858eeec2e2a44e28ba0b64865200e7d2712d65ba97fc656dc634f56c46166034580755b39bf7c556e7eb1ddc07c3367abd95046549f126d71c249
|
7
|
+
data.tar.gz: 41ae170c048e453be9192bf90a307ea5b55e972341d968800775a5db3bcbd604449efe14504ea44678c5e05096c41d3b31869f3d503802d1dac7f53c2aeb1ab6
|
data/lib/effective_test_bot.rb
CHANGED
@@ -56,8 +56,13 @@ module EffectiveTestBot
|
|
56
56
|
if Rails.env.test?
|
57
57
|
ActionController::Base.send :include, ::EffectiveTestBotControllerHelper
|
58
58
|
|
59
|
-
ActionController::Base.
|
60
|
-
|
59
|
+
if ActionController::Base.respond_to?(:before_action)
|
60
|
+
ActionController::Base.send :before_action, :expires_now # Prevent 304 Not Modified caching
|
61
|
+
ActionController::Base.send :after_action, :assign_test_bot_http_headers
|
62
|
+
else
|
63
|
+
ActionController::Base.send :before_filter, :expires_now # Prevent 304 Not Modified caching
|
64
|
+
ActionController::Base.send :after_filter, :assign_test_bot_http_headers
|
65
|
+
end
|
61
66
|
|
62
67
|
ApplicationController.instance_exec do
|
63
68
|
rescue_from ActionController::UnpermittedParameters do |exception|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
ENV['RAILS_ENV'] = 'test'
|
2
|
-
require File.expand_path(
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
3
3
|
require 'rails/test_help'
|
4
4
|
require 'minitest/rails'
|
5
5
|
require 'minitest/rails/capybara'
|
@@ -13,6 +13,8 @@ require 'capybara/webkit'
|
|
13
13
|
require 'capybara-screenshot/minitest'
|
14
14
|
require 'capybara/slow_finder_errors'
|
15
15
|
|
16
|
+
require 'database_cleaner'
|
17
|
+
|
16
18
|
class ActiveSupport::TestCase
|
17
19
|
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
|
18
20
|
fixtures :all
|
@@ -26,8 +28,15 @@ class ActionDispatch::IntegrationTest
|
|
26
28
|
include Capybara::Screenshot::MiniTestPlugin
|
27
29
|
include Warden::Test::Helpers if defined?(Devise)
|
28
30
|
|
29
|
-
def
|
30
|
-
super()
|
31
|
+
def after_setup
|
32
|
+
super()
|
33
|
+
DatabaseCleaner.start
|
34
|
+
end
|
35
|
+
|
36
|
+
def after_teardown
|
37
|
+
super()
|
38
|
+
DatabaseCleaner.clean
|
39
|
+
Capybara.reset_sessions! # Some apps seem to need this to correctly reset the test_06:_capybara_can_sign_in
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
@@ -44,16 +53,19 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
|
44
53
|
Rails.backtrace_cleaner.remove_silencers!
|
45
54
|
Rails.backtrace_cleaner.add_silencer { |line| line =~ /minitest/ }
|
46
55
|
|
56
|
+
###############################################
|
47
57
|
### Effective Test Bot specific stuff below ###
|
58
|
+
###############################################
|
48
59
|
|
49
|
-
# So the very first thing
|
50
|
-
|
51
|
-
|
52
|
-
end
|
60
|
+
# So the very first thing we do is consistently reset the database.
|
61
|
+
# This can be done with Snippet 1 or Snippet 2.
|
62
|
+
# Snippet 1 is faster, and will usually work. Snippet 2 should always work.
|
53
63
|
|
64
|
+
# Snippet 1:
|
65
|
+
silence_stream(STDOUT) { Rake::Task['db:schema:load'].invoke }
|
54
66
|
ActiveRecord::Migration.maintain_test_schema!
|
55
67
|
|
56
|
-
#
|
68
|
+
# Snippet 2:
|
57
69
|
|
58
70
|
# silence_stream(STDOUT) do
|
59
71
|
# Rake::Task['db:drop'].invoke
|
@@ -61,6 +73,7 @@ ActiveRecord::Migration.maintain_test_schema!
|
|
61
73
|
# Rake::Task['db:migrate'].invoke
|
62
74
|
# end
|
63
75
|
|
76
|
+
# Now we populate our test data:
|
64
77
|
Rake::Task['db:fixtures:load'].invoke # There's just no way to get the seeds first, as this has to delete everything
|
65
78
|
Rake::Task['db:seed'].invoke
|
66
79
|
Rake::Task['test:load_fixture_seeds'].invoke # This is included by effective_test_bot. It just runs the app's test/fixtures/seeds.rb if it exists
|
@@ -69,14 +82,23 @@ if EffectiveTestBot.fail_fast?
|
|
69
82
|
require 'minitest/fail_fast'
|
70
83
|
end
|
71
84
|
|
72
|
-
#
|
73
|
-
#
|
74
|
-
|
75
|
-
|
76
|
-
@@shared_connection = nil
|
85
|
+
# "Connection not rolling back" snippets
|
86
|
+
# These are some snippets that the internet has collected to fix test threading issues.
|
87
|
+
# They are unneeded with effective_test_bot. On my machine. But I leave them here as a reference.
|
88
|
+
# Try one or both if you are having issues passing rake test:bot:environment
|
77
89
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
90
|
+
# class ActiveRecord::Base
|
91
|
+
# mattr_accessor :shared_connection
|
92
|
+
# @@shared_connection = nil
|
93
|
+
|
94
|
+
# def self.connection
|
95
|
+
# @@shared_connection || retrieve_connection
|
96
|
+
# end
|
97
|
+
# end
|
98
|
+
# ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
|
99
|
+
|
100
|
+
# ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
|
101
|
+
# def current_connection_id
|
102
|
+
# Thread.main.object_id
|
103
|
+
# end
|
104
|
+
# end
|
@@ -21,14 +21,14 @@ module TestBot
|
|
21
21
|
action = route.defaults[:action]
|
22
22
|
|
23
23
|
# Devise Test
|
24
|
-
if
|
24
|
+
if is_devise_controller?(route)
|
25
25
|
next if seen_actions['devise'].present?
|
26
26
|
seen_actions['devise'] = true # So we don't repeat it
|
27
27
|
|
28
28
|
devise_test()
|
29
29
|
|
30
30
|
# Redirect Test
|
31
|
-
elsif
|
31
|
+
elsif is_redirect?(route)
|
32
32
|
path = route.path.spec.to_s
|
33
33
|
route.path.optional_names.each { |name| path.sub!("(.:#{name})", '') } # Removes (.:format) from path
|
34
34
|
redirect_test(from: path, to: route.app.path([], nil))
|
@@ -54,19 +54,23 @@ module TestBot
|
|
54
54
|
|
55
55
|
# Wizard Test
|
56
56
|
elsif is_wicked_controller?(route)
|
57
|
-
|
58
|
-
|
57
|
+
next if seen_actions[controller].present?
|
58
|
+
seen_actions[controller] = true # So we don't repeat it
|
59
|
+
|
60
|
+
wizard_test(from: "#{route.name}_path".to_sym, step: controller_instance(route).wizard_steps.first)
|
59
61
|
|
60
62
|
# Member Test
|
61
|
-
elsif
|
63
|
+
elsif is_member?(route)
|
62
64
|
member_test(controller: controller, action: action)
|
63
65
|
|
64
66
|
# Page Test
|
65
|
-
elsif
|
67
|
+
elsif is_page?(route)
|
66
68
|
page_test(path: "#{route.name}_path".to_sym, route: route, label: "#{route.name}_path")
|
67
69
|
|
68
70
|
else
|
69
|
-
|
71
|
+
unless EffectiveTestBot.silence_skipped_routes
|
72
|
+
puts "skipping #{route.name}_path | #{route.path.spec} | #{route.verb} | #{route.defaults[:controller]} | #{route.defaults[:action]}"
|
73
|
+
end
|
70
74
|
|
71
75
|
end # / Routes
|
72
76
|
end
|
@@ -74,6 +78,17 @@ module TestBot
|
|
74
78
|
|
75
79
|
protected
|
76
80
|
|
81
|
+
def is_devise_controller?(route)
|
82
|
+
return true if (route.defaults[:controller] || '').include?('devise')
|
83
|
+
|
84
|
+
controller = controller_instance(route)
|
85
|
+
controller.respond_to?(:devise_controller?) && controller.devise_controller?
|
86
|
+
end
|
87
|
+
|
88
|
+
def is_redirect?(route)
|
89
|
+
route.app.kind_of?(ActionDispatch::Routing::PathRedirect) && route.path.required_names.blank?
|
90
|
+
end
|
91
|
+
|
77
92
|
def is_crud_controller?(route)
|
78
93
|
return false unless CRUD_ACTIONS.include?(route.defaults[:action])
|
79
94
|
|
@@ -85,6 +100,9 @@ module TestBot
|
|
85
100
|
def is_wicked_controller?(route)
|
86
101
|
return false unless defined?(Wicked::Wizard)
|
87
102
|
|
103
|
+
# This might be a wickeds controller, but it's a nested one, so we can't handle it anyway
|
104
|
+
return false unless route.path.required_names == ['id']
|
105
|
+
|
88
106
|
controller = controller_instance(route)
|
89
107
|
return false unless controller.kind_of?(Wicked::Wizard)
|
90
108
|
|
@@ -95,6 +113,14 @@ module TestBot
|
|
95
113
|
controller.wizard_steps.present?
|
96
114
|
end
|
97
115
|
|
116
|
+
def is_member?(route)
|
117
|
+
route.verb.to_s.include?('GET') && route.path.required_names == ['id']
|
118
|
+
end
|
119
|
+
|
120
|
+
def is_page?(route)
|
121
|
+
route.verb.to_s.include?('GET') && route.name.present? && Array(route.path.required_names).blank? # This could eventually be removed to supported nested routes
|
122
|
+
end
|
123
|
+
|
98
124
|
private
|
99
125
|
|
100
126
|
def controller_instance(route)
|
@@ -93,18 +93,22 @@ module BaseTest
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def resources_path # index, create
|
96
|
-
polymorphic_path([*controller_namespace, resource_class])
|
96
|
+
path = polymorphic_path([*controller_namespace, resource_class]) rescue nil
|
97
|
+
path || polymorphic_path([*controller_namespace.try(:singularize), resource_class])
|
97
98
|
end
|
98
99
|
|
99
100
|
def resource_path(resource) # show, update, destroy
|
100
|
-
polymorphic_path([*controller_namespace, resource])
|
101
|
+
path = polymorphic_path([*controller_namespace, resource]) rescue nil
|
102
|
+
path || polymorphic_path([*controller_namespace.try(:singularize), resource])
|
101
103
|
end
|
102
104
|
|
103
105
|
def new_resource_path # new
|
104
|
-
new_polymorphic_path([*controller_namespace, resource_class])
|
106
|
+
path = new_polymorphic_path([*controller_namespace, resource_class]) rescue nil
|
107
|
+
path || new_polymorphic_path([*controller_namespace.try(:singularize), resource_class])
|
105
108
|
end
|
106
109
|
|
107
110
|
def edit_resource_path(resource) # edit
|
108
|
-
edit_polymorphic_path([*controller_namespace, resource])
|
111
|
+
path = edit_polymorphic_path([*controller_namespace, resource]) rescue nil
|
112
|
+
path || edit_polymorphic_path([*controller_namespace.try(:singularize), resource])
|
109
113
|
end
|
110
114
|
end
|
@@ -5,7 +5,13 @@ module WizardTest
|
|
5
5
|
protected
|
6
6
|
|
7
7
|
def test_bot_wizard_test(&block)
|
8
|
-
sign_in(user)
|
8
|
+
sign_in(user)
|
9
|
+
|
10
|
+
if from.kind_of?(Symbol) && defined?(step)
|
11
|
+
visit(public_send(from, id: step))
|
12
|
+
else
|
13
|
+
visit(from)
|
14
|
+
end
|
9
15
|
|
10
16
|
0.upto(50) do |index| # Can only test wizards 51 steps long
|
11
17
|
assert_page_normal
|
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.
|
4
|
+
version: 0.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: 2016-
|
11
|
+
date: 2016-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: database_cleaner
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: shoulda
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -285,7 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
285
299
|
version: '0'
|
286
300
|
requirements: []
|
287
301
|
rubyforge_project:
|
288
|
-
rubygems_version: 2.
|
302
|
+
rubygems_version: 2.5.1
|
289
303
|
signing_key:
|
290
304
|
specification_version: 4
|
291
305
|
summary: A shared library of rails model & capybara-based feature tests that should
|