effective_test_bot 0.4.1 → 0.4.2

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.
@@ -5,6 +5,8 @@ if defined?(Devise) && defined?(User)
5
5
  class UserTest < ActiveSupport::TestCase
6
6
  let(:user) { User.new() }
7
7
 
8
+ # These are mostly here as an example of using shoulda
9
+ # I don't find that I use the gem, but I see it's value
8
10
  should validate_presence_of(:email)
9
11
  should validate_presence_of(:password)
10
12
  should validate_presence_of(:encrypted_password)
@@ -0,0 +1,62 @@
1
+ # All the methods in this file should not be called from the outside world
2
+ # See the DSL files in concerns/test_botable/ for how to call these tests
3
+
4
+ module BaseTest
5
+ protected
6
+
7
+ def assert_page_normal(message = nil)
8
+ unless test_bot_skip?(:normal)
9
+ assert_page_status unless test_bot_skip?(:page_status)
10
+ assert_page_title unless test_bot_skip?(:page_title)
11
+ assert_no_js_errors unless test_bot_skip?(:no_js_errors)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ # I want to use this same method for the current_test rake test:bot skip functionality
18
+ # As well as the individual assertion skips
19
+
20
+ # Only class level dsl methods will have a current_test assigned
21
+ # if you use the action_test_ instance methods, current_test is nil, and test skips won't apply
22
+ # Any global assertion skips will tho
23
+ def test_bot_skip?(assertion = nil)
24
+ # Skip the whole test
25
+ # this will put SKIP into the minitest output
26
+ skip if (defined?(current_test) && EffectiveTestBot.skip?(current_test))
27
+
28
+ # Check if the individual assertion should be skipped
29
+ EffectiveTestBot.skip?((current_test if defined?(current_test)), assertion)
30
+ end
31
+
32
+ def find_or_create_resource!
33
+ existing = resource_class.last
34
+ (existing.present? && !existing.kind_of?(User)) ? existing : create_resource!
35
+ end
36
+
37
+ def create_resource!
38
+ visit(new_resource_path)
39
+
40
+ within("form#new_#{resource_name}") do
41
+ fill_form(resource_attributes) and submit_form
42
+ end
43
+
44
+ resource_class.last
45
+ end
46
+
47
+ def resources_path # index, create
48
+ polymorphic_path([*controller_namespace, resource_class])
49
+ end
50
+
51
+ def resource_path(resource) # show, update, destroy
52
+ polymorphic_path([*controller_namespace, resource])
53
+ end
54
+
55
+ def new_resource_path # new
56
+ new_polymorphic_path([*controller_namespace, resource])
57
+ end
58
+
59
+ def edit_resource_path(resource) # edit
60
+ edit_polymorphic_path([*controller_namespace, resource])
61
+ end
62
+ end
@@ -1,11 +1,15 @@
1
+ # All the methods in this file should not be called from the outside world
2
+ # See the DSL files in concerns/test_botable/ for how to call these tests
3
+
1
4
  module CrudTest
2
- def new
5
+ protected
6
+
7
+ def test_bot_new_test
8
+ test_bot_skip?
3
9
  sign_in(user) and visit(new_resource_path)
4
10
 
5
- assert_page_status
6
- assert_page_title
7
- assert_no_js_errors
8
- assert_assigns(resource_name)
11
+ assert_page_normal
12
+ assert_assigns(resource_name) # unskippable
9
13
 
10
14
  # Make sure there's a form with a submit button
11
15
  form_selector = "form#new_#{resource_name}"
@@ -16,31 +20,35 @@ module CrudTest
16
20
  end
17
21
  end
18
22
 
19
- def create_valid
23
+ def test_bot_create_valid_test
24
+ test_bot_skip?
20
25
  sign_in(user) and visit(new_resource_path)
21
26
 
22
27
  before = { count: resource_class.count, path: page.current_path }
23
28
 
24
29
  within("form#new_#{resource_name}") do
25
30
  fill_form(resource_attributes)
26
- skip?(:unpermitted_params) == true ? submit_form : with_raised_unpermitted_params_exceptions { submit_form }
31
+ test_bot_skip?(:unpermitted_params) ? submit_form : with_raised_unpermitted_params_exceptions { submit_form }
27
32
  end
