capybara-slow_finder_errors 0.1.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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +100 -0
- data/Rakefile +2 -0
- data/capybara-slow_finder_errors.gemspec +21 -0
- data/lib/capybara/slow_finder_errors.rb +19 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ac8ff324327298695ce17961339c03d8c47649a
|
4
|
+
data.tar.gz: d255a4751b415d6d49d661c76025fd10805b2cd6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6a6fba191388f26e7a2ab41db205d7150e606cfbeb0ad3a4ee5544a30e2e9cc1cd15c2f9853a3bad74b9d10a2ca01ca8d75cf318be51e57cd09ec95b2bcdc4ac
|
7
|
+
data.tar.gz: 016d49c366165d7d2b7272acf7eea1cea53ac242f5ffddda2e0bf9b85eb78fe91f6b7257e681cc48ae20ac623ed4e3db8050814e9441d2b328ce2634954791ec
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Nick Gauthier
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Capybara::SlowFinderErrors
|
2
|
+
|
3
|
+
Raises an error when you use a capybara finder and it times out.
|
4
|
+
|
5
|
+
The goal of this gem is to aid in discovering errors in capybara usage to help speed up your test suite.
|
6
|
+
|
7
|
+
## Example
|
8
|
+
|
9
|
+
If you do:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
refute page.has_content?("An Error Occurred")
|
13
|
+
```
|
14
|
+
|
15
|
+
To make sure there's no error on the page, the full timeout will be reached because `has_content?` waits for the content to appear. The correct usage is:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
assert page.has_no_content?("An Error Occurred")
|
19
|
+
```
|
20
|
+
|
21
|
+
Which would evaluate quickly.
|
22
|
+
|
23
|
+
This gem will raise a `Capybara::SlowFinderError` whenever the first situation occurs. In fact, it raises the error any time a Capybara synchronized piece of code reaches a timeout.
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
Add this line to your application's Gemfile:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
gem 'capybara-slow_finder_errors'
|
31
|
+
```
|
32
|
+
|
33
|
+
And then execute:
|
34
|
+
|
35
|
+
$ bundle
|
36
|
+
|
37
|
+
Or install it yourself as:
|
38
|
+
|
39
|
+
$ gem install capybara-slow_finder_errors
|
40
|
+
|
41
|
+
## Usage
|
42
|
+
|
43
|
+
Run your test suite as usual. If you have any slow finders, you'll get a stack trace like this:
|
44
|
+
|
45
|
+
```
|
46
|
+
Capybara::SlowFinderError (Capybara::SlowFinderError)
|
47
|
+
/path/to/capybara-slow_finder_errors/lib/capybara/slow_finder_errors.rb:11:in `rescue in synchronize_with_timeout_error'
|
48
|
+
/path/to/capybara-slow_finder_errors/lib/capybara/slow_finder_errors.rb:7:in `synchronize_with_timeout_error'
|
49
|
+
./features/support/signed_in_user.rb:31:in `signed_in?'
|
50
|
+
./features/support/user_helper.rb:59:in `sign_in_as'
|
51
|
+
features/configuring_a_project.feature:6:in `Given I am signed in as "herbert@awesomestartup.com"'
|
52
|
+
|
53
|
+
execution expired (Timeout::Error)
|
54
|
+
/path/to/.gems/gems/poltergeist-1.5.1/lib/capybara/poltergeist/web_socket_server.rb:72:in `select'
|
55
|
+
/path/to/.gems/gems/poltergeist-1.5.1/lib/capybara/poltergeist/web_socket_server.rb:72:in `receive'
|
56
|
+
/path/to/.gems/gems/poltergeist-1.5.1/lib/capybara/poltergeist/web_socket_server.rb:85:in `send'
|
57
|
+
/path/to/.gems/gems/poltergeist-1.5.1/lib/capybara/poltergeist/server.rb:33:in `send'
|
58
|
+
/path/to/.gems/gems/poltergeist-1.5.1/lib/capybara/poltergeist/browser.rb:270:in `command'
|
59
|
+
/path/to/.gems/gems/poltergeist-1.5.1/lib/capybara/poltergeist/browser.rb:106:in `evaluate'
|
60
|
+
/path/to/.gems/gems/poltergeist-1.5.1/lib/capybara/poltergeist/driver.rb:130:in `evaluate_script'
|
61
|
+
/path/to/.gems/gems/capybara-2.4.4/lib/capybara/session.rb:527:in `evaluate_script'
|
62
|
+
...
|
63
|
+
```
|
64
|
+
|
65
|
+
If you look at the lines below the gem's trace, you'll see that the slow finder is in `signed_in_user.rb` on line 31 in the `signed_in?` method. Just follow those traces and clean up your code!
|
66
|
+
|
67
|
+
## Common Fixes
|
68
|
+
|
69
|
+
This section will hopefully grow as people contribute common situations and fixes.
|
70
|
+
|
71
|
+
### Inverted Finder
|
72
|
+
|
73
|
+
Replace `refute page.has_content?("abc")` with `assert page.has_no_content?("abc")`.
|
74
|
+
|
75
|
+
### Boolean Finder
|
76
|
+
|
77
|
+
A method that returns a boolean shouldn't use a waiting finder. So:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
def signed_in?
|
81
|
+
page.has_content?("Sign out")
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
Returns true if they are signed in, but it waits a full timeout before returning false. Instead, perform a waiting finder for content that is always present (to ensure the page is loaded) then use a quick finder that doesn't wait:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
def signed_in?
|
89
|
+
page.has_content?("Dashboard")
|
90
|
+
page.all('a', :text => 'Home').any?
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
## Contributing
|
95
|
+
|
96
|
+
1. Fork it `https://github.com/ngauthier/capybara-slow_finder_errors/fork`
|
97
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
98
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
99
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
100
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "capybara-slow_finder_errors"
|
5
|
+
spec.version = "0.1.0"
|
6
|
+
spec.authors = ["Nick Gauthier"]
|
7
|
+
spec.email = ["ngauthier@gmail.com"]
|
8
|
+
spec.summary = %q{Raises an error when you use a Capybara finder improperly}
|
9
|
+
spec.description = %q{If you use a finder that reaches capybara's timeout, and error is raised.}
|
10
|
+
spec.homepage = ""
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0")
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
19
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
20
|
+
spec.add_dependency "capybara", "~> 2.0"
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'capybara'
|
2
|
+
module Capybara
|
3
|
+
class SlowFinderError < CapybaraError; end
|
4
|
+
|
5
|
+
module Node
|
6
|
+
class Base
|
7
|
+
def synchronize_with_timeout_error(seconds=Capybara.default_wait_time, options = {}, &block)
|
8
|
+
start_time = Time.now
|
9
|
+
synchronize_without_timeout_error(seconds, options, &block)
|
10
|
+
rescue Capybara::ElementNotFound => e
|
11
|
+
if Time.now-start_time > seconds
|
12
|
+
raise SlowFinderError
|
13
|
+
end
|
14
|
+
end
|
15
|
+
alias_method :synchronize_without_timeout_error, :synchronize
|
16
|
+
alias_method :synchronize, :synchronize_with_timeout_error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capybara-slow_finder_errors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Gauthier
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: capybara
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
description: If you use a finder that reaches capybara's timeout, and error is raised.
|
56
|
+
email:
|
57
|
+
- ngauthier@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- capybara-slow_finder_errors.gemspec
|
68
|
+
- lib/capybara/slow_finder_errors.rb
|
69
|
+
homepage: ''
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.4.1
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Raises an error when you use a Capybara finder improperly
|
93
|
+
test_files: []
|