capybara-angular 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 693dad6d8c4ff820c47a41b26d0c680179148256
4
- data.tar.gz: 72e6b43dbe008965532ddc18b864476c37f50d60
2
+ SHA256:
3
+ metadata.gz: bcb03c75ee5122b2ac0feb6410f7592a00a7058539fa4d1a1c0911108a2024bf
4
+ data.tar.gz: 62b1d29e8b1561694249b40efce0804d827814fdf6c468349536ea84135f7b0f
5
5
  SHA512:
6
- metadata.gz: a2960689f9869d6a45f269a49d60e8b6d3c42e98740b5e64a14acc029b2bdebe2dea0b5c25e9f2cf311ca5391ea71d500ea14a3364dee66ba311f4c490d3b814
7
- data.tar.gz: 325b2b29a1741e706cd361bc8235bff5d1cd8f8cf2dd3accbf2c8a43ad83e58fa0968400cec6fb4431862c9d6062b35bd5dbae1ede3f9b166fdec3704256991d
6
+ metadata.gz: 1a230af009fe1cc36312d9ac5877549cc5377ec7f2eccb03355ef34c00bc862b75353ff6a5c4d2b74dc30681309ef2806605c034fd53b7c8a57f9f85bb35cecc
7
+ data.tar.gz: d8bb3cbfcfea3594475f67d1a5dab917a0c452b349a5cf4af213c7006fbef20ee338254d86bb94d7d261275032b84756794d3be50cf947f31a96e4638c951f87
@@ -0,0 +1,46 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: test-suite
9
+
10
+ on: [push, pull_request]
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-20.04
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ gemfile: ["rails-7.0.x"]
19
+ ruby: [3.2]
20
+ include:
21
+ - gemfile: rails-7.0.x
22
+ ruby: '3.1'
23
+ - gemfile: rails-7.0.x
24
+ ruby: '3.0'
25
+ - gemfile: rails-7.0.x
26
+ ruby: '2.7'
27
+ - gemfile: rails-6.1.x
28
+ ruby: '3.1'
29
+ - gemfile: rails-6.1.x
30
+ ruby: '3.0'
31
+ - gemfile: rails-6.1.x
32
+ ruby: 2.7
33
+ - gemfile: rails-6.0.x
34
+ ruby: 2.7
35
+ - gemfile: rails-5.2.x
36
+ ruby: 2.7
37
+
38
+ env:
39
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/Gemfile.${{ matrix.gemfile }}
40
+ steps:
41
+ - uses: actions/checkout@v2
42
+ - uses: ruby/setup-ruby@v1
43
+ with:
44
+ ruby-version: ${{ matrix.ruby }}
45
+ bundler-cache: true
46
+ - run: bundle exec rspec
data/.gitignore CHANGED
@@ -5,6 +5,7 @@
5
5
  .yardoc
6
6
  .rvmrc
7
7
  Gemfile.lock
