effective_test_bot 0.0.10 → 0.2.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.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -30
  3. data/lib/effective_test_bot/engine.rb +10 -1
  4. data/lib/effective_test_bot/version.rb +2 -1
  5. data/lib/generators/effective_test_bot/install_generator.rb +1 -20
  6. data/lib/generators/templates/effective_test_bot.rb +3 -1
  7. data/lib/generators/templates/{minitest/test_helper.rb → test_helper.rb} +9 -5
  8. data/lib/tasks/effective_test_bot_tasks.rake +4 -22
  9. data/test/concerns/acts_as_test_botable.rb +57 -0
  10. data/test/support/effective_test_bot_assertions.rb +26 -0
  11. data/{app/helpers/effective_test_bot_helper.rb → test/support/effective_test_bot_form_helper.rb} +14 -45
  12. data/test/support/effective_test_bot_login_helper.rb +31 -0
  13. data/test/support/effective_test_bot_test_helper.rb +18 -0
  14. data/test/test_bot/integration/devise_test.rb +51 -0
  15. data/test/test_bot/integration/minitest_test.rb +49 -59
  16. data/test/test_bot/models/user_test.rb +1 -1
  17. data/test/test_botable/crud_test.rb +181 -0
  18. metadata +24 -15
  19. data/lib/generators/templates/rspec/rails_helper.rb +0 -62
  20. data/lib/generators/templates/rspec/spec_helper.rb +0 -90
  21. data/spec/features/crud/crud_spec.rb +0 -50
  22. data/spec/features/devise/sign_in_spec.rb +0 -43
  23. data/spec/features/devise/sign_up_spec.rb +0 -29
  24. data/spec/features/home_page_spec.rb +0 -8
  25. data/spec/models/user_spec.rb +0 -19
  26. data/test/fixtures/users.yml +0 -3
  27. data/test/test_bot/integration/devise/sign_in_test.rb +0 -37
  28. data/test/test_bot/integration/devise/sign_up_test.rb +0 -25
  29. data/test/test_bot/models/database_test.rb +0 -24
@@ -0,0 +1,18 @@
1
+ module EffectiveTestBotTestHelper
2
+
3
+ # This makes sure capybara is done, and breaks out of any 'within' blocks
4
+ def synchronize!
5
+ page.document.find('html')
6
+ end
7
+
8
+ # Because capybara-webkit can't make delete requests, we need to use rack_test
9
+ # Makes a DELETE request to the given path as the given user
10
+ # It leaves any existing Capybara sessions untouched
11
+ def visit_delete(path, user)
12
+ session = Capybara::Session.new(:rack_test, Rails.application)
13
+ sign_in(user)
14
+ session.driver.submit :delete, path, {}
15
+ session.document.find('html')
16
+ end
17
+
18
+ end
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ if defined?(Devise) && defined?(User)
4
+ module TestBot
5
+ class DeviseTest < ActionDispatch::IntegrationTest
6
+ let(:email) { 'unique@testbot.com'}
7
+ let(:password) { '!Password123' }
8
+ let(:create_user!) { User.new(email: email, password: password, password_confirmation: password).save(validate: false) }
9
+
10
+ test 'sign up' do
11
+ visit new_user_registration_path
12
+
13
+ within('form#new_user') do
14
+ fill_form(email: email, password: password, password_confirmation: password)
15
+ submit_form
16
+ end
17
+
18
+ assert_equal page.status_code, 200
19
+ assert_content I18n.t('devise.registrations.signed_up')
20
+ assert User.find_by_email(email).present?
21
+ end
22
+
23
+ test 'sign in' do
24
+ create_user!
25
+ visit new_user_session_path
26
+
27
+ within('form#new_user') do
28
+ fill_form(email: email, password: password)
29
+ submit_form
30
+ end
31
+
32
+ assert_equal 200, page.status_code
33
+ assert_content I18n.t('devise.sessions.signed_in')
34
+ assert_equal 1, User.find_by_email(email).sign_in_count
35
+ end
36
+
37
+ test 'invalid sign in' do
38
+ create_user!
39
+ visit new_user_session_path
40
+
41
+ within('form#new_user') do
42
+ fill_form(email: email, password: 'not-correct-password')
43
+ submit_form
44
+ end
45
+
46
+ assert_equal 200, page.status_code
47
+ assert_content I18n.t('devise.failure.invalid', authentication_keys: Devise.authentication_keys.join(', '))
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,79 +1,69 @@
1
1
  require 'test_helper'
2
2
 