28
33
 
29
34
  after = { count: resource_class.count, path: page.current_path }
30
35
 
31
- assert_no_unpermitted_params '[create_valid: :unpermitted_params] Expected no unpermitted params' unless skip?(:unpermitted_params)
36
+ assert_page_normal
37
+ assert_no_unpermitted_params unless test_bot_skip?(:unpermitted_params)
32
38
 
33
39
  refute_equal before[:count], after[:count], "Expected fill_form to create a #{resource_class} object"
34
- refute_equal(before[:path], after[:path], "[create_valid: :path] Expected unique before and after paths") unless skip?(:path)
40
+ refute_equal(before[:path], after[:path], "(path) Expected unique before and after paths") unless test_bot_skip?(:path)
35
41
 
36
42
  # In a rails controller, if I redirect to resources_path it may not assign the instance variable
37
43
  # Wheras if I redirect to edit_resource_path I must ensure that the instance variable is set
38
- assert_assigns(resource_name) if after[:path].include?('/edit/')
39
- assert_equal(nil, assigns[resource_name]['errors'], "Expected @#{resource_name}['errors'] to be blank") if assigns[resource_name].present?
44
+ assert_assigns(resource_name) if (after[:path].include?('/edit/') && !test_bot_skip?(:assigns))
45
+ assert_no_assigns_errors(resource_name) unless test_bot_skip?(:no_assigns_errors)
40
46
  end
41
47
 
42
- def create_invalid
48
+ def test_bot_create_invalid_test
49
+ test_bot_skip?
43
50
  sign_in(user) and visit(new_resource_path)
51
+
44
52
  before = { count: resource_class.count }
45
53
 
46
54
  within("form#new_#{resource_name}") do
@@ -50,36 +58,37 @@ module CrudTest
50
58
 
51
59
  after = { count: resource_class.count }
52
60
 
53
- assert_equal before[:count], after[:count], "Expected: #{resource_class}.count to be unchanged"
54
- assert_page_title :any, 'Expected page title to be present after failed validation'
61
+ assert_equal before[:count], after[:count], "Expected #{resource_class}.count to be unchanged"
62
+ assert_page_title(:any, '(page_title) Expected page title to be present after failed validation') unless test_bot_skip?(:page_title)
55
63
 
56
- assert_flash :danger
57
- assert_assigns resource_name
58
- refute_equal nil, assigns[resource_name]['errors'], "Expected @#{resource_name}['errors'] to be present"
64
+ assert_no_js_errors unless test_bot_skip?(:no_js_errors)
65
+ assert_flash(:danger) unless test_bot_skip?(:flash)
66
+ assert_assigns(resource_name) unless test_bot_skip?(:assigns)
67
+ assert_assigns_errors(resource_name) unless test_bot_skip?(:assigns_errors)
59
68
 
60
- assert_equal(resources_path, page.current_path, "[create_invalid: :path] Expected current_path to match resource #create path") unless skip?(:path)
69
+ assert_equal(resources_path, page.current_path, "(path) Expected current_path to match resource #create path #{resources_path}") unless test_bot_skip?(:path)
61
70
  end
62
71
 
63
- def edit
72
+ def test_bot_edit_test
73
+ test_bot_skip?
64
74
  sign_in(user) and (resource = find_or_create_resource!)
65
75
 
66
76
  visit(edit_resource_path(resource))
67
77
 
68
- assert_page_status
69
- assert_page_title
70
- assert_no_js_errors
71
- assert_assigns resource_name
78
+ assert_page_normal
79
+ assert_assigns(resource_name) unless test_bot_skip?(:assigns)
72
80
 
73
81
  # Make sure there's a form with a submit button
74
82
  form_selector = "form#edit_#{resource_name}_#{resource.id}"
75
83
 
76
84
  assert_selector form_selector, "Expected form with selector #{form_selector}"
77
85
  within(form_selector) do
78
- assert_selector 'input[type=submit]', 'Expected submit button to be present'
86
+ assert_selector 'input[type=submit]', 'Expected input[type=submit] to be present'
79
87
  end
80
88
  end
81
89
 