8
+ gemfiles/*.lock
8
9
  InstalledFiles
9
10
  _yardoc
10
11
  coverage
data/README.md CHANGED
@@ -18,6 +18,13 @@ Use it as you would use regular Capybara API, however this time, you won't face
18
18
  include Capybara::Angular::DSL
19
19
  ```
20
20
 
21
+ If you need to run some code without caring about AngularJS, you can use `ignoring_angular` like this:
22
+ ```ruby
23
+ ignoring_angular do
24
+ # Your AngularJS agnostic code goes here
25
+ end
26
+ ```
27
+
21
28
  ## Limitations
22
29
 
23
30
  At the moment it works with AngularJS applications initialized with `ng-app`.
@@ -17,11 +17,14 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
+ spec.required_ruby_version = ">= 2.7"
20
21
 
21
22
  spec.add_dependency 'capybara', '>= 2.5.0'
22
23
 
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "bundler", "> 1.17", "< 3"
25
+ spec.add_development_dependency "rails", "> 5.2", "< 7.1"
24
26
  spec.add_development_dependency "rake"
25
27
  spec.add_development_dependency "rspec"
26
28
  spec.add_development_dependency "poltergeist"
29
+ spec.add_development_dependency "puma", "< 6"
27
30
  end
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 5.2.0'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 6.0.0'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 6.1.0'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 7.0.0'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', github: 'rails/rails'
@@ -4,8 +4,8 @@ module Capybara
4
4
  include Capybara::DSL
5
5
 
6
6
  Capybara::Session::DSL_METHODS.each do |method|
7
- define_method(method) do |*args, &block|
8
- page.send(method, *args, &block)
7
+ define_method(method) do |*args, **kwargs, &block|
8
+ page.send(method, *args, **kwargs, &block)
9
9
  end
10
10
  end
11
11
 
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Angular
3
- VERSION = "0.2.5"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -0,0 +1,53 @@
1
+ // This script is injected from waiter.rb. It is responsible for setting
2
+ // window.capybaraAngularReady when either a) angular is ready, or b)
3
+ // it determines the page is not an angular page.
4
+
5
+ (function () {
6
+ "use strict";
7
+
8
+ window.capybaraAngularReady = false;
9
+
10
+ function ready() {
11
+ window.capybaraAngularReady = true;
12
+ }
13
+
14
+ function angularPresent() {
15
+ return window.angular !== undefined;
16
+ }
17
+
18
+ function element() {
19
+ return document.querySelector("[ng-app], [data-ng-app]") || document.querySelector("body");
20
+ }
21
+
22
+ function elementPresent() {
23
+ return element() !== undefined;
24
+ }
25
+
26
+ function setupTestability() {
27
+ try {
28
+ angular.getTestability(element()).whenStable(ready);
29
+ } catch (err) {
30
+ ready();
31
+ }
32
+ }
33
+
34
+ function setupInjector() {
35
+ try {
36
+ angular.element(element()).injector().get("$browser").notifyWhenNoOutstandingRequests(ready);
37
+ } catch (err) {
38
+ ready();
39
+ }
40
+ }
41
+
42
+ function setup() {
43
+ if (!angularPresent() || !elementPresent()) {
44
+ ready();
45
+ } else if (angular.getTestability) {
46
+ setupTestability();
47
+ } else {
48
+ setupInjector();
49
+ }
50
+ }
51
+
52
+ setup();
53
+ }());
@@ -1,6 +1,8 @@
1
1
  module Capybara
2
2
  module Angular
3
3
  class Waiter
4
+ WAITER_JS = IO.read(File.expand_path "../waiter.js", __FILE__)
5
+
4
6
  attr_accessor :page
5
7
 
6
8
  def initialize(page)
@@ -8,23 +10,24 @@ module Capybara
8
10
  end
9
11
 
10
12
  def wait_until_ready
11
- return unless angular_app?
12
-
13
- setup_ready
14
-
13
+ return unless driver_supports_js?
15
14
  start = Time.now
15
+
16
16
  until ready?
17
+ inject_waiter
17
18
  timeout! if timeout?(start)
18
- if page_reloaded_on_wait?
19
- return unless angular_app?
20
- setup_ready
21
- end
22
19
  sleep(0.01)
23
20
  end
24
21
  end
25
22
 
26
23
  private
27
24
 
25
+ def driver_supports_js?
26
+ page.evaluate_script "true"
27
+ rescue Capybara::NotSupportedByDriverError
28
+ false
29
+ end
30
+
28
31
  def timeout?(start)
29
32
  Time.now - start > Capybara::Angular.default_max_wait_time
30
33
  end
@@ -33,37 +36,13 @@ module Capybara
33
36
  raise Timeout::Error.new("timeout while waiting for angular")
34
37
  end
35
38
 
36
- def ready?
37
- page.evaluate_script("window.angularReady")
38
- end
39
-
40
- def angular_app?
41
- js = '!!window.angular'
42
- page.evaluate_script js
43
-
44
- rescue Capybara::NotSupportedByDriverError
45
- false
46
- end
47
-
48
- def setup_ready
49
- page.execute_script <<-JS
50
- var el = document.querySelector('[ng-app], [data-ng-app]') || document.querySelector('body');
51
-
52
- window.angularReady = false;
53
-
54
- if (angular.getTestability) {
55
- angular.getTestability(el).whenStable(function() { window.angularReady = true; });
56
- } else {
57
- var $browser = angular.element(el).injector().get('$browser');
58
-
59
- if ($browser.outstandingRequestCount > 0) { window.angularReady = false; }
60
- $browser.notifyWhenNoOutstandingRequests(function() { window.angularReady = true; });
61
- }
62
- JS
39
+ def inject_waiter
40
+ return if page.evaluate_script("window.capybaraAngularReady !== undefined")
41
+ page.execute_script WAITER_JS
63
42
  end
64
43
 
65
- def page_reloaded_on_wait?
66
- page.evaluate_script("window.angularReady === undefined")
44
+ def ready?
45
+ page.evaluate_script("window.capybaraAngularReady === true")
67
46
  end
68
47
  end
69
48
  end
@@ -1,4 +1,6 @@
1
1
  require 'rack'
2
+ require 'puma'
3
+ require 'rack/handler/puma'
2
4
  require 'capybara'
3
5
  require 'capybara/rspec'
4
6
  require 'capybara/poltergeist'
@@ -27,6 +29,16 @@ feature 'Waiting for angular' do
27
29
  timeout_page_should_have_waited
28
30
  end
29
31
 
32
+ scenario 'when visiting a non-angular page' do
33
+ open_non_angular_page
34
+ non_angular_page_should_load
35
+ end
36
+
37
+ scenario 'when visiting a non-angular page that loads angular javascript' do
38
+ open_non_angular_page_with_angular_javascript
39
+ non_angular_page_should_load
40
+ end
41
+
30
42
  def open_manual_bootstrap_page
31
43
  visit '/manual.html'
32
44
  end
@@ -39,7 +51,19 @@ feature 'Waiting for angular' do
39
51
  visit '/ng-app-not-on-body.html'
40
52
  end
41
53
 
54
+ def open_non_angular_page
55
+ visit '/non-angular-page.html'
56
+ end
57
+
58
+ def open_non_angular_page_with_angular_javascript
59
+ visit '/non-angular-page-with-angular-javascript.html'
60
+ end
61
+
42
62
  def timeout_page_should_have_waited
43
63
  expect(page).to have_content('waited')
44
64
  end
65
+
66
+ def non_angular_page_should_load
67
+ expect(page).to have_content('non-angular page')
68
+ end
45
69
  end
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+ <script src="/js/angular-1.5.8.js"></script>
4
+ </head>
5
+ <body>
6
+ non-angular page
7
+ </body>
8
+ </html>
@@ -0,0 +1,6 @@
1
+ <html>
2
+ <head/>
3
+ <body>
4
+ non-angular page
5
+ </body>
6
+ </html>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-angular
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pawel Pierzchala
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-10 00:00:00.000000000 Z
11
+ date: 2022-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -28,16 +28,42 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.3'
33
+ version: '1.17'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '3'
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "~>"
41
+ - - ">"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.17'
44
+ - - "<"
39
45
  - !ruby/object:Gem::Version
40
- version: '1.3'
46
+ version: '3'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rails
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">"
52
+ - !ruby/object:Gem::Version
53
+ version: '5.2'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '7.1'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">"
62
+ - !ruby/object:Gem::Version
63
+ version: '5.2'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '7.1'
41
67
  - !ruby/object:Gem::Dependency
42
68
  name: rake
43
69
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +106,20 @@ dependencies:
80
106
  - - ">="
81
107
  - !ruby/object:Gem::Version
82
108
  version: '0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: puma
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "<"
114
+ - !ruby/object:Gem::Version
115
+ version: '6'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "<"
121
+ - !ruby/object:Gem::Version
122
+ version: '6'
83
123
  description: Capybara API that knows how to wait for Angular in end to end specs
84
124
  email:
85
125
  - pawelpierzchala@gmail.com
@@ -87,6 +127,7 @@ executables: []
87
127
  extensions: []
88
128
  extra_rdoc_files: []
89
129
  files:
130
+ - ".github/workflows/test-suite.yml"
90
131
  - ".gitignore"
91
132
  - ".travis.yml"
92
133
  - Gemfile
@@ -94,9 +135,15 @@ files:
94
135
  - README.md
95
136
  - Rakefile
96
137
  - capybara-angular.gemspec
138
+ - gemfiles/Gemfile.rails-5.2.x
139
+ - gemfiles/Gemfile.rails-6.0.x
140
+ - gemfiles/Gemfile.rails-6.1.x
141
+ - gemfiles/Gemfile.rails-7.0.x
142
+ - gemfiles/Gemfile.rails-edge
97
143
  - lib/capybara/angular.rb
98
144
  - lib/capybara/angular/dsl.rb
99
145
  - lib/capybara/angular/version.rb
146
+ - lib/capybara/angular/waiter.js
100
147
  - lib/capybara/angular/waiter.rb
101
148
  - spec/capybara/angular_spec.rb
102
149
  - spec/public/js/angular-1.5.8.js
@@ -104,11 +151,13 @@ files:
104
151
  - spec/public/manual.html
105
152
  - spec/public/ng-app-not-on-body.html
106
153
  - spec/public/ng-app.html
154
+ - spec/public/non-angular-page-with-angular-javascript.html
155
+ - spec/public/non-angular-page.html
107
156
  homepage: ''
108
157
  licenses:
109
158
  - MIT
110
159
  metadata: {}
111
- post_install_message:
160
+ post_install_message:
112
161
  rdoc_options: []
113
162
  require_paths:
114
163
  - lib
@@ -116,16 +165,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
165
  requirements:
117
166
  - - ">="
118
167
  - !ruby/object:Gem::Version
119
- version: '0'
168
+ version: '2.7'
120
169
  required_rubygems_version: !ruby/object:Gem::Requirement
121
170
  requirements:
122
171
  - - ">="
123
172
  - !ruby/object:Gem::Version
124
173
  version: '0'
125
174
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.6.8
128
- signing_key:
175
+ rubygems_version: 3.1.6
176
+ signing_key:
129
177
  specification_version: 4
130
178
  summary: Stable Capybara API for AngularJS applications
131
179
  test_files:
@@ -135,3 +183,5 @@ test_files:
135
183
  - spec/public/manual.html
136
184
  - spec/public/ng-app-not-on-body.html
137
185
  - spec/public/ng-app.html
186
+ - spec/public/non-angular-page-with-angular-javascript.html
187
+ - spec/public/non-angular-page.html