3
- class MinitestTest < ActionDispatch::IntegrationTest
4
- def self.test_order
5
- :alpha
6
- end
7
-
8
- test 'A: seeds and fixtures loaded' do
9
- assert_normal
10
- end
3
+ module TestBot
4
+ class MinitestTest < ActionDispatch::IntegrationTest
5
+ @@original_users_count = User.count
6
+ let(:original_users_count) { @@original_users_count }
11
7
 
12
- test 'B: i can use activerecord to create a user' do
13
- User.new(:email => 'another@agilestyle.com').save(:validate => false)
14
- assert_equal 3, User.count
15
- end
8
+ let(:email) { 'unique@testbot.com'}
9
+ let(:password) { '!Password123' }
10
+ let(:create_user!) { User.new(email: email, password: password, password_confirmation: password).save(validate: false) }
16
11
 
17
- test 'C: the test database is back to normal' do
18
- assert_normal
19
- end
12
+ def self.test_order
13
+ :alpha
14
+ end
20
15
 
21
- test 'D: i can use capybara to create a user' do
22
- user = sign_up()
23
- assert_equal 3, User.count
24
- assert_signed_in
25
- end
16
+ test '1: seeds and fixtures loaded' do
17
+ assert_normal
18
+ end
26
19
 
27
- test 'E: the test database is back to normal' do
28
- assert_normal
29
- end
20
+ test '2: activerecord can create a user' do
21
+ create_user!
22
+ assert_equal (original_users_count + 1), User.count
23
+ end
30
24
 
31
- test 'F: i am in a new capybara session, not currently signed in (after signing up in D)' do
32
- assert_signed_out
33
- sign_in('admin@agilestyle.com')
34
- assert_signed_in
35
- end
25
+ test '3: test database is back to normal' do
26
+ assert_normal
27
+ end
36
28
 
37
- test 'G: i am still in a new capybara session, not currently signed in' do
38
- assert_signed_out
39
- sign_in_manually('normal@agilestyle.com', 'password')
40
- assert_signed_in
41
- end
29
+ test '4: capybara can create a user' do
30
+ user = sign_up()
31
+ assert user.kind_of?(User)
42
32
 
43
- test 'H: i can use the with_user helper' do
44
- assert_signed_out
45
- as_user(User.first) do
33
+ assert_equal (original_users_count + 1), User.count
46
34
  assert_signed_in
47
35
  end
48
- assert_signed_out
49
- end
50
36
 
51
- private
37
+ test '5: test database is back to normal' do
38
+ assert_normal
39
+ end
40
+
41
+ test '6: capybara session has been reset after manual sign up' do
42
+ assert_signed_out
43
+ create_user!
44
+ sign_in(email)
45
+ assert_signed_in
46
+ end
52
47
 
53
- def assert_normal
54
- visit root_path
55
- assert_equal page.status_code, 200
48
+ test '7: test database is back to normal' do
49
+ assert_normal
50
+ end
56
51
 
57
- assert_equal 2, User.count
58
- assert_equal 1, Effective::Menu.count
52
+ test '8: capybara session has been reset after warden login_as' do
53
+ assert_signed_out
54
+ end
59
55
 
60
- assert_equal 'normal@agilestyle.com', User.first.email
61
- assert_equal 'admin@agilestyle.com', User.last.email
56
+ test '9: test database is back to normal' do
57
+ assert_normal
58
+ end
62
59
 
63
- assert_equal users(:normal).email, 'normal@agilestyle.com'
64
- end
60
+ private
65
61
 
66
- def assert_signed_in
67
- visit new_user_session_path
68
- assert_content 'You are already signed in. '
69
- refute page.has_selector?('form#new_user')
70
- end
62
+ def assert_normal
63
+ visit root_path
64
+ assert_equal page.status_code, 200
65
+ assert_equal original_users_count, User.count
66
+ end
71
67
 
72
- def assert_signed_out
73
- visit new_user_session_path
74
- refute_content 'You are already signed in. '
75
- assert_content 'Log in'
76
- assert page.has_selector?('form#new_user')
77
68
  end
78
-
79
69
  end
@@ -9,7 +9,7 @@ if defined?(Devise) && defined?(User)
9
9
  should validate_presence_of(:password)
10
10
  should validate_presence_of(:encrypted_password)
11
11
 
12
- test "user fails validation when password and confirmation mismatch" do
12
+ test "user invalid when password and confirmation mismatch" do
13
13
  user.password = '123456789'
14
14
  user.password_confirmation = '987654321'
15
15
 
