capybara_turbolinks 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +70 -0
- data/Rakefile +6 -0
- data/app/assets/javascripts/capybara_turbolinks.coffee.erb +7 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/capybara_turbolinks.gemspec +35 -0
- data/lib/capybara_turbolinks.rb +3 -0
- data/lib/capybara_turbolinks/capybara.rb +45 -0
- data/lib/capybara_turbolinks/engine.rb +5 -0
- data/lib/capybara_turbolinks/version.rb +3 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 48092d0f36c8e4258b4460f8bd945430555df9ab
|
4
|
+
data.tar.gz: 857cb2e29975c63c0201375eb1cd7c68f1f93f0b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: baacb03171c79a8a5a7c9836061ad6a6fcd2af4fd034da77ff1651b1e93489e2c921992ed1016de196b289241f78bae3de1fc81738483b44a79bc2d09d2b8ecb
|
7
|
+
data.tar.gz: a535afd2859d72d549db5c256d5795823a3d07592ceec334a0c4b69e1e37c0c3070402206d3c3505b71ab86f20a785836e5a36763bf68b8d4980d74a96cdf303
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Brendan Asselstine
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Capybara Turbolinks
|
2
|
+
|
3
|
+
Extends Capybara with methods that mitigate race conditions introduced by Turbolinks caching.
|
4
|
+
|
5
|
+
Turbolinks is a page loading mechanism introduced in Rails 4. It's default behaviour is to cache pages on the client side, so that page loading appears extremely fast. This caching (and Turbolinks itself) can be problematic; the shopify team decided to [disable caching entirely](https://github.com/rails/turbolinks/issues/551). We decided to keep the page caching, because it was so fast. However, we experienced race conditions in our integration tests.
|
6
|
+
|
7
|
+
From a Capybara and integration test point of view, the caching is problematic because it loads the page twice; once with the cached page, and a second time with the actual page from the server.
|
8
|
+
|
9
|
+
This causes issues with integration tests that block until they see certain page content or selectors, because the integration tests continue before the *actual* page has been loaded from the server.
|
10
|
+
|
11
|
+
This gem's solution is to add a small amount of JavaScript code in the test environment that adds and removes classes to the body tag that correspond to the Turbolinks page lifecycle. This allows us to use Capybara #has_css? to block until we have detected that the Turbolinks request is complete.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'capybara_turbolinks'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install capybara_turbolinks
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
This gem extends Capybara by adding two additional methods:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
Capybara::Node::Actions#click_turbolink
|
35
|
+
```
|
36
|
+
|
37
|
+
and
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
Capybara::Node::Element#turboclick
|
41
|
+
```
|
42
|
+
|
43
|
+
When you are clicking a link that triggers turbolinks, you will need to use one of the above methods. For example:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
visit root_path
|
47
|
+
click_turbolink 'View all deals'
|
48
|
+
```
|
49
|
+
|
50
|
+
Or when you are finding an element to click on:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
visit root_path
|
54
|
+
find('a.all-deals').turboclick
|
55
|
+
```
|
56
|
+
|
57
|
+
## Development
|
58
|
+
|
59
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
60
|
+
|
61
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Loft47/capybara_turbolinks.
|
66
|
+
|
67
|
+
## License
|
68
|
+
|
69
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
70
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "capybara_turbolinks"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capybara_turbolinks/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "capybara_turbolinks"
|
8
|
+
spec.version = CapybaraTurbolinks::VERSION
|
9
|
+
spec.authors = ["Brendan Asselstine"]
|
10
|
+
spec.email = ["mail.asselstine@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Extends Capybara to elegantly handle Turbolinks}
|
13
|
+
spec.description = %q{This gem will help you ensure that your Capybara tests wait for Turbolinks to finish page loads.}
|
14
|
+
spec.homepage = "http://github.com/Loft47/capybara_turbolinks"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_runtime_dependency "capybara", ">= 2.4"
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec"
|
35
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'capybara'
|
2
|
+
|
3
|
+
module CapybaraTurbolinks
|
4
|
+
FETCH_CSS_SELECTOR='body.page--fetch'
|
5
|
+
COMPLETE_CSS_SELECTOR='body.page--complete'
|
6
|
+
|
7
|
+
module ::Capybara
|
8
|
+
module Node
|
9
|
+
module Actions
|
10
|
+
class_eval do
|
11
|
+
def click_turbolink(*args)
|
12
|
+
click_link(*args)
|
13
|
+
has_css? FETCH_CSS_SELECTOR
|
14
|
+
has_css? COMPLETE_CSS_SELECTOR
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
class Element < Base
|
19
|
+
class_eval do
|
20
|
+
def turboclick
|
21
|
+
click
|
22
|
+
session.has_css? FETCH_CSS_SELECTOR
|
23
|
+
session.has_css? COMPLETE_CSS_SELECTOR
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
class Session
|
29
|
+
class_eval do
|
30
|
+
define_method :click_turbolink do |*args, &block|
|
31
|
+
@touched = true
|
32
|
+
current_scope.send(:click_turbolink, *args, &block)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
module DSL
|
37
|
+
class_eval do
|
38
|
+
define_method :click_turbolink do |*args, &block|
|
39
|
+
page.send :click_turbolink, *args, &block
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capybara_turbolinks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brendan Asselstine
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capybara
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: This gem will help you ensure that your Capybara tests wait for Turbolinks
|
70
|
+
to finish page loads.
|
71
|
+
email:
|
72
|
+
- mail.asselstine@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- app/assets/javascripts/capybara_turbolinks.coffee.erb
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- capybara_turbolinks.gemspec
|
88
|
+
- lib/capybara_turbolinks.rb
|
89
|
+
- lib/capybara_turbolinks/capybara.rb
|
90
|
+
- lib/capybara_turbolinks/engine.rb
|
91
|
+
- lib/capybara_turbolinks/version.rb
|
92
|
+
homepage: http://github.com/Loft47/capybara_turbolinks
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata:
|
96
|
+
allowed_push_host: https://rubygems.org
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.4.5
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Extends Capybara to elegantly handle Turbolinks
|
117
|
+
test_files: []
|