effective_test_bot 0.3.0 → 0.4.0
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/lib/effective_test_bot/version.rb +1 -1
- data/lib/generators/templates/test_helper.rb +1 -0
- data/test/concerns/test_botable/crud_test.rb +17 -7
- data/test/support/effective_test_bot_assertions.rb +7 -7
- data/test/support/effective_test_bot_form_helper.rb +5 -3
- data/test/support/effective_test_bot_test_helper.rb +2 -2
- data/test/test_botable/crud_test.rb +33 -27
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8daba6efe86cb1bdf02b6894c786581de4b1a0d1
|
4
|
+
data.tar.gz: d894f71336ba73f58c5bc968b5eae7e69272f476
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d76c1ec917029ebed79bbb2b8c457573cc699aed07b45957831be86f0edddd08aea345054a29a89e5f799866071cc79d10a6abdad1ee21b4b7e91365e8ae2fd
|
7
|
+
data.tar.gz: 0602b7675e99bffc14cf809230532d2277c4285a11f069ead884f92c4c2575b6c3018f3ccb55e35732565246343fe8fb6b6b4df415457229e60e70b5eec66d03
|
@@ -45,6 +45,7 @@ Capybara.javascript_driver = :webkit
|
|
45
45
|
Capybara::Screenshot.autosave_on_failure = true
|
46
46
|
Capybara::Screenshot.prune_strategy = :keep_last_run
|
47
47
|
Capybara::Screenshot.webkit_options = { width: 1024, height: 768 }
|
48
|
+
Capybara::Webkit.configure { |config| config.allow_unknown_urls }
|
48
49
|
|
49
50
|
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
50
51
|
|
@@ -14,6 +14,11 @@ module TestBotable
|
|
14
14
|
raise 'invalid parameters passed to crud_test(), expecting crud_test(Post || Post.new(), User.first, options_hash)'
|
15
15
|
end
|
16
16
|
|
17
|
+
if (options[:skip] || options[:skips]).present? && (options[:skip] || options[:skips]).kind_of?(Hash) == false
|
18
|
+
raise 'invalid skip syntax, expecting skip: {create_invalid: [:path]}'
|
19
|
+
end
|
20
|
+
|
21
|
+
skips = options.delete(:skip) || options.delete(:skips) || {} # So you can skip sub tests
|
17
22
|
test_options = crud_test_options(obj, user, options) # returns a Hash of let! options
|
18
23
|
tests_prefix = crud_tests_prefix(options) # returns a string something like "test_bot (3)"
|
19
24
|
|
@@ -30,7 +35,11 @@ module TestBotable
|
|
30
35
|
when :destroy ; "#{tests_prefix} #destroy"
|
31
36
|
end
|
32
37
|
|
33
|
-
|
38
|
+
if skips[test].present?
|
39
|
+
define_method(test_name) { crud_action_test(test, test_options.merge(skips: Array(skips[test]))) }
|
40
|
+
else
|
41
|
+
define_method(test_name) { crud_action_test(test, test_options) }
|
42
|
+
end
|
34
43
|
end
|
35
44
|
end
|
36
45
|
|
@@ -60,14 +69,15 @@ module TestBotable
|
|
60
69
|
resource_name: resource_class.name.underscore,
|
61
70
|
resource_attributes: resource_attributes,
|
62
71
|
controller_namespace: options[:namespace],
|
63
|
-
user: user
|
72
|
+
user: user,
|
73
|
+
skips: Array(options[:skip] || options[:skips])
|
64
74
|
}
|
65
75
|
end
|
66
76
|
|
67
77
|
# Run any test_bot tests first, in the order they're defined
|
68
78
|
# then the rest of the tests with whatever order they come in
|
69
79
|
def runnable_methods
|
70
|
-
self.public_instance_methods.select { |name| name.to_s.starts_with?('
|
80
|
+
self.public_instance_methods.select { |name| name.to_s.starts_with?('crud_test') }.map(&:to_s) +
|
71
81
|
super.reject { |name| name.starts_with?('test_bot') }
|
72
82
|
end
|
73
83
|
|
@@ -100,11 +110,11 @@ module TestBotable
|
|
100
110
|
@num_defined_crud_tests = (@num_defined_crud_tests || 0) + 1
|
101
111
|
|
102
112
|
if options[:label].present?
|
103
|
-
"
|
113
|
+
"crud_test: (#{options[:label]})"
|
104
114
|
elsif @num_defined_crud_tests > 1
|
105
|
-
"
|
115
|
+
"crud_test: (#{@num_defined_crud_tests})"
|
106
116
|
else
|
107
|
-
'
|
117
|
+
'crud_test:'
|
108
118
|
end
|
109
119
|
end
|
110
120
|
|
@@ -129,7 +139,7 @@ module TestBotable
|
|
129
139
|
self.class.crud_test_options(obj, user, options)
|
130
140
|
end.each { |k, v| self.class.let(k) { v } } # Using the regular let(:foo) { 'bar'} syntax
|
131
141
|
|
132
|
-
self.
|
142
|
+
self.public_send(test)
|
133
143
|
end
|
134
144
|
end
|
135
145
|
end
|
@@ -11,7 +11,7 @@ module EffectiveTestBotAssertions
|
|
11
11
|
assert page.has_selector?('form#new_user')
|
12
12
|
end
|
13
13
|
|
14
|
-
def assert_page_title(title = :any, message = '
|
14
|
+
def assert_page_title(title = :any, message = 'Expected page title to be present')
|
15
15
|
if title.present? && title != :any
|
16
16
|
assert_title(title) # Capybara TitleQuery, match this text
|
17
17
|
else
|
@@ -20,8 +20,8 @@ module EffectiveTestBotAssertions
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def assert_page_status(status = 200)
|
24
|
-
assert_equal status, page.status_code,
|
23
|
+
def assert_page_status(status = 200, message = 'Expected :status: HTTP status code')
|
24
|
+
assert_equal status, page.status_code, message.sub(':status:', status.to_s)
|
25
25
|
end
|
26
26
|
|
27
27
|
def assert_no_js_errors
|
@@ -36,9 +36,9 @@ module EffectiveTestBotAssertions
|
|
36
36
|
if key.present? && value.present?
|
37
37
|
assert_equal value, flash[key.to_s]
|
38
38
|
elsif key.present?
|
39
|
-
assert flash[key.to_s].present?, "
|
39
|
+
assert flash[key.to_s].present?, "Expected flash[#{key}] to be present"
|
40
40
|
else
|
41
|
-
assert flash.present?, '
|
41
|
+
assert flash.present?, 'Expected flash to be present'
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -49,9 +49,9 @@ module EffectiveTestBotAssertions
|
|
49
49
|
if key.present? && value.present?
|
50
50
|
assert_equal value, assigns[key.to_s]
|
51
51
|
elsif key.present?
|
52
|
-
assert assigns[key.to_s].present?, "
|
52
|
+
assert assigns[key.to_s].present?, "Expected @#{key} to be assigned"
|
53
53
|
else
|
54
|
-
assert assigns.present?, '
|
54
|
+
assert assigns.present?, 'Expected assigns to be present'
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -30,10 +30,13 @@ module EffectiveTestBotFormHelper
|
|
30
30
|
raise "unsupported field type #{[field.tag_name, field['type']].compact.join('_')}"
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
true
|
33
35
|
end
|
34
36
|
|
35
37
|
def clear_form
|
36
38
|
all('input,select,textarea').each { |field| (field.set('') rescue false) }
|
39
|
+
true
|
37
40
|
end
|
38
41
|
|
39
42
|
# Operates on just string keys
|
@@ -60,7 +63,7 @@ module EffectiveTestBotFormHelper
|
|
60
63
|
when 'input_number'
|
61
64
|
Faker::Number.number(4)
|
62
65
|
when 'input_password'
|
63
|
-
Faker::Internet.password
|
66
|
+
@test_bot_password ||= Faker::Internet.password # Use the same password throughout a single test. Allows passwords and password_confirmations to match.
|
64
67
|
when 'input_tel'
|
65
68
|
d = 10.times.map { DIGITS.sample }
|
66
69
|
d[0] + d[1] + d[2] + '-' + d[3] + d[4] + d[5] + '-' + d[6] + d[7] + d[8] + d[9]
|
@@ -111,6 +114,7 @@ module EffectiveTestBotFormHelper
|
|
111
114
|
first(:css, "input[type='submit']").click
|
112
115
|
end
|
113
116
|
synchronize!
|
117
|
+
true
|
114
118
|
end
|
115
119
|
|
116
120
|
# Submit form after disabling any HTML5 validations
|
@@ -125,8 +129,6 @@ module EffectiveTestBotFormHelper
|
|
125
129
|
files = Array(files)
|
126
130
|
uid = field['id']
|
127
131
|
|
128
|
-
page.driver.allow_url(Effective::Asset.s3_base_path)
|
129
|
-
|
130
132
|
js = "fileList = Array();"
|
131
133
|
|
132
134
|
files.each_with_index do |file, i|
|
@@ -22,11 +22,11 @@ module EffectiveTestBotTestHelper
|
|
22
22
|
# EffectiveTestBot includes an after_filter on ApplicationController to set an http header
|
23
23
|
# that encodes the flash message, and some of the assigns
|
24
24
|
def flash
|
25
|
-
@flash ||= (JSON.parse(Base64.decode64(page.
|
25
|
+
@flash ||= (JSON.parse(Base64.decode64(page.response_headers['Test-Bot-Flash'])) rescue {})
|
26
26
|
end
|
27
27
|
|
28
28
|
def assigns
|
29
|
-
@assigns ||= (JSON.parse(Base64.decode64(page.
|
29
|
+
@assigns ||= (JSON.parse(Base64.decode64(page.response_headers['Test-Bot-Assigns'])) rescue {})
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
@@ -5,14 +5,14 @@ module CrudTest
|
|
5
5
|
assert_page_status
|
6
6
|
assert_page_title
|
7
7
|
assert_no_js_errors
|
8
|
-
assert_assigns
|
8
|
+
assert_assigns(resource_name)
|
9
9
|
|
10
10
|
# Make sure there's a form with a submit button
|
11
11
|
form_selector = "form#new_#{resource_name}"
|
12
12
|
|
13
|
-
assert_selector form_selector, "
|
13
|
+
assert_selector form_selector, "Expected form with selector #{form_selector}"
|
14
14
|
within(form_selector) do
|
15
|
-
assert_selector 'input[type=submit]', '
|
15
|
+
assert_selector 'input[type=submit]', 'Expected submit button to be present'
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -28,13 +28,13 @@ module CrudTest
|
|
28
28
|
|
29
29
|
after = { count: resource_class.count, path: page.current_path }
|
30
30
|
|
31
|
-
refute_equal before[:count], after[:count], "
|
32
|
-
refute_equal
|
31
|
+
refute_equal before[:count], after[:count], "Expected fill_form to create a #{resource_class} object"
|
32
|
+
refute_equal(before[:path], after[:path], "[create_valid: :path] Expected unique before and after paths") unless skip?(:path)
|
33
33
|
|
34
|
-
# In a rails controller, if
|
34
|
+
# In a rails controller, if I redirect to resources_path it may not assign the instance variable
|
35
35
|
# Wheras if I redirect to edit_resource_path I must ensure that the instance variable is set
|
36
36
|
assert_assigns(resource_name) if after[:path].include?('/edit/')
|
37
|
-
|
37
|
+
assert_equal(nil, assigns[resource_name]['errors'], "Expected @#{resource_name}['errors'] to be blank") if assigns[resource_name].present?
|
38
38
|
end
|
39
39
|
|
40
40
|
def create_invalid
|
@@ -42,18 +42,20 @@ module CrudTest
|
|
42
42
|
before = { count: resource_class.count }
|
43
43
|
|
44
44
|
within("form#new_#{resource_name}") do
|
45
|
+
clear_form
|
45
46
|
submit_novalidate_form
|
46
47
|
end
|
47
48
|
|
48
49
|
after = { count: resource_class.count }
|
49
50
|
|
50
|
-
assert_equal before[:count], after[:count],
|
51
|
-
|
52
|
-
assert_page_title :any, 'page title missing after failed validation'
|
51
|
+
assert_equal before[:count], after[:count], "Expected: #{resource_class}.count to be unchanged"
|
52
|
+
assert_page_title :any, 'Expected page title to be present after failed validation'
|
53
53
|
|
54
54
|
assert_flash :danger
|
55
55
|
assert_assigns resource_name
|
56
|
-
|
56
|
+
refute_equal nil, assigns[resource_name]['errors'], "Expected @#{resource_name}['errors'] to be present"
|
57
|
+
|
58
|
+
assert_equal(resources_path, page.current_path, "[create_invalid: :path] Expected current_path to match resource #create path") unless skip?(:path)
|
57
59
|
end
|
58
60
|
|
59
61
|
def edit
|
@@ -69,12 +71,10 @@ module CrudTest
|
|
69
71
|
# Make sure there's a form with a submit button
|
70
72
|
form_selector = "form#edit_#{resource_name}_#{resource.id}"
|
71
73
|
|
72
|
-
assert_selector form_selector, "
|
74
|
+
assert_selector form_selector, "Expected form with selector #{form_selector}"
|
73
75
|
within(form_selector) do
|
74
|
-
assert_selector 'input[type=submit]', '
|
76
|
+
assert_selector 'input[type=submit]', 'Expected submit button to be present'
|
75
77
|
end
|
76
|
-
|
77
|
-
assert_assigns resource_name
|
78
78
|
end
|
79
79
|
|
80
80
|
def update_valid
|
@@ -92,14 +92,15 @@ module CrudTest
|
|
92
92
|
|
93
93
|
after = { count: resource_class.count, updated_at: (resource.updated_at rescue nil) }
|
94
94
|
|
95
|
-
assert_equal before[:count], after[:count], "
|
96
|
-
|
95
|
+
assert_equal before[:count], after[:count], "Expected #{resource_class}.count to be unchanged"
|
96
|
+
refute_equal(before[:updated_at], after[:updated_at], "Expected @#{resource_name}.updated_at to have changed") if resource.respond_to?(:updated_at)
|
97
97
|
|
98
98
|
assert_flash :success
|
99
|
+
|
99
100
|
# In a rails controller, if i redirect to resources_path it may not assign the instance variable
|
100
101
|
# Wheras if I redirect to edit_resource_path I must ensure that the instance variable is set
|
101
102
|
assert_assigns(resource_name) if after[:path] == edit_resource_path(resource)
|
102
|
-
|
103
|
+
assert_equal(nil, assigns[resource_name]['errors'], "Expected @#{resource_name}['errors'] to be blank") if assigns[resource_name].present?
|
103
104
|
end
|
104
105
|
|
105
106
|
def update_invalid
|
@@ -117,14 +118,15 @@ module CrudTest
|
|
117
118
|
|
118
119
|
after = { count: resource_class.count, updated_at: (resource.updated_at rescue nil) }
|
119
120
|
|
120
|
-
assert_equal before[:count], after[:count], "
|
121
|
-
assert_equal(
|
122
|
-
|
123
|
-
assert_page_title :any, 'page title missing after failed validation'
|
121
|
+
assert_equal before[:count], after[:count], "Expected: #{resource_class}.count to be unchanged"
|
122
|
+
assert_equal(before[:updated_at], after[:updated_at], "Expected @#{resource_name}.updated_at to be unchanged") if resource.respond_to?(:updated_at)
|
123
|
+
assert_page_title :any, 'Expected page title to be present after failed validation'
|
124
124
|
|
125
125
|
assert_flash :danger
|
126
126
|
assert_assigns resource_name
|
127
|
-
|
127
|
+
refute_equal(nil, assigns[resource_name]['errors'], "Expected @#{resource_name}['errors'] to be present") if assigns[resource_name].present?
|
128
|
+
|
129
|
+
assert_equal(resource_path(resource), page.current_path, "[update_invalid: :path] Expected current_path to match resource #update path") unless skip?(:path)
|
128
130
|
end
|
129
131
|
|
130
132
|
def index
|
@@ -135,7 +137,7 @@ module CrudTest
|
|
135
137
|
assert_page_status
|
136
138
|
assert_page_title
|
137
139
|
assert_no_js_errors
|
138
|
-
assert
|
140
|
+
assert((assigns['datatable'].present? || assigns[resource_name.pluralize].present?), "[index: :assigns] Expected @#{resource_name.pluralize} or @datatable to be present") unless skip?(:assigns)
|
139
141
|
end
|
140
142
|
|
141
143
|
def show
|
@@ -161,17 +163,21 @@ module CrudTest
|
|
161
163
|
assert_flash :success
|
162
164
|
|
163
165
|
if resource.respond_to?(:archived)
|
164
|
-
assert after[:archived] == true, "
|
166
|
+
assert after[:archived] == true, "Expected #{resource_class}.archived? to be true"
|
165
167
|
else
|
166
|
-
refute_equal before[:count], after[:count], "
|
168
|
+
refute_equal before[:count], after[:count], "Expected: #{resource_class}.count to decrement by 1"
|
167
169
|
end
|
168
170
|
end
|
169
171
|
|
170
172
|
protected
|
171
173
|
|
174
|
+
def skip?(test)
|
175
|
+
skips.include?(test)
|
176
|
+
end
|
177
|
+
|
172
178
|
def find_or_create_resource!
|
173
179
|
existing = resource_class.last
|
174
|
-
existing.present? ? existing : create_resource!
|
180
|
+
(existing.present? && !existing.kind_of?(User)) ? existing : create_resource!
|
175
181
|
end
|
176
182
|
|
177
183
|
def create_resource!
|
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.
|
4
|
+
version: 0.4.0
|
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: 2015-06
|
11
|
+
date: 2015-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 1.6.0
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 1.6.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: capybara-screenshot
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|