effective_test_bot 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/app/helpers/effective_test_bot_controller_helper.rb +19 -0
- data/lib/effective_test_bot/version.rb +1 -1
- data/test/concerns/test_botable/base_dsl.rb +1 -0
- data/test/support/effective_test_bot_assertions.rb +15 -0
- data/test/support/effective_test_bot_form_helper.rb +2 -1
- data/test/support/effective_test_bot_screenshots_helper.rb +1 -1
- data/test/support/effective_test_bot_test_helper.rb +2 -2
- data/test/test_botable/base_test.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 533f4dfe9d458e6c298b9da728e511cc2346e466
|
4
|
+
data.tar.gz: 92e5aad66b7f4d7ef653324412c45b5cc6b445e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afec0dac31e2002a83206d087e4b3706b6966addfc8e63b5ec58461da5d020bd9f9d28ec4181c68e356758c6134fe4bb319a7b316548437989ca8f5cb4b71f6c
|
7
|
+
data.tar.gz: 328fcf108174c8348c251da7a5eaab777453b35bee4604ec36e997271e138e5bae4323f0fb1524147eec83847f505170be8c19254e818cbf0ea67e8a31f01d10
|
data/README.md
CHANGED
@@ -105,6 +105,7 @@ The following assertions are added for use in any integration test:
|
|
105
105
|
|
106
106
|
- `assert_assigns` asserts a given rails view_assigns object is present.
|
107
107
|
- `assert_assigns_errors` use after an intentionally invalid form submit to make sure your assigned rails object has errors, or a specific error.
|
108
|
+
- `assert_authorization` checks for a 403 Access Denied error. Add `assign_test_bot_access_denied_exception(exception)` to your ApplicationController's `rescue_from` block to generate more information.
|
108
109
|
- `assert_no_assigns_errors` should be used after any form submit to make sure your assigned rails object has no errors. Prints out any errors if they exist.
|
109
110
|
- `assert_current_path(path)` asserts the current page path.
|
110
111
|
- `assert_email(action)` asserts an email with the given action name was sent. Also supports `assert_email(to: email)` type syntax with to, from, subject, body.
|
@@ -253,10 +254,10 @@ There are a few variations on the one-liner method:
|
|
253
254
|
```ruby
|
254
255
|
class PostsTest < Capybara::Rails::TestCase
|
255
256
|
# Runs all 9 crud_action tests against /posts
|
256
|
-
crud_test(resource: Post
|
257
|
+
crud_test(resource: Post)
|
257
258
|
|
258
259
|
# Runs all 9 crud_action tests against /posts and use this Post's attributes when calling fill_form.
|
259
|
-
crud_test(resource: Post.new(title: 'my first post')
|
260
|
+
crud_test(resource: Post.new(title: 'my first post'))
|
260
261
|
|
261
262
|
# Runs all 9 crud_action tests against /admin/posts controller as a previously seeded or fixtured admin user
|
262
263
|
crud_test(resource: 'admin/posts', user: User.where(admin: true).first)
|
@@ -30,4 +30,23 @@ module EffectiveTestBotControllerHelper
|
|
30
30
|
response.headers['Test-Bot-Unpermitted-Params'] = Base64.encode64(exception.params.to_json)
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
def assign_test_bot_access_denied_exception(exception)
|
35
|
+
return unless Rails.env.test?
|
36
|
+
|
37
|
+
response.headers['Test-Bot-Access-Denied'] = Base64.encode64({
|
38
|
+
exception: exception,
|
39
|
+
action: exception.action,
|
40
|
+
subject: (
|
41
|
+
if exception.subject.kind_of?(Symbol)
|
42
|
+
":#{exception.subject}"
|
43
|
+
elsif exception.subject.class == Class
|
44
|
+
exception.subject.name
|
45
|
+
else
|
46
|
+
exception.subject.class.name
|
47
|
+
end
|
48
|
+
)
|
49
|
+
}.to_json)
|
50
|
+
end
|
51
|
+
|
33
52
|
end
|
@@ -54,6 +54,21 @@ module EffectiveTestBotAssertions
|
|
54
54
|
assert all("input[type='submit'],button[type='submit']").present?, message
|
55
55
|
end
|
56
56
|
|
57
|
+
def assert_authorization(message = '(authorization) Expected authorized access')
|
58
|
+
if page.status_code == 403
|
59
|
+
exception = access_denied_exception
|
60
|
+
|
61
|
+
info = [
|
62
|
+
"Encountered a 403 Access Denied",
|
63
|
+
("(cannot :#{exception['action']}, #{exception['subject']})" if exception.present?),
|
64
|
+
"on #{page.current_path} as user #{user || 'no user'}.",
|
65
|
+
("\nAdd assign_test_bot_access_denied_exception(exception) to your ApplicationController's rescue_from block to gather more information." unless exception.present?),
|
66
|
+
].compact.join(' ')
|
67
|
+
|
68
|
+
assert false, "#{message}.\n#{info}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
57
72
|
def assert_page_status(status = 200, message = '(page_status) Expected :status: HTTP status code')
|
58
73
|
assert_equal status, page.status_code, message.sub(':status:', status.to_s)
|
59
74
|
end
|
@@ -30,6 +30,7 @@ module EffectiveTestBotFormHelper
|
|
30
30
|
assert_no_unpermitted_params unless test_bot_skip?(:no_unpermitted_params)
|
31
31
|
assert_no_assigns_errors unless test_bot_skip?(:no_assigns_errors)
|
32
32
|
assert_no_exceptions unless test_bot_skip?(:exceptions)
|
33
|
+
assert_authorization unless test_bot_skip?(:authorization)
|
33
34
|
assert_page_status unless test_bot_skip?(:page_status)
|
34
35
|
|
35
36
|
true
|
@@ -45,7 +46,7 @@ module EffectiveTestBotFormHelper
|
|
45
46
|
def clear_form
|
46
47
|
all('input,select,textarea').each do |field|
|
47
48
|
if field.tag_name == 'select' && field['class'].to_s.include?('select2') # effective_select
|
48
|
-
within(field.
|
49
|
+
within(field.query_scope) { first(:css, '.select2-selection__clear').try(:click) }
|
49
50
|
end
|
50
51
|
|
51
52
|
begin
|
@@ -95,7 +95,7 @@ module EffectiveTestBotScreenshotsHelper
|
|
95
95
|
|
96
96
|
def current_test_failure_filename
|
97
97
|
# Match Capybara-screenshots format-ish
|
98
|
-
"#{current_test_name.parameterize}
|
98
|
+
"#{current_test_name.parameterize}-failure-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.gif"
|
99
99
|
end
|
100
100
|
|
101
101
|
# Where the tour animated gif ends up
|
@@ -69,8 +69,8 @@ module EffectiveTestBotTestHelper
|
|
69
69
|
(JSON.parse(Base64.decode64(page.response_headers['Test-Bot-Unpermitted-Params'])) rescue [])
|
70
70
|
end
|
71
71
|
|
72
|
-
def
|
73
|
-
(JSON.parse(Base64.decode64(page.response_headers['Test-Bot-
|
72
|
+
def access_denied_exception
|
73
|
+
(JSON.parse(Base64.decode64(page.response_headers['Test-Bot-Access-Denied'])) rescue {})
|
74
74
|
end
|
75
75
|
|
76
76
|
end
|
@@ -8,6 +8,7 @@ module BaseTest
|
|
8
8
|
return if test_bot_skip?(:normal)
|
9
9
|
|
10
10
|
assert_no_exceptions unless test_bot_skip?(:exceptions)
|
11
|
+
assert_authorization unless test_bot_skip?(:authorization)
|
11
12
|
assert_page_status unless test_bot_skip?(:page_status)
|
12
13
|
assert_no_js_errors unless test_bot_skip?(:no_js_errors)
|
13
14
|
assert_page_title unless (test_bot_skip?(:page_title) || all('head').blank? || was_download?)
|
@@ -51,7 +52,9 @@ module BaseTest
|
|
51
52
|
assert(new_path.present?, "TestBotError: Generated polymorphic route new_#{[*controller_namespace, resource_name].compact.join('_')}_path is undefined. #{hint}")
|
52
53
|
|
53
54
|
visit(new_path)
|
55
|
+
|
54
56
|
assert_no_exceptions
|
57
|
+
assert_authorization(hint)
|
55
58
|
assert_page_status
|
56
59
|
|
57
60
|
assert_form("form#new_#{resource_name}", "TestBotError: Failed to find form#new_#{resource_name}. #{hint}") unless test_bot_skip?(:form)
|
@@ -63,6 +66,7 @@ module BaseTest
|
|
63
66
|
submit_novalidate_form
|
64
67
|
|
65
68
|
assert_no_exceptions
|
69
|
+
assert_authorization(hint)
|
66
70
|
assert_page_status
|
67
71
|
end
|
68
72
|
|
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.6.
|
4
|
+
version: 0.6.4
|
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: 2017-02-
|
11
|
+
date: 2017-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|