patientgeist 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +12 -0
- data/lib/patientgeist/client/browser_overrides.coffee +40 -0
- data/lib/patientgeist/client/compiled/browser_overrides.js +89 -0
- data/lib/patientgeist/client/compiled/main_overrides.js +26 -0
- data/lib/patientgeist/client/main_overrides.coffee +22 -0
- data/lib/patientgeist/client_override.rb +12 -0
- data/lib/patientgeist/version.rb +3 -0
- data/lib/patientgeist.rb +6 -0
- data/patientgeist.gemspec +26 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 32eb01f19ccf09b8cf59256273b11183a38ee338
|
4
|
+
data.tar.gz: 114f03ee841bb8d49d3bb807219b0885453b9b18
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 16d291a7fb137cf9f6e9d2bc202bd858bf9ffb81f2f559a028abe4534e3d8d4f0cc004ec6879b432089d99217070bb61fd7100796143c4e4a10b68eed795d1b2
|
7
|
+
data.tar.gz: 006593c5382072b000e4c6ceb86f181168a25509d61645ab43dd1d0a65e53bd16a3abff8fd66f4da04b7d04614e1b2947c39a377f6a1015a37a7e0e7934ae34e
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
patientgeist
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Christopher Erin
|
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,39 @@
|
|
1
|
+
# Patientgeist
|
2
|
+
|
3
|
+
Be patient when making ajax requests in poltergeist. Do not take the next action until the ajax request has been completed.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'patientgeist'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install patientgeist
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
click_button 'save'
|
23
|
+
wait_for_ajax
|
24
|
+
expect(find('#message')).to equal('saved')
|
25
|
+
```
|
26
|
+
|
27
|
+
Can now be:
|
28
|
+
```ruby
|
29
|
+
click_button 'save'
|
30
|
+
expect(find('#message')).to equal('saved')
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require 'coffee-script'
|
3
|
+
|
4
|
+
task :compile do
|
5
|
+
Dir.glob("lib/patientgeist/client/*.coffee").each do |f|
|
6
|
+
compiled = "lib/patientgeist/client/compiled/#{f.split("/").last.split(".").first}.js"
|
7
|
+
File.open(compiled, "w") do |out|
|
8
|
+
puts "Compiling #{f}"
|
9
|
+
out << CoffeeScript.compile(File.read(f), :bare => true)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class Poltergeist.Browser extends Poltergeist.Browser
|
2
|
+
constructor: (@owner, width, height) ->
|
3
|
+
originalResetFunc = this.resetPage
|
4
|
+
initialReset = => originalResetFunc.apply(this)
|
5
|
+
|
6
|
+
this.resetPage = =>
|
7
|
+
initialReset()
|
8
|
+
@additionalReset()
|
9
|
+
super(@owner, width, height)
|
10
|
+
|
11
|
+
additionalReset: =>
|
12
|
+
@jsonRequests = []
|
13
|
+
@page.onResourceRequested = (request) =>
|
14
|
+
if request.url.match(/\.json$/)
|
15
|
+
@jsonRequests.push(request.id)
|
16
|
+
|
17
|
+
sendResponse: (response) ->
|
18
|
+
if not @responseCallback(response)
|
19
|
+
callback = => @responseCallback(response)
|
20
|
+
@responseInterval = setInterval(callback, 10)
|
21
|
+
|
22
|
+
responseCallback: (response)=>
|
23
|
+
if (@page.allRequestsReceived(@jsonRequests) || @page.errors().count > 0)
|
24
|
+
errors = @page.errors()
|
25
|
+
@page.clearErrors()
|
26
|
+
if errors.length > 0 && @js_errors
|
27
|
+
@owner.sendError(new Poltergeist.JavascriptError(errors))
|
28
|
+
clearInterval(@responseInterval)
|
29
|
+
else
|
30
|
+
@owner.sendResponse(response)
|
31
|
+
clearInterval(@responseInterval)
|
32
|
+
return true
|
33
|
+
return false
|
34
|
+
|
35
|
+
class Poltergeist.WebPage extends Poltergeist.WebPage
|
36
|
+
allRequestsReceived: (ids)->
|
37
|
+
for requestId in ids
|
38
|
+
if @networkTraffic()[requestId].responseParts.length == 0
|
39
|
+
return false
|
40
|
+
return true
|
@@ -0,0 +1,89 @@
|
|
1
|
+
var _ref,
|
2
|
+
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
3
|
+
__hasProp = {}.hasOwnProperty,
|
4
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
5
|
+
|
6
|
+
Poltergeist.Browser = (function(_super) {
|
7
|
+
__extends(Browser, _super);
|
8
|
+
|
9
|
+
function Browser(owner, width, height) {
|
10
|
+
var initialReset, originalResetFunc,
|
11
|
+
_this = this;
|
12
|
+
this.owner = owner;
|
13
|
+
this.responseCallback = __bind(this.responseCallback, this);
|
14
|
+
this.additionalReset = __bind(this.additionalReset, this);
|
15
|
+
originalResetFunc = this.resetPage;
|
16
|
+
initialReset = function() {
|
17
|
+
return originalResetFunc.apply(_this);
|
18
|
+
};
|
19
|
+
this.resetPage = function() {
|
20
|
+
initialReset();
|
21
|
+
return _this.additionalReset();
|
22
|
+
};
|
23
|
+
Browser.__super__.constructor.call(this, this.owner, width, height);
|
24
|
+
}
|
25
|
+
|
26
|
+
Browser.prototype.additionalReset = function() {
|
27
|
+
var _this = this;
|
28
|
+
this.jsonRequests = [];
|
29
|
+
return this.page.onResourceRequested = function(request) {
|
30
|
+
if (request.url.match(/\.json$/)) {
|
31
|
+
return _this.jsonRequests.push(request.id);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
};
|
35
|
+
|
36
|
+
Browser.prototype.sendResponse = function(response) {
|
37
|
+
var callback,
|
38
|
+
_this = this;
|
39
|
+
if (!this.responseCallback(response)) {
|
40
|
+
callback = function() {
|
41
|
+
return _this.responseCallback(response);
|
42
|
+
};
|
43
|
+
return this.responseInterval = setInterval(callback, 10);
|
44
|
+
}
|
45
|
+
};
|
46
|
+
|
47
|
+
Browser.prototype.responseCallback = function(response) {
|
48
|
+
var errors;
|
49
|
+
if (this.page.allRequestsReceived(this.jsonRequests) || this.page.errors().count > 0) {
|
50
|
+
errors = this.page.errors();
|
51
|
+
this.page.clearErrors();
|
52
|
+
if (errors.length > 0 && this.js_errors) {
|
53
|
+
this.owner.sendError(new Poltergeist.JavascriptError(errors));
|
54
|
+
clearInterval(this.responseInterval);
|
55
|
+
} else {
|
56
|
+
this.owner.sendResponse(response);
|
57
|
+
clearInterval(this.responseInterval);
|
58
|
+
}
|
59
|
+
return true;
|
60
|
+
}
|
61
|
+
return false;
|
62
|
+
};
|
63
|
+
|
64
|
+
return Browser;
|
65
|
+
|
66
|
+
})(Poltergeist.Browser);
|
67
|
+
|
68
|
+
Poltergeist.WebPage = (function(_super) {
|
69
|
+
__extends(WebPage, _super);
|
70
|
+
|
71
|
+
function WebPage() {
|
72
|
+
_ref = WebPage.__super__.constructor.apply(this, arguments);
|
73
|
+
return _ref;
|
74
|
+
}
|
75
|
+
|
76
|
+
WebPage.prototype.allRequestsReceived = function(ids) {
|
77
|
+
var requestId, _i, _len;
|
78
|
+
for (_i = 0, _len = ids.length; _i < _len; _i++) {
|
79
|
+
requestId = ids[_i];
|
80
|
+
if (this.networkTraffic()[requestId].responseParts.length === 0) {
|
81
|
+
return false;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
return true;
|
85
|
+
};
|
86
|
+
|
87
|
+
return WebPage;
|
88
|
+
|
89
|
+
})(Poltergeist.WebPage);
|
@@ -0,0 +1,26 @@
|
|
1
|
+
var browser_overrides_path, e, index, old_phantom, path, phantom, phantomjs_script,
|
2
|
+
__hasProp = {}.hasOwnProperty,
|
3
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
4
|
+
|
5
|
+
try {
|
6
|
+
browser_overrides_path = phantom.args[phantom.args.length - 1];
|
7
|
+
phantomjs_script = phantom.args[phantom.args.length - 2];
|
8
|
+
old_phantom = phantom;
|
9
|
+
phantom = {};
|
10
|
+
__extends(phantom, old_phantom);
|
11
|
+
index = phantomjs_script.lastIndexOf("/");
|
12
|
+
path = phantomjs_script.substr(0, index);
|
13
|
+
phantom.injectJs = function(file) {
|
14
|
+
old_phantom.injectJs(file);
|
15
|
+
if (file.match(/browser.js$/)) {
|
16
|
+
old_phantom.injectJs(browser_overrides_path);
|
17
|
+
phantom = old_phantom;
|
18
|
+
return phantom.libraryPath = path;
|
19
|
+
}
|
20
|
+
};
|
21
|
+
phantom.libraryPath = path;
|
22
|
+
phantom.injectJs("" + phantom.libraryPath + "/main.js");
|
23
|
+
} catch (_error) {
|
24
|
+
e = _error;
|
25
|
+
console.log(e);
|
26
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
try
|
2
|
+
browser_overrides_path = phantom.args[phantom.args.length - 1]
|
3
|
+
phantomjs_script = phantom.args[phantom.args.length - 2]
|
4
|
+
|
5
|
+
old_phantom = phantom
|
6
|
+
phantom = {}
|
7
|
+
phantom extends old_phantom
|
8
|
+
|
9
|
+
index = phantomjs_script.lastIndexOf("/")
|
10
|
+
path = phantomjs_script.substr(0, index)
|
11
|
+
|
12
|
+
phantom.injectJs = (file)->
|
13
|
+
old_phantom.injectJs(file)
|
14
|
+
if file.match(/browser.js$/)
|
15
|
+
old_phantom.injectJs(browser_overrides_path)
|
16
|
+
phantom = old_phantom
|
17
|
+
phantom.libraryPath = path
|
18
|
+
|
19
|
+
phantom.libraryPath = path
|
20
|
+
phantom.injectJs("#{phantom.libraryPath}/main.js")
|
21
|
+
catch e
|
22
|
+
console.log e
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Capybara::Poltergeist
|
2
|
+
class Client
|
3
|
+
alias old_command command
|
4
|
+
def command
|
5
|
+
main_override_path = File.expand_path('../client/compiled/main_overrides.js', __FILE__)
|
6
|
+
command_array = old_command
|
7
|
+
command_array[1] = main_override_path
|
8
|
+
command_array << PHANTOMJS_SCRIPT
|
9
|
+
command_array << File.expand_path('../client/compiled/browser_overrides.js', __FILE__)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/patientgeist.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'patientgeist/version'
|
5
|
+
gem 'coffee-script'
|
6
|
+
require 'coffee-script'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = "patientgeist"
|
10
|
+
spec.version = Patientgeist::VERSION
|
11
|
+
spec.authors = ["Christopher Erin"]
|
12
|
+
spec.email = ["chris.erin@gmail.com"]
|
13
|
+
spec.description = %q{Enable capybara/poltergiest to wait for json ajax requests by default.}
|
14
|
+
spec.summary = %q{Enable capybara to wait for json ajax requests by default.}
|
15
|
+
spec.homepage = "https://github.com/chriserin/patientgeist"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "coffee-script"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: patientgeist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Erin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: coffee-script
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
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.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Enable capybara/poltergiest to wait for json ajax requests by default.
|
56
|
+
email:
|
57
|
+
- chris.erin@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .ruby-gemset
|
64
|
+
- .ruby-version
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/patientgeist.rb
|
70
|
+
- lib/patientgeist/client/browser_overrides.coffee
|
71
|
+
- lib/patientgeist/client/compiled/browser_overrides.js
|
72
|
+
- lib/patientgeist/client/compiled/main_overrides.js
|
73
|
+
- lib/patientgeist/client/main_overrides.coffee
|
74
|
+
- lib/patientgeist/client_override.rb
|
75
|
+
- lib/patientgeist/version.rb
|
76
|
+
- patientgeist.gemspec
|
77
|
+
homepage: https://github.com/chriserin/patientgeist
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.1.11
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Enable capybara to wait for json ajax requests by default.
|
101
|
+
test_files: []
|