@@ -0,0 +1,181 @@
1
+ module CrudTest
2
+ define_method 'test_bot: #new' do
3
+ should_skip!(:new)
4
+
5
+ sign_in(user) and visit(new_resource_path)
6
+
7
+ assert_page_status
8
+ assert_page_title
9
+
10
+ # Make sure there's a form with a submit button
11
+ form_selector = "form#new_#{resource_name}"
12
+
13
+ assert_selector form_selector, "page does not contain a form with selector #{form_selector}"
14
+ within(form_selector) do
15
+ assert_selector 'input[type=submit]', 'page form does not contain a submit button'
16
+ end
17
+ end
18
+
19
+ define_method 'test_bot: #create valid' do
20
+ should_skip!(:create)
21
+
22
+ sign_in(user) and visit(new_resource_path)
23
+
24
+ before = { count: resource_class.count, url: page.current_url }
25
+
26
+ within("form#new_#{resource_name}") do
27
+ fill_form(resource_attributes)
28
+ submit_form
29
+ end
30
+
31
+ after = { count: resource_class.count, url: page.current_url }
32
+
33
+ refute_equal before[:count], after[:count], "unable to create #{resource_class} object"
34
+ refute_equal before[:url], after[:url], "unable to create #{resource_class} object"
35
+ end
36
+
37
+ define_method 'test_bot: #create invalid' do
38
+ should_skip!(:create)
39
+
40
+ sign_in(user) and visit(new_resource_path)
41
+ before = { count: resource_class.count, url: page.current_url }
42
+
43
+ within("form#new_#{resource_name}") do
44
+ submit_form # Submit an empty form
45
+ end
46
+
47
+ after = { count: resource_class.count, url: page.current_url }
48
+
49
+ assert_equal before[:count], after[:count], 'unexpectedly created object anyway'
50
+ assert_equal before[:url], after[:url], 'did not return to #new action'
51
+ assert_page_title :any, 'page title missing after failed validation'
52
+ end
53
+
54
+ define_method 'test_bot: #edit' do
55
+ should_skip!(:edit) and sign_in(user) and (resource = create_resource!)
56
+
57
+ visit(edit_resource_path(resource))
58
+
59
+ assert_page_status
60
+ assert_page_title
61
+
62
+ # Make sure there's a form with a submit button
63
+ form_selector = "form#edit_#{resource_name}_#{resource.id}"
64
+
65
+ assert_selector form_selector, "page does not contain a form with selector #{form_selector}"
66
+ within(form_selector) do
67
+ assert_selector 'input[type=submit]', 'page form does not contain a submit button'
68
+ end
69
+ end
70
+
71
+ define_method 'test_bot: #update valid' do
72
+ should_skip!(:update) and sign_in(user) and (resource = create_resource!)
73
+
74
+ visit(edit_resource_path(resource))
75
+
76
+ before = { count: resource_class.count, url: page.current_url, updated_at: (resource.updated_at rescue nil) }
77
+
78
+ within("form#edit_#{resource_name}_#{resource.id}") do
79
+ fill_form(resource_attributes)
80
+ submit_form
81
+ end
82
+ resource = resource_class.find(resource.id)
83
+
84
+ after = { count: resource_class.count, url: page.current_url, updated_at: (resource.updated_at rescue nil) }
85
+
86
+ assert_equal before[:count], after[:count], "updating resource unexpectedly changed #{resource_class}.count"
87
+ assert(after[:updated_at] > before[:updated_at], "failed to update resource") if resource.respond_to?(:updated_at)
88
+ end
89
+
90
+ define_method 'test_bot: #update invalid' do
91
+ should_skip!(:update) and sign_in(user) and (resource = create_resource!)
92
+
93
+ visit(edit_resource_path(resource))
94
+
95
+ before = { count: resource_class.count, url: page.current_url, updated_at: (resource.updated_at rescue nil) }
96
+
97
+ within("form#edit_#{resource_name}_#{resource.id}") do
98
+ clear_form
99
+ submit_form
100
+ end
101
+ resource = resource_class.find(resource.id)
102
+
103
+ after = { count: resource_class.count, url: page.current_url, updated_at: (resource.updated_at rescue nil) }
104
+
105
+ assert_equal before[:count], after[:count], "updating resource unexpectedly changed #{resource_class}.count"
106
+ assert_equal(after[:updated_at], before[:updated_at], 'unexpectedly updated object anyway') if resource.respond_to?(:updated_at)
107
+ assert_equal before[:url], after[:url], 'did not return to #edit action'
108
+ assert_page_title :any, 'page title missing after failed validation'
109
+ end
110
+
111
+ define_method 'test_bot: #index' do
112
+ should_skip!(:index) and sign_in(user) and (resource = create_resource!)
113
+
114
+ visit resources_path
115
+
116
+ assert_page_status
117
+ assert_page_title
118
+ end
119
+
120
+ define_method 'test_bot: #show' do
121
+ should_skip!(:show) and sign_in(user) and (resource = create_resource!)
122
+
123
+ visit resource_path(resource)
124
+
125
+ assert_page_status
126
+ assert_page_title
127
+ end
128
+
129
+ define_method 'test_bot: #destroy' do
130
+ should_skip!(:destroy) and sign_in(user) and (resource = create_resource!)
131
+
132
+ before = { count: resource_class.count, archived: (resource.archived rescue nil) }
133
+
134
+ visit_delete(resource_path(resource), user)
135
+
136
+ after = { count: resource_class.count, archived: (resource_class.find(resource.id).archived rescue nil) }
137
+
138
+ if resource.respond_to?(:archived)
139
+ assert after[:archived] == true, "expected #{resource_class}.archived == true"
140
+ else
141
+ assert(false, "Unable to delete #{resource_class}") if before[:count] == after[:count]
142
+ end
143
+ end
144
+
145
+ protected
146
+
147
+ def should_skip!(action)
148
+ skip('skipped') unless crud_actions_to_test.include?(action)
149
+ true
150
+ end
151
+
152
+ def create_resource!
153
+ visit(new_resource_path)
154
+
155
+ within("form#new_#{resource_name}") do
156
+ fill_form(resource_attributes) and submit_form
157
+ end
158
+
159
+ refute_equal new_resource_path, page.current_url
160
+ resource_class.last
161
+ end
162
+
163
+ private
164
+
165
+ def resources_path # index, create
166
+ polymorphic_path([*controller_namespace, resource_class])
167
+ end
168
+
169
+ def resource_path(resource) # show, update, destroy
170
+ polymorphic_path([*controller_namespace, resource])
171
+ end
172
+
173
+ def new_resource_path # new
174
+ new_polymorphic_path([*controller_namespace, resource])
175
+ end
176
+
177
+ def edit_resource_path(resource) # edit
178
+ edit_polymorphic_path([*controller_namespace, resource])
179
+ end
180
+
181
+ 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.0.10
4
+ version: 0.2.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-18 00:00:00.000000000 Z
11
+ date: 2015-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: capybara-slow_finder_errors
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: shoulda
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -189,28 +203,23 @@ files:
189
203
  - MIT-LICENSE