82
- def update_valid
90
+ def test_bot_update_valid_test
91
+ test_bot_skip?
83
92
  sign_in(user) and (resource = find_or_create_resource!)
84
93
 
85
94
  visit(edit_resource_path(resource))
@@ -88,26 +97,28 @@ module CrudTest
88
97
 
89
98
  within("form#edit_#{resource_name}_#{resource.id}") do
90
99
  fill_form(resource_attributes)
91
- skip?(:unpermitted_params) == true ? submit_form : with_raised_unpermitted_params_exceptions { submit_form }
100
+ test_bot_skip?(:unpermitted_params) ? submit_form : with_raised_unpermitted_params_exceptions { submit_form }
92
101
  end
93
102
  resource = resource_class.find(resource.id)
94
103
 
95
104
  after = { count: resource_class.count, updated_at: (resource.updated_at rescue nil) }
96
105
 
97
- assert_no_unpermitted_params '[update_valid: :unpermitted_params] Expected no unpermitted params' unless skip?(:unpermitted_params)
106
+ assert_no_js_errors unless test_bot_skip?(:no_js_errors)
107
+ assert_no_unpermitted_params unless test_bot_skip?(:unpermitted_params)
98
108
 
99
109
  assert_equal before[:count], after[:count], "Expected #{resource_class}.count to be unchanged"
100
- refute_equal(before[:updated_at], after[:updated_at], "Expected @#{resource_name}.updated_at to have changed") if resource.respond_to?(:updated_at)
110
+ refute_equal(before[:updated_at], after[:updated_at], "(updated_at_changed) Expected @#{resource_name}.updated_at to have changed") if (resource.respond_to?(:updated_at) && !test_bot_skip?(:updated_at_changed))
101
111
 
102
- assert_flash :success
112
+ assert_flash(:success) unless test_bot_skip?(:flash)
103
113
 
104
114
  # In a rails controller, if i redirect to resources_path it may not assign the instance variable
105
115
  # Wheras if I redirect to edit_resource_path I must ensure that the instance variable is set
106
- assert_assigns(resource_name) if after[:path] == edit_resource_path(resource)
107
- assert_equal(nil, assigns[resource_name]['errors'], "Expected @#{resource_name}['errors'] to be blank") if assigns[resource_name].present?
116
+ assert_assigns(resource_name) if (after[:path] == edit_resource_path(resource) && !test_bot_skip?(:assigns))
117
+ assert_no_assigns_errors(resource_name) unless test_bot_skip?(:no_assigns_errors)
108
118
  end
109
119
 
110
- def update_invalid
120
+ def test_bot_update_invalid_test
121
+ test_bot_skip?
111
122
  sign_in(user) and (resource = find_or_create_resource!)
112
123
 
113
124
  visit(edit_resource_path(resource))
@@ -122,40 +133,44 @@ module CrudTest
122
133
 
123
134
  after = { count: resource_class.count, updated_at: (resource.updated_at rescue nil) }
124
135
 
136
+ assert_no_js_errors unless test_bot_skip?(:no_js_errors)
125
137
  assert_equal before[:count], after[:count], "Expected: #{resource_class}.count to be unchanged"
126
138
  assert_equal(before[:updated_at], after[:updated_at], "Expected @#{resource_name}.updated_at to be unchanged") if resource.respond_to?(:updated_at)
127
- assert_page_title :any, 'Expected page title to be present after failed validation'
139
+ assert_page_title(:any, '(page_title) Expected page title to be present after failed validation') unless test_bot_skip?(:page_title)
128
140
 
129
- assert_flash :danger
130
- assert_assigns resource_name
131
- refute_equal(nil, assigns[resource_name]['errors'], "Expected @#{resource_name}['errors'] to be present") if assigns[resource_name].present?
141
+ assert_flash(:danger) unless test_bot_skip?(:flash)
142
+ assert_assigns(resource_name) unless test_bot_skip?(:assigns)
143
+ assert_assigns_errors(resource_name) unless test_bot_skip?(:assigns_errors)
132
144
 
133
- assert_equal(resource_path(resource), page.current_path, "[update_invalid: :path] Expected current_path to match resource #update path") unless skip?(:path)
145
+ assert_equal(resource_path(resource), page.current_path, "(path) Expected current_path to match resource #update path") unless test_bot_skip?(:path)
134
146
  end
