capybara-angular 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capybara-angular.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Pawel Pierzchala
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,21 @@
1
+ # Capybara::Angular
2
+
3
+ Capybara API that knows how to wait for Angular in end to end specs.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capybara-angular'
10
+
11
+ ## Usage
12
+
13
+ Use it as you would use regular Capybara API, however this time, you won't facy any race conditions when working with AngularJS applications
14
+
15
+ ## Contributing
16
+
17
+ 1. Fork it
18
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
19
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
20
+ 4. Push to the branch (`git push origin my-new-feature`)
21
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capybara/angular/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capybara-angular"
8
+ spec.version = Capybara::Angular::VERSION
9
+ spec.authors = ["Pawel Pierzchala"]
10
+ spec.email = ["pawelpierzchala@gmail.com"]
11
+ spec.description = %q{Capybara API that knows how to wait for Angular in end to end specs}
12
+ spec.summary = %q{Stable Capybara API for AngularJS applications}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'capybara'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,4 @@
1
+ require "capybara"
2
+
3
+ require_relative "angular/dsl"
4
+ require_relative "angular/waiter"
@@ -0,0 +1,21 @@
1
+ module Capybara
2
+ module Angular
3
+ module DSL
4
+ include Capybara::DSL
5
+
6
+ Capybara::Session::DSL_METHODS.each do |method|
7
+ define_method(method) do |*args, &block|
8
+ wait_until_angular_ready
9
+ Capybara.current_session.send(method, *args, &block)
10
+ end
11
+ end
12
+
13
+ def wait_until_angular_ready
14
+ Waiter.new(Capybara.current_session).wait_until_ready
15
+ end
16
+
17
+ extend DSL
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,5 @@
1
+ module Capybara
2
+ module Angular
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,55 @@
1
+ module Capybara
2
+ module Angular
3
+ class Waiter
4
+ attr_accessor :page
5
+
6
+ def initialize(page)
7
+ @page = page
8
+ end
9
+
10
+ def wait_until_ready
11
+ return unless angular_app?
12
+
13
+ setup_ready
14
+
15
+ start = Time.now
16
+ until ready?
17
+ timeout! if timeout?(start)
18
+ sleep(0.01)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def timeout?(start)
25
+ Time.now - start > Capybara.default_wait_time
26
+ end
27
+
28
+ def timeout!
29
+ raise TimeoutError.new("timeout while waiting for angular")
30
+ end
31
+
32
+ def ready?
33
+ page.evaluate_script("window.angularReady")
34
+ end
35
+
36
+ def angular_app?
37
+ page.evaluate_script "(typeof $ != 'undefined') && $('[ng-app]')"
38
+ end
39
+
40
+ def setup_ready
41
+ page.execute_script <<-JS
42
+ window.angularReady = false;
43
+ var app = $('*[ng-app]');
44
+ var injector = app.injector();
45
+
46
+ injector.invoke(function($browser) {
47
+ $browser.notifyWhenNoOutstandingRequests(function() {
48
+ window.angularReady = true;
49
+ });
50
+ });
51
+ JS
52
+ end
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capybara-angular
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pawel Pierzchala
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capybara
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Capybara API that knows how to wait for Angular in end to end specs
63
+ email:
64
+ - pawelpierzchala@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - capybara-angular.gemspec
75
+ - lib/capybara/angular.rb
76
+ - lib/capybara/angular/dsl.rb
77
+ - lib/capybara/angular/version.rb
78
+ - lib/capybara/angular/waiter.rb
79
+ homepage: ''
80
+ licenses:
81
+ - MIT
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ segments:
93
+ - 0
94
+ hash: 1072475411
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ segments:
102
+ - 0
103
+ hash: 1072475411
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.25
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Stable Capybara API for AngularJS applications
110
+ test_files: []