190
204
  - README.md
191
205
  - Rakefile
192
- - app/helpers/effective_test_bot_helper.rb
193
206
  - lib/effective_test_bot.rb
194
207
  - lib/effective_test_bot/engine.rb
195
208
  - lib/effective_test_bot/version.rb
196
209
  - lib/generators/effective_test_bot/install_generator.rb
197
210
  - lib/generators/templates/effective_test_bot.rb
198
- - lib/generators/templates/minitest/test_helper.rb
199
- - lib/generators/templates/rspec/rails_helper.rb
200
- - lib/generators/templates/rspec/spec_helper.rb
211
+ - lib/generators/templates/test_helper.rb
201
212
  - lib/tasks/effective_test_bot_tasks.rake
202
- - spec/features/crud/crud_spec.rb
203
- - spec/features/devise/sign_in_spec.rb
204
- - spec/features/devise/sign_up_spec.rb
205
- - spec/features/home_page_spec.rb
206
- - spec/models/user_spec.rb
207
- - test/fixtures/users.yml
208
- - test/test_bot/integration/devise/sign_in_test.rb
209
- - test/test_bot/integration/devise/sign_up_test.rb
213
+ - test/concerns/acts_as_test_botable.rb
214
+ - test/support/effective_test_bot_assertions.rb
215
+ - test/support/effective_test_bot_form_helper.rb
216
+ - test/support/effective_test_bot_login_helper.rb
217
+ - test/support/effective_test_bot_test_helper.rb
218
+ - test/test_bot/integration/devise_test.rb
210
219
  - test/test_bot/integration/home_page_test.rb
211
220
  - test/test_bot/integration/minitest_test.rb
212
- - test/test_bot/models/database_test.rb
213
221
  - test/test_bot/models/user_test.rb
222
+ - test/test_botable/crud_test.rb
214
223
  homepage: https://github.com/code-and-effect/effective_test_bot
215
224
  licenses:
216
225
  - MIT