effective_test_bot 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +225 -55
- data/lib/effective_test_bot.rb +12 -2
- data/lib/effective_test_bot/version.rb +1 -1
- data/lib/generators/effective_test_bot/install_generator.rb +4 -5
- data/lib/generators/templates/effective_test_bot.rb +1 -1
- data/lib/tasks/effective_test_bot_tasks.rake +8 -6
- data/test/support/effective_test_bot_assertions.rb +20 -0
- data/test/support/effective_test_bot_form_filler.rb +26 -5
- data/test/support/effective_test_bot_form_helper.rb +2 -1
- data/test/support/effective_test_bot_login_helper.rb +5 -3
- data/test/test_bot/integration/environment_test.rb +38 -15
- 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: 050059046b219c8b63e06bed237a2af8330bbd74
|
4
|
+
data.tar.gz: 5ab3fb4a52857df4f5a158207fdc16f5fb5eccc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 153ff53a0aaea5cdc8df869c479cb6202e2bc422713cb9bc278ec704d233e8aac52faf58a4b98b7f601a2d268127b58d9805f8a57f967fbaecb2aa047c6680d1
|
7
|
+
data.tar.gz: 6ef150344ff12ace02a5717611b8f537540061653141d375ed5c79ddad6f69f87b3b7d8669d4ba639582d9bfc8ff94cad51c10322e693b57f0ca9f55c9dd9fc0
|
data/README.md
CHANGED
@@ -1,18 +1,37 @@
|
|
1
1
|
# Effective TestBot
|
2
2
|
|
3
|
-
|
3
|
+
Stop testing and start test botting.
|
4
4
|
|
5
|
-
|
5
|
+
A minitest library of capybara-webkit based feature tests that should pass in every Ruby on Rails application.
|
6
6
|
|
7
|
-
|
7
|
+
Adds many additional minitest assertions and capybara quality of life helper functions.
|
8
8
|
|
9
|
+
Provides a curated set of minitest/capybara/rails testing gems and a well configured `test_helper.rb` minitest file.
|
10
|
+
|
11
|
+
Includes a rake task to validate your testing environment.
|
12
|
+
|
13
|
+
Ensures that all fixtures and seeds are properly initialized. Makes sure database transactions and web sessions correctly reset between tests.
|
14
|
+
|
15
|
+
Provides a DSL of class and instance level 1-liners that run entire test suites, checking many assertions all at once.
|
16
|
+
|
17
|
+
Autosaves an animated gif for any failing test.
|
18
|
+
|
19
|
+
Run `rake test:bot` to automatically check every route in your application against an appropriate test suite, without writing any code.
|
20
|
+
|
21
|
+
Automatically fills forms with appropriate pseudo-random input, and checks for all kinds of errors and omissions along the way.
|
22
|
+
|
23
|
+
Turn on tour mode to automatically generate animated gifs of every part of your website.
|
24
|
+
|
25
|
+
Makes sure everything actually works.
|
9
26
|
|
10
27
|
## Getting Started
|
11
28
|
|
12
|
-
|
29
|
+
Make sure your site is using [devise](https://github.com/plataformatec/devise) and that your application javascript includes [jQuery](http://jquery.com/) and rails' [jquery_ujs](https://github.com/rails/jquery-ujs).
|
13
30
|
|
14
31
|
```ruby
|
15
|
-
|
32
|
+
group :test do
|
33
|
+
gem 'effective_test_bot'
|
34
|
+
end
|
16
35
|
```
|
17
36
|
|
18
37
|
Run the bundle command to install it:
|
@@ -21,99 +40,250 @@ Run the bundle command to install it:
|
|
21
40
|
bundle install
|
22
41
|
```
|
23
42
|
|
24
|
-
|
43
|
+
Install the configuration file:
|
25
44
|
|
26
|
-
```
|
45
|
+
```console
|
27
46
|
rails generate effective_test_bot:install
|
28
47
|
```
|
29
48
|
|
30
|
-
The
|
49
|
+
The generator will run `minitest:install` if minitest is not already present and create an initializer file which describes all configuration options.
|
50
|
+
|
51
|
+
Fixture or seed one user:
|
31
52
|
|
32
|
-
|
53
|
+
effective_test_bot requires that at least one user -- ideally a fully priviledged admin type user -- be available in the testing environment.
|
33
54
|
|
34
|
-
|
55
|
+
* There are future plans to make this better. Right now `rake test:bot` just runs everything as one user. There really isn't support for 'this user should not be able to'. yet.
|
56
|
+
|
57
|
+
As per the `test/test_helper.rb` default file, when minitest and/or effective_test_bot starts, following tasks are run:
|
35
58
|
|
36
59
|
```ruby
|
37
|
-
|
38
|
-
|
60
|
+
# Rails default task, load fixtures from test/fixtures/*.yml (including users.yml if it exists)
|
61
|
+
rake db:fixtures:load
|
62
|
+
|
63
|
+
# Rails default task, loads db/seeds.rb
|
64
|
+
rake db:seed
|
65
|
+
|
66
|
+
# Added by effective_test_bot. loads test/fixtures/seeds.rb. 'cause screw yaml.
|
67
|
+
rake test:load_fixture_seeds
|
39
68
|
```
|
40
69
|
|
41
|
-
|
70
|
+
Your initial user may be created by any of the above 3 tasks.
|
42
71
|
|
43
|
-
|
72
|
+
Test that your testing environment is set up correctly:
|
44
73
|
|
45
|
-
|
74
|
+
Run `rake test:bot:environment` and make sure all the tests pass.
|
46
75
|
|
47
|
-
|
76
|
+
You now have effective_test_bot configured and you're ready to go.
|
48
77
|
|
49
|
-
|
78
|
+
# How to use this gem
|
50
79
|
|
51
|
-
TestBot
|
80
|
+
Effective TestBot is a 3-layered cake of testing deliciousness.
|
52
81
|
|
53
|
-
|
54
|
-
rake test:bot TEST=posts#index
|
55
|
-
rake test:bot TEST=
|
82
|
+
The bottom layer consists of advanced individual minitest assertions and capybara quality of life helper functions.
|
56
83
|
|
57
|
-
|
58
|
-
Definign TEST= works with test names 'documents#new' or 'documents' or 'something_path' but not with 'flash' assertions
|
84
|
+
The middle layer is a meta testing DSL -- 1-liners for you to use in your regular minitest tests that run entire test suites (10-50+ assertions) against a page or controller.
|
59
85
|
|
86
|
+
The final layer builds on the bottom two, run `rake test:bot` to scan every route in your application and choose an appropriate test suite to run.
|
60
87
|
|
61
|
-
|
62
|
-
# 'flash',
|
63
|
-
# 'users#show',
|
64
|
-
# 'users#create_invalid' => ['path', 'page_title'],
|
65
|
-
# 'users#create_invalid' => 'no_unpermitted_params',
|
66
|
-
# 'report_total_allocation_index_path'
|
67
|
-
# 'documents#destroy flash'
|
68
|
-
# ]
|
88
|
+
## Minitest Assertions
|
69
89
|
|
90
|
+
The following assertions are added for use in any minitest & capybara integration test:
|
70
91
|
|
71
|
-
|
92
|
+
- `assert_signed_in` visits the devise `new_user_session_path` and checks for the `devise.failure.already_authenticated` content
|
93
|
+
- `assert_signed_out` visits the devise `new_user_session_path` and checks for absense of the `devise.failure.already_authenticated` content
|
94
|
+
- `assert_page_title` makes sure there is an html <title></title> present
|
95
|
+
- `assert_submit_input` makes sure there is an input[type='submit'] present
|
96
|
+
- `assert_page_status` checks for a given http status, default 200.
|
97
|
+
- `assert_current_path(path)` asserts the current page path
|
98
|
+
- `assert_redirect(from_path)` optionally with to_path, makes sure the current page path is not from_path
|
99
|
+
- `assert_no_js_errors` - checks for any javascript errors on the page
|
100
|
+
- `assert_no_unpermitted_params` makes sure the last submitted form did not include any unpermitted params and prints out any unpermitted params that do exist.
|
101
|
+
- `assert_no_exceptions` checks for any exceptions in the last page request and gives a stacktrace if there was
|
102
|
+
- `assert_no_html_form_validation_errors` checks for frontend html5 errors
|
103
|
+
- `assert_jquery_ujs_disable_with` makes sure all input[type=submit] elements on the page have the data-disable-with property set
|
104
|
+
- `assert_flash` optionally with the desired :success, :error key and/or message, makes sure the flash is set
|
105
|
+
- `assert_assigns` asserts a given rails view_assigns object is present
|
106
|
+
- `assert_no_assigns_errors` use after a form submit to make sure your assigned rails object has no errors. Prints out any errors if they exist.
|
107
|
+
- `assert_assigns_errors` use after an intentionally invalid form submit to make sure your assigned rails object has errors, or a specific error.
|
72
108
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
109
|
+
## Capybara Extras
|
110
|
+
|
111
|
+
The following quality of life helpers are added for use in any minitest & capybara integration test:
|
112
|
+
|
113
|
+
### fill_form
|
114
|
+
|
115
|
+
Finds all the input, select and textarea form fields on the current page and fills them with pseudo-random appropriate values.
|
116
|
+
|
117
|
+
Detects names, addresses, start and end dates, telephone numbers, postal and zip codes, file, price, email, numeric, password and password confirmation fields. Probably more.
|
118
|
+
|
119
|
+
Will only fill visible fields that are currently visible and not disabled.
|
120
|
+
|
121
|
+
If a selection made in one field changes the visibility/disabled of fields later in the form, those fields will be properly filled.
|
78
122
|
|
123
|
+
It works with the [cocoon](https://github.com/nathanvda/cocoon), [select2](https://select2.github.io/) and [effective_assets](https://github.com/code-and-effect/effective_assets) gems.
|
124
|
+
|
125
|
+
It will click through bootstrap tabs and fill them left-to-right one tab at a time.
|
126
|
+
|
127
|
+
You can pass a Hash of 'fills' to specify specific input values:
|
128
|
+
|
129
|
+
```ruby
|
79
130
|
require 'test_helper'
|
80
131
|
|
81
|
-
class
|
82
|
-
|
132
|
+
class PostTest < ActionDispatch::IntegrationTest
|
133
|
+
test 'creating a new post' do
|
134
|
+
visit new_post_path
|
135
|
+
fill_form(:title => 'A Cool Post', 'author.last_name' => 'Smith')
|
136
|
+
submit_form
|
137
|
+
end
|
83
138
|
end
|
139
|
+
```
|
140
|
+
|
141
|
+
And you can disable specific fields from being filled, by modifying the input html in your normal view:
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
= f.input :too_complicated, 'data-test-bot-skip' => true
|
145
|
+
```
|
146
|
+
|
147
|
+
Sometimes you have the requirement that inputs add upto a certain number. For example, having to provide percentages in 3-4 input fields that always add upto 100%.
|
148
|
+
|
149
|
+
You can use the html `min` and `max` properties to indicate this requirement.
|
150
|
+
|
151
|
+
The `min` and `max` html properties are considered when filling in any numeric field -- the fill value will always be within the specified range.
|
152
|
+
|
153
|
+
If there are 2 or more numeric inputs that end with the same jquery selector, the fields will be filled so that their sum will match the html `max` value.
|
154
|
+
|
155
|
+
You can scope the fill_form to a particular area of the page by using the regular capybara `within` `do..end` block
|
156
|
+
|
157
|
+
### submit_form
|
158
|
+
|
159
|
+
As well as just click on the `input[type='submit']` button (or optional label), this helper also checks:
|
160
|
+
- `assert_no_html5_form_validation_errors`
|
161
|
+
- `assert_jquery_ujs_disable_with`
|
162
|
+
- `assert_no_unpermitted_params`
|
163
|
+
|
164
|
+
### other helpers
|
165
|
+
|
166
|
+
- `submit_novalidate_form` will use javascript to disable all required fields, and submit a form without client side validation.
|
167
|
+
- `clear_form` clears all form fields, probably used before `submit_novalidate_form` to test invalid form submissions.
|
168
|
+
- `sign_in(user)` optionally with user, signs in via `Warden::Test::Helpers` hacky login skipping method.
|
169
|
+
- `sign_in_manually(user, password)` visits the devise `new_user_session_path` and signs in via the form
|
170
|
+
- `sign_up` visits the devise `new_user_registration_path` and signs up as a new user.
|
171
|
+
- `as_user(user) do .. end` yields a block between `sign_in`, and `logout`
|
172
|
+
- `synchronize!` should fix any timing issues waiting for capybara elements
|
173
|
+
- `was_redirect?` returns true/false if the last time we changed pages was a 304 redirect.
|
174
|
+
- `was_download?` if clicking a link returned a file of any type rather than a page change.
|
175
|
+
|
176
|
+
## Capybara Super Extras
|
177
|
+
|
178
|
+
So the problem with running integration tests with capybara-webkit is that it's a real full black-box integration test.
|
179
|
+
|
180
|
+
Capybara runs in a totally separate process. It knows nothing about your rails app. You can't get access to any of the rails internal state. All you can test is html, javascript and urls. That really sucks.
|
84
181
|
|
182
|
+
effective_test_bot mixes in a rails controller include and does a bit of http header hackery to make available to capybara the internal rails state values that are just so handy.
|
183
|
+
|
184
|
+
The following are refreshed on each page change, and are available to check anywhere in your tests.
|
185
|
+
|
186
|
+
- `flash` a Hash representation of the current page's flash
|
187
|
+
- `assigns` a Hash representation of the current page's rails `view_assigns`. Serializes any ActiveRecord objects, as well as any TrueClass, FalseClass, NilClass, String, Symbol, Numeric objects. Does not serialize anything else, but sets a symbol `assigns[key] == :present_but_not_serialized`.
|
188
|
+
- `exceptions` an Array with the exception message and a stacktrace.
|
189
|
+
- `unpermitted_params` an Array of any unpermitted paramaters that were encountered by the last request
|
190
|
+
|
191
|
+
- `save_test_bot_screenshot` saves a screenshot of the current page to be added to the current test's animated gif (see screenshots and tour mode below).
|
192
|
+
|
193
|
+
## Test Bot DSL Methods
|
194
|
+
|
195
|
+
All of the following DSL methods use the assertions and capybara extras to build an entire test suite that runs against a given page or controller action.
|
196
|
+
|
197
|
+
Right now the `crud_test` method is by far the most mature, with the other methods having had less development time.
|
198
|
+
|
199
|
+
Each DSL method has a class level `x_test` and an instance level `x_action_test` version of each.
|
200
|
+
|
201
|
+
```ruby
|
85
202
|
require 'test_helper'
|
86
203
|
|
87
|
-
class
|
88
|
-
page_test(:
|
89
|
-
page_test(:user_settings_path, User.first)
|
90
|
-
page_test(:user_settings_path, User.first)
|
91
|
-
crud_test(Physician, User.first, except: :show)
|
92
|
-
crud_test('physicians', User.first, except: :show)
|
204
|
+
class PostsTest < ActionDispatch::IntegrationTest
|
205
|
+
page_test(:posts_path, User.first) # Runs the page_test test suite against posts_path (class level) as User.first
|
93
206
|
|
94
|
-
|
95
|
-
|
207
|
+
# Does the same thing.
|
208
|
+
# Runs the page_test suite against posts_path (instance level) as User.first
|
209
|
+
test 'my posts test' do
|
210
|
+
page_action_test(:posts_path, User.first)
|
96
211
|
end
|
97
212
|
end
|
213
|
+
```
|
98
214
|
|
215
|
+
### Skipping assertions and tests
|
99
216
|
|
100
|
-
|
217
|
+
Each of these DSL test suite methods are designed to assert an expected standard rails behaviour.
|
101
218
|
|
219
|
+
But sometimes a developer has a good reason for deviating from what is considered standard; therefore, each individual assertion is skippable.
|
102
220
|
|
221
|
+
When an assertion fails, the minitest output will look something like:
|
103
222
|
|
223
|
+
```console
|
224
|
+
crud_test: (users#update_invalid) FAIL (3.74s)
|
104
225
|
|
105
|
-
|
226
|
+
Minitest::Assertion: (path) Expected current_path to match resource #update path.
|
227
|
+
Expected: "/users/562391275"
|
228
|
+
Actual: "/members/562391275"
|
229
|
+
/Users/matt/Sites/effective_test_bot/test/test_botable/crud_test.rb:155:in `test_bot_update_invalid_test'
|
230
|
+
```
|
106
231
|
|
107
|
-
|
232
|
+
The `(path)` is the name of the specific assertion that failed.
|
233
|
+
|
234
|
+
The expectation is that when submitting an invalid form at `/users/562391275/edit` we should be returned to the update action url `/users/562391275`, but in this totally reasonable but not-standard case we are redirected to `/members/562391275` instead.
|
108
235
|
|
109
|
-
|
236
|
+
You can skip this specific assertion by adding it to the `app/config/initializers/effective_test_bot.rb` file:
|
110
237
|
|
111
|
-
```
|
112
|
-
|
113
|
-
|
114
|
-
|
238
|
+
```ruby
|
239
|
+
EffectiveTestBot.setup do |config|
|
240
|
+
config.except = [
|
241
|
+
'users#create_invalid path', # Skips the path assertion for just the users#create_invalid test
|
242
|
+
'path' # Skips the path assertion entirely in all tests
|
243
|
+
]
|
244
|
+
end
|
115
245
|
```
|
116
246
|
|
247
|
+
There is support for skipping individual assertions as well as entire tests.
|
248
|
+
|
249
|
+
Please see the installed effective_test_bot.rb initializer file for a full description of all options.
|
250
|
+
|
251
|
+
### crud_test
|
252
|
+
|
253
|
+
TODO
|
254
|
+
|
255
|
+
### devise_test
|
256
|
+
|
257
|
+
TODO
|
258
|
+
|
259
|
+
### page_test
|
260
|
+
|
261
|
+
TODO
|
262
|
+
|
263
|
+
### member_test
|
264
|
+
|
265
|
+
TODO
|
266
|
+
|
267
|
+
### redirect_test
|
268
|
+
|
269
|
+
TODO
|
270
|
+
|
271
|
+
### wizard_test
|
272
|
+
|
273
|
+
TODO
|
274
|
+
|
275
|
+
## Automated Testing / Rake tasks
|
276
|
+
|
277
|
+
TODO
|
278
|
+
|
279
|
+
## Screenshots and Animated Gifs
|
280
|
+
|
281
|
+
TODO
|
282
|
+
|
283
|
+
### Tour mode
|
284
|
+
|
285
|
+
TODO
|
286
|
+
|
117
287
|
|
118
288
|
## License
|
119
289
|
|
data/lib/effective_test_bot.rb
CHANGED
@@ -7,6 +7,7 @@ module EffectiveTestBot
|
|
7
7
|
mattr_accessor :screenshots
|
8
8
|
mattr_accessor :autosave_animated_gif_on_failure
|
9
9
|
mattr_accessor :tour_mode
|
10
|
+
mattr_accessor :tour_mode_extreme
|
10
11
|
mattr_accessor :animated_gif_delay
|
11
12
|
mattr_accessor :animated_gif_background_color
|
12
13
|
|
@@ -60,11 +61,20 @@ module EffectiveTestBot
|
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
64
|
+
# form_filler will take a screenshot after every form field is filled
|
65
|
+
def self.tour_mode_extreme?
|
66
|
+
if ENV['TOUR'].present?
|
67
|
+
['extreme', 'debug'].include?(ENV['TOUR'].to_s.downcase)
|
68
|
+
else
|
69
|
+
screenshots && ['extreme', 'debug'].include?(tour_mode.to_s)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
63
73
|
def self.tour_mode_verbose?
|
64
74
|
if ENV['TOUR'].present?
|
65
|
-
['verbose', 'debug'].include?(ENV['TOUR'].to_s.downcase)
|
75
|
+
['extreme', 'verbose', 'debug'].include?(ENV['TOUR'].to_s.downcase)
|
66
76
|
else
|
67
|
-
screenshots && ['verbose', 'debug'].include?(tour_mode.to_s)
|
77
|
+
screenshots && ['extreme', 'verbose', 'debug'].include?(tour_mode.to_s)
|
68
78
|
end
|
69
79
|
end
|
70
80
|
|
@@ -22,9 +22,7 @@ module EffectiveTestBot
|
|
22
22
|
puts "files with those packaged inside the effective_test_bot gem."
|
23
23
|
puts ""
|
24
24
|
puts "If you have very specific existing minitest configuration,"
|
25
|
-
puts "you
|
26
|
-
puts "and refer to the GitHub documentation for this gem:"
|
27
|
-
puts "https://github.com/code-and-effect/effective_test_bot"
|
25
|
+
puts "you should ensure it's under version control so you can revert if needed"
|
28
26
|
puts ""
|
29
27
|
puts "Otherwise, press 'Y' to all the following prompts to automatically configure"
|
30
28
|
puts "minitest-rails and capybara-webkit based effective_test_bot test coverage"
|
@@ -41,8 +39,9 @@ module EffectiveTestBot
|
|
41
39
|
|
42
40
|
def thank_you
|
43
41
|
puts "Thanks for using EffectiveTestBot"
|
44
|
-
puts "
|
45
|
-
puts "Run
|
42
|
+
puts "Make sure you create a user in your db/seeds.rb, test/fixtures/users.yml, or test/fixtures/seeds.rb"
|
43
|
+
puts "Run `rake test:bot:environment` once to ensure the testing environment is correctly configured"
|
44
|
+
puts "Test your app with 'rake test:bot'"
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
@@ -39,7 +39,7 @@ if Rails.env.test?
|
|
39
39
|
# 100 equals 1 second. (a bit on the slow side, but suitable for a demo)
|
40
40
|
config.animated_gif_delay = 100
|
41
41
|
|
42
|
-
# Shorter than maximum height
|
42
|
+
# Shorter than maximum height animated gif frames have their
|
43
43
|
# bottom area filled by this color
|
44
44
|
# For best appearance, have this match your site's background color
|
45
45
|
config.animated_gif_background_color = 'white'
|
@@ -67,6 +67,14 @@ namespace :test do
|
|
67
67
|
end
|
68
68
|
end # /namespace bot
|
69
69
|
|
70
|
+
desc 'loads test/fixtures/seeds.rb'
|
71
|
+
task :load_fixture_seeds => :environment do
|
72
|
+
seeds = "#{Rails.root}/test/fixtures/seeds.rb"
|
73
|
+
load(seeds) if File.exists?(seeds)
|
74
|
+
end
|
75
|
+
|
76
|
+
# This ensures rake test:prepare is run before rake test:bot or rake test:bot:environment run
|
77
|
+
# Test files stuff is minitest hackery to just load the 1 test file
|
70
78
|
Rails::TestTask.new('effective_test_bot' => 'test:prepare') do |t|
|
71
79
|
t.libs << 'test'
|
72
80
|
t.test_files = FileList["#{File.dirname(__FILE__)}/../../test/test_bot/integration/application_test.rb"]
|
@@ -77,10 +85,4 @@ namespace :test do
|
|
77
85
|
t.test_files = FileList["#{File.dirname(__FILE__)}/../../test/test_bot/integration/environment_test.rb"]
|
78
86
|
end
|
79
87
|
|
80
|
-
desc 'loads test/fixtures/seeds.rb'
|
81
|
-
task :load_fixture_seeds => :environment do
|
82
|
-
seeds = "#{Rails.root}/test/fixtures/seeds.rb"
|
83
|
-
load(seeds) if File.exists?(seeds)
|
84
|
-
end
|
85
|
-
|
86
88
|
end
|
@@ -11,6 +11,26 @@ module EffectiveTestBotAssertions
|
|
11
11
|
assert page.has_selector?('form#new_user'), message || '(signed_out) Expected new_user form to be present'
|
12
12
|
end
|
13
13
|
|
14
|
+
def assert_capybara_can_execute_javascript(message = "Expected capybara-webkit page.evaluate_script() to be successful")
|
15
|
+
error = nil; result = nil;
|
16
|
+
|
17
|
+
begin
|
18
|
+
result = page.evaluate_script("var js = 'javascript'; js;")
|
19
|
+
rescue => e
|
20
|
+
error = e.message
|
21
|
+
end
|
22
|
+
|
23
|
+
assert (result == 'javascript'), "#{message}. Error was: #{error}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def assert_jquery_present(message = "Expected jquery ($.fn.jquery) to be present")
|
27
|
+
assert((page.evaluate_script('$.fn.jquery') rescue '').length > 0, message)
|
28
|
+
end
|
29
|
+
|
30
|
+
def assert_jquery_ujs_present(message = "Expected rails' jquery_ujs ($.rails) to be present")
|
31
|
+
assert((page.evaluate_script('$.rails') rescue '').length > 0, message)
|
32
|
+
end
|
33
|
+
|
14
34
|
def assert_page_title(title = :any, message = '(page_title) Expected page title to be present')
|
15
35
|
return if was_download? # If this was a download, it correctly won't have a page title
|
16
36
|
|
@@ -45,10 +45,18 @@ module EffectiveTestBotFormFiller
|
|
45
45
|
def fill_form_fields(fills = {})
|
46
46
|
fills = HashWithIndifferentAccess.new(fills) unless fills.kind_of?(HashWithIndifferentAccess)
|
47
47
|
|
48
|
+
save_test_bot_screenshot
|
49
|
+
|
48
50
|
# Support for the cocoon gem
|
49
51
|
all('a.add_fields[data-association-insertion-template]').each do |field|
|
50
52
|
next if skip_form_field?(field)
|
51
|
-
|
53
|
+
|
54
|
+
if EffectiveTestBot.tour_mode_extreme?
|
55
|
+
2.times { field.click(); save_test_bot_screenshot }
|
56
|
+
else
|
57
|
+
2.times { field.click() }
|
58
|
+
save_test_bot_screenshot
|
59
|
+
end
|
52
60
|
end
|
53
61
|
|
54
62
|
all('input,select,textarea', visible: false).each do |field|
|
@@ -60,11 +68,19 @@ module EffectiveTestBotFormFiller
|
|
60
68
|
field.set(value_for_field(field, fills))
|
61
69
|
when 'select'
|
62
70
|
if field['class'].to_s.include?('select2') # effective_select
|
63
|
-
|
64
|
-
|
71
|
+
if EffectiveTestBot.tour_mode_extreme?
|
72
|
+
page.execute_script("try { $('select##{field['id']}').select2('open'); } catch(e) {};")
|
73
|
+
save_test_bot_screenshot
|
74
|
+
end
|
65
75
|
end
|
66
76
|
|
67
77
|
field.select(value_for_field(field, fills), match: :first)
|
78
|
+
|
79
|
+
if field['class'].to_s.include?('select2') # effective_select
|
80
|
+
if EffectiveTestBot.tour_mode_extreme?
|
81
|
+
page.execute_script("try { $('select##{field['id']}').select2('close'); } catch(e) {};")
|
82
|
+
end
|
83
|
+
end
|
68
84
|
when 'input_file'
|
69
85
|
if field['class'].to_s.include?('asset-box-uploader-fileinput')
|
70
86
|
upload_effective_asset(field, value_for_field(field, fills))
|
@@ -78,8 +94,13 @@ module EffectiveTestBotFormFiller
|
|
78
94
|
raise "unsupported field type #{[field.tag_name, field['type']].compact.join('_')}"
|
79
95
|
end
|
80
96
|
|
81
|
-
|
97
|
+
if EffectiveTestBot.tour_mode_extreme?
|
98
|
+
save_test_bot_screenshot unless skip_field_screenshot
|
99
|
+
end
|
82
100
|
end
|
101
|
+
|
102
|
+
save_test_bot_screenshot
|
103
|
+
|
83
104
|
end
|
84
105
|
|
85
106
|
# Generates an appropriately pseudo-random value for the given field
|
@@ -241,7 +262,7 @@ module EffectiveTestBotFormFiller
|
|
241
262
|
within("#asset-box-input-#{uid}") do
|
242
263
|
within('.uploads') do
|
243
264
|
while (first('.upload').present? rescue false) do
|
244
|
-
save_test_bot_screenshot
|
265
|
+
save_test_bot_screenshot if EffectiveTestBot.tour_mode_extreme?
|
245
266
|
sleep(0.5)
|
246
267
|
end
|
247
268
|
end
|
@@ -9,12 +9,14 @@ module EffectiveTestBotLoginHelper
|
|
9
9
|
user.kind_of?(String) ? login_as(User.find_by_email!(user)) : login_as(user)
|
10
10
|
end
|
11
11
|
|
12
|
-
def sign_in_manually(
|
12
|
+
def sign_in_manually(user_or_email, password = nil)
|
13
13
|
visit new_user_session_path
|
14
14
|
|
15
|
+
email = (user_or_email.respond_to?(:email) ? user_or_email.email : user_or_email)
|
16
|
+
|
15
17
|
within('form#new_user') do
|
16
18
|
fill_form(email: email, password: password)
|
17
|
-
|
19
|
+
submit_novalidate_form
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
@@ -23,7 +25,7 @@ module EffectiveTestBotLoginHelper
|
|
23
25
|
|
24
26
|
within('form#new_user') do
|
25
27
|
fill_form(email: email, password: password, password_confirmation: password)
|
26
|
-
|
28
|
+
submit_novalidate_form
|
27
29
|
end
|
28
30
|
|
29
31
|
User.find_by_email(email)
|
@@ -7,7 +7,7 @@ module TestBot
|
|
7
7
|
|
8
8
|
let(:email) { 'unique@testbot.com' }
|
9
9
|
let(:password) { '!Password123' }
|
10
|
-
let(:
|
10
|
+
let(:username) { 'test_bot_user' }
|
11
11
|
|
12
12
|
def self.test_order
|
13
13
|
:alpha
|
@@ -18,20 +18,20 @@ module TestBot
|
|
18
18
|
end
|
19
19
|
|
20
20
|
test '02: all fixtures and seeds valid' do
|
21
|
+
tables = ActiveRecord::Base.connection.tables
|
22
|
+
|
21
23
|
ActiveRecord::Base.descendants.each do |model|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
rescue ActiveRecord::StatementInvalid
|
27
|
-
; # Not entirely sure why I'm getting this error
|
24
|
+
next unless (model.respond_to?(:table_name) && tables.include?(model.table_name))
|
25
|
+
|
26
|
+
(model.unscoped.all rescue []).each do |resource|
|
27
|
+
assert resource.valid?, "fixture or seed data is invalid (#{model.to_s} id=#{resource.id} #{resource.errors.full_messages.join(', ')})"
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
# I could remove this if sign_in checks for and creates a user with devise or not
|
33
33
|
test '03: at least one user is seeded' do
|
34
|
-
assert (User.
|
34
|
+
assert (User.count > 0), 'please create at least 1 seed or fixture user for effective_test_bot to function'
|
35
35
|
end
|
36
36
|
|
37
37
|
test '04: activerecord can create a user' do
|
@@ -43,37 +43,52 @@ module TestBot
|
|
43
43
|
assert_environment_normal
|
44
44
|
end
|
45
45
|
|
46
|
-
test '06: capybara can
|
46
|
+
test '06: capybara can execute javascript' do
|
47
|
+
visit root_path
|
48
|
+
assert_capybara_can_execute_javascript
|
49
|
+
end
|
50
|
+
|
51
|
+
test '07: jquery is present' do
|
52
|
+
visit root_path
|
53
|
+
assert_jquery_present
|
54
|
+
end
|
55
|
+
|
56
|
+
test '08: rails jquery_ujs is present' do
|
57
|
+
visit root_path
|
58
|
+
assert_jquery_ujs_present
|
59
|
+
end
|
60
|
+
|
61
|
+
test '09: capybara can sign up a user' do
|
47
62
|
user = sign_up()
|
48
|
-
assert user.kind_of?(User)
|
63
|
+
assert user.kind_of?(User), "expected to create a new user after submitting sign up form at #{new_user_registration_path}"
|
49
64
|
|
50
65
|
assert_equal (original_users_count + 1), User.count
|
51
66
|
assert_signed_in
|
52
67
|
end
|
53
68
|
|
54
|
-
test '
|
69
|
+
test '10: database and session have reset' do
|
55
70
|
assert_signed_out
|
56
71
|
assert_environment_normal
|
57
72
|
end
|
58
73
|
|
59
|
-
test '
|
74
|
+
test '11: capybara can login_as via warden test helper' do
|
60
75
|
create_user!
|
61
76
|
sign_in(email)
|
62
77
|
assert_signed_in
|
63
78
|
end
|
64
79
|
|
65
|
-
test '
|
80
|
+
test '12: database and session have reset' do
|
66
81
|
assert_signed_out
|
67
82
|
assert_environment_normal
|
68
83
|
end
|
69
84
|
|
70
|
-
test '
|
85
|
+
test '13: capybara can sign in manually' do
|
71
86
|
create_user!
|
72
87
|
sign_in_manually(email, password)
|
73
88
|
assert_signed_in
|
74
89
|
end
|
75
90
|
|
76
|
-
test '
|
91
|
+
test '14: database and session have reset' do
|
77
92
|
assert_signed_out
|
78
93
|
assert_environment_normal
|
79
94
|
end
|
@@ -88,5 +103,13 @@ module TestBot
|
|
88
103
|
assert assigns[:current_user].blank?, 'Expected current_user to be blank'
|
89
104
|
end
|
90
105
|
|
106
|
+
def create_user!
|
107
|
+
user = User.new(email: email, password: password, password_confirmation: password)
|
108
|
+
user.username = username if user.respond_to?('username=')
|
109
|
+
user.login = username if user.respond_to?('login=')
|
110
|
+
|
111
|
+
user.valid? ? user.save : user.save(validate: false)
|
112
|
+
end
|
113
|
+
|
91
114
|
end
|
92
115
|
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.
|
4
|
+
version: 0.4.7
|
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-
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|