135
147
 
136
- def index
137
- sign_in(user) and (resource = find_or_create_resource!)
148
+ def test_bot_index_test
149
+ test_bot_skip?
150
+ sign_in(user) and (resource = (find_or_create_resource! rescue nil))
138
151
 
139
152
  visit resources_path
140
153
 
141
- assert_page_status
142
- assert_page_title
143
- assert_no_js_errors
144
- assert((assigns['datatable'].present? || assigns[resource_name.pluralize].present?), "[index: :assigns] Expected @#{resource_name.pluralize} or @datatable to be present") unless skip?(:assigns)
154
+ assert_page_normal
155
+
156
+ assert(
157
+ (assigns['datatable'].present? || assigns[resource_name.pluralize].present?),
158
+ "(assigns) Expected @#{resource_name.pluralize} or @datatable to be present"
159
+ ) unless test_bot_skip?(:assigns)
145
160
  end
146
161
 
147
- def show
148
- sign_in(user) and (resource = create_resource!)
162
+ def test_bot_show_test
163
+ test_bot_skip?
164
+ sign_in(user) and (resource = find_or_create_resource!)
149
165
 
150
166
  visit resource_path(resource)
151
167
 
152
- assert_page_status
153
- assert_page_title
154
- assert_no_js_errors
155
- assert_assigns resource_name
168
+ assert_page_normal
169
+ assert_assigns(resource_name) unless test_bot_skip?(:assigns)
156
170
  end
157
171
 
158
- def destroy
172
+ def test_bot_destroy_test
173
+ test_bot_skip?
159
174
  sign_in(user) and (resource = find_or_create_resource!)
160
175
 
161
176
  before = { count: resource_class.count, archived: (resource.archived rescue nil) }
@@ -164,51 +179,12 @@ module CrudTest
164
179
 
165
180
  after = { count: resource_class.count, archived: (resource_class.find(resource.id).archived rescue nil) }
166
181
 
167
- assert_flash :success
182
+ assert_flash(:success) unless test_bot_skip?(:flash)
168
183
 
169
184
  if resource.respond_to?(:archived)
170
- assert after[:archived] == true, "Expected #{resource_class}.archived? to be true"
185
+ assert_equal(true, after[:archived], "Expected #{resource_class}.archived? to be true")
171
186
  else
172
- refute_equal before[:count], after[:count], "Expected: #{resource_class}.count to decrement by 1"
187
+ assert_equal before[:count]-1, after[:count], "Expected: #{resource_class}.count to decrement by 1"
173
188
  end
174
189
  end
175
-
176
- protected
177
-
178
- def skip?(test)
179
- skips.include?(test)
180
- end
181
-
182
- def find_or_create_resource!
183
- existing = resource_class.last
184
- (existing.present? && !existing.kind_of?(User)) ? existing : create_resource!
185
- end
186
-
187
- def create_resource!
188
- visit(new_resource_path)
189
-
190
- within("form#new_#{resource_name}") do
191
- fill_form(resource_attributes) and submit_form
192
- end
193
-
194
- resource_class.last
195
- end
196
-
197
- private
198
-
199
- def resources_path # index, create
200
- polymorphic_path([*controller_namespace, resource_class])
201
- end
202
-
203
- def resource_path(resource) # show, update, destroy
204
- polymorphic_path([*controller_namespace, resource])
205
- end
206
-
207
- def new_resource_path # new
208
- new_polymorphic_path([*controller_namespace, resource])
209
- end
210
-
211
- def edit_resource_path(resource) # edit
212
- edit_polymorphic_path([*controller_namespace, resource])
213
- end
214
190
  end
@@ -0,0 +1,20 @@
1
+ # All the methods in this file should not be called from the outside world
2
+ # See the DSL files in concerns/test_botable/ for how to call these tests
3
+
4
+ module MemberTest
5
+ protected
6
+
7
+ def test_bot_member_test
8
+ test_bot_skip?
9
+ sign_in(user) and (resource = find_or_create_resource!)
10
+
11
+ path = url_for(controller: controller, action: action, id: resource.id, only_path: true)
12
+
13
+ visit(path)
14
+
15
+ assert_page_normal
16
+ assert_flash unless test_bot_skip?(:flash)
17
+ assert_assigns(resource_name) unless (was_redirect?(path) || test_bot_skip?(:assigns))
18
+ end
19
+
20
+ end
@@ -0,0 +1,23 @@
1
+ # All the methods in this file should not be called from the outside world
2
+ # See the DSL files in concerns/test_botable/ for how to call these tests
3
+
4
+ module PageTest
5
+ protected
6
+
7
+ def test_bot_page_test
8
+ test_bot_skip?
9
+
10
+ sign_in(user)
11
+
12
+ if page_path.kind_of?(Symbol)
13
+ visit(public_send(page_path))
14
+ else
15
+ visit(page_path)
16
+ end
17
+
18
+ assert_page_normal
19
+
20
+ #page.save_screenshot("#{page_path.to_s.parameterize}.png")
21
+ end
22
+
23
+ end
@@ -0,0 +1,18 @@
1
+ # All the methods in this file should not be called from the outside world
2
+ # See the DSL files in concerns/test_botable/ for how to call these tests
3
+
4
+ module RedirectTest
5
+ protected
6
+
7
+ def test_bot_redirect_test
8
+ test_bot_skip?
9
+
10
+ sign_in(user) and visit(from_path)
11
+
12
+ assert_redirect(from_path, to_path)
13
+ assert_page_normal
14
+
15
+ #page.save_screenshot("#{from_path.parameterize}.png")
16
+ end
17
+
18
+ end
@@ -0,0 +1,31 @@
1
+ # All the methods in this file should not be called from the outside world
2
+ # See the DSL files in concerns/test_botable/ for how to call these tests
3
+
4
+ module WizardTest
5
+ protected
6
+
7
+ def test_bot_wizard_test
8
+ test_bot_skip?
9
+
10
+ sign_in(user) and visit(from_path)
11
+
12
+ 0.upto(50) do |index| # Can only test wizards 51 steps long
13
+ assert_page_normal
14
+
15
+ if defined?(within_form)
16
+ within(within_form) do
17
+ fill_form
18
+ submit_form
19
+ end
20
+ else
21
+ fill_form
22
+ submit_form
23
+ end
24
+
25
+ break if page.current_path == to_path
26
+ end
27
+
28
+ assert_current_path to_path
29
+ end
30
+
31
+ end
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.1
4
+ version: 0.4.2
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-07-07 00:00:00.000000000 Z
11
+ date: 2015-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -211,17 +211,27 @@ files:
211
211
  - lib/generators/templates/effective_test_bot.rb
212
212
  - lib/generators/templates/test_helper.rb
213
213
  - lib/tasks/effective_test_bot_tasks.rake
214
- - test/concerns/test_botable/crud_test.rb
214
+ - test/concerns/test_botable/base_dsl.rb
215
+ - test/concerns/test_botable/crud_dsl.rb
216
+ - test/concerns/test_botable/member_dsl.rb
217
+ - test/concerns/test_botable/page_dsl.rb
218
+ - test/concerns/test_botable/redirect_dsl.rb
219
+ - test/concerns/test_botable/wizard_dsl.rb
215
220
  - test/support/effective_assets_upload_file._test
216
221
  - test/support/effective_test_bot_assertions.rb
217
222
  - test/support/effective_test_bot_form_helper.rb
218
223
  - test/support/effective_test_bot_login_helper.rb
219
224
  - test/support/effective_test_bot_test_helper.rb
225
+ - test/test_bot/integration/application_test.rb
220
226
  - test/test_bot/integration/devise_test.rb
221
- - test/test_bot/integration/home_page_test.rb
222
227
  - test/test_bot/integration/minitest_test.rb
223
228
  - test/test_bot/models/user_test.rb
229
+ - test/test_botable/base_test.rb
224
230
  - test/test_botable/crud_test.rb
231
+ - test/test_botable/member_test.rb
232
+ - test/test_botable/page_test.rb
233
+ - test/test_botable/redirect_test.rb
234
+ - test/test_botable/wizard_test.rb
225
235
  homepage: https://github.com/code-and-effect/effective_test_bot
226
236
  licenses:
227
237
  - MIT