capybara-ng 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4751f5d1b3319c7ffdc1524119db8ae2af4ad77b
4
- data.tar.gz: 8eb230d62a078b284fa5f04108f2fd26c229d754
3
+ metadata.gz: 9a4244f3f4b4efc807b67ad806ebab71b7a7a470
4
+ data.tar.gz: b844b0f756bbf73f3c6318f41c864aa7cce9121d
5
5
  SHA512:
6
- metadata.gz: 7693856f13f3b8488998226acb849b265ae0e03b905ea8cde880a5fc3aa3424a7f430e6942304624b4c1c19e6ae200ba6152b066831e0c4c0652cb2d1f68912c
7
- data.tar.gz: 7c2f25c8bb781d417e3b4011fa5356be4171253526394931609b203c1508cba3e4be18d933fb6e7d799a7cc54d3a1bb7d969761a1b134777474c34bee3b5c98e
6
+ metadata.gz: b7c4f1fbde0af58a31fd0e52a72bc59a7efbdf726c25ed17c4609c522eaade408388e1f1b3cd0b1be0cd6584daa30211b5361a97f8a7a20f9bb814d5f29929cd
7
+ data.tar.gz: 6f899d9f44d42f4e166554cc194ef13c72e7ab85715b7018edf15e6842d87f16932e144e9011e43cab8a070f58bc585b96b5d5382025718c4853b48e44b02f3b
data/README.md CHANGED
@@ -12,6 +12,7 @@ Based into testing following drivers should work.
12
12
 
13
13
  - chrome
14
14
  - poltergeist
15
+ - selenium (using firefox)
15
16
  - webkit
16
17
 
17
18
  ## Related Projects
data/lib/angular/dsl.rb CHANGED
@@ -1,9 +1,23 @@
1
1
  module Angular
2
+ #
3
+ # common options (aka. "opt"):
4
+ # - root_selector Allow overriding global/page per individual query
5
+ # - wait If true wait for AngularJS to be ready before doing quer (default: true)
6
+ #
2
7
  module DSL
3
8
  def ng
4
9
  Capybara.current_session.ng
5
10
  end
6
11
 
12
+ #
13
+ # Get or set selector to find ng-app for current capybara test session
14
+ #
15
+ # TIP: try using '[ng-app]', which will find ng-app as attribute anywhere.
16
+ #
17
+ # @param root_selector if nil then return current value without change
18
+ # @return test specific selector to find ng-app,
19
+ # by default global ::Angular.root_selector is used.
20
+ #
7
21
  def ng_root_selector(root_selector = nil)
8
22
  opt = ng.page.ng_session_options
9
23
  if root_selector
@@ -12,15 +26,25 @@ module DSL
12
26
  opt[:root_selector] || ::Angular.root_selector
13
27
  end
14
28
 
29
+ #
30
+ # Setup AngularJS test hooks in web page. In normal usage there is no need
31
+ # to use this
32
+ #
15
33
  def ng_install
16
34
  ng.install
17
35
  end
18
36
 
37
+ #
38
+ # Wait that AngularJS is ready
39
+ #
19
40
  def ng_wait
20
41
  ng.ng_wait
21
42
  end
22
43
 
23
44
  #
45
+ # @param opt
46
+ # - :root_selector
47
+ # - :wait
24
48
  # @return current location absolute url
25
49
  #
26
50
  def ng_location_abs(opt = {})
@@ -28,6 +52,10 @@ module DSL
28
52
  ng.make_call :getLocationAbsUrl, [selector], opt
29
53
  end
30
54
 
55
+ #
56
+ # @param opt
57
+ # - :root_selector
58
+ # - :wait
31
59
  # @return current location absolute url
32
60
  #
33
61
  def ng_location(opt = {})
@@ -36,6 +64,9 @@ module DSL
36
64
  end
37
65
 
38
66
  #
67
+ # @param opt
68
+ # - :root_selector
69
+ # - :wait
39
70
  # @return current location
40
71
  #
41
72
  def ng_set_location(url, opt = {})
@@ -59,7 +90,6 @@ module DSL
59
90
  #
60
91
  # @param opt
61
92
  # - :exact
62
- # - :using
63
93
  # - :root_selector
64
94
  # - :wait
65
95
  # @return true | false
@@ -77,7 +107,6 @@ module DSL
77
107
  # @param opt
78
108
  # - :row
79
109
  # - :exact
80
- # - :using
81
110
  # - :root_selector
82
111
  # - :wait
83
112
  # @return nth node
@@ -93,7 +122,6 @@ module DSL
93
122
  #
94
123
  # @param opt
95
124
  # - :exact
96
- # - :using
97
125
  # - :root_selector
98
126
  # - :wait
99
127
  # @return [node, ...]
@@ -107,7 +135,6 @@ module DSL
107
135
  # Does model exist
108
136
  #
109
137
  # @param opt
110
- # - :using
111
138
  # - :root_selector
112
139
  # - :wait
113
140
  # @return true | false
@@ -122,7 +149,6 @@ module DSL
122
149
  # Does model not exist
123
150
  #
124
151
  # @param opt
125
- # - :using
126
152
  # - :root_selector
127
153
  # - :wait
128
154
  # @return true | false
@@ -136,7 +162,6 @@ module DSL
136
162
  #
137
163
  # @param opt
138
164
  # - :row
139
- # - :using
140
165
  # - :root_selector
141
166
  # - :wait
142
167
  # @return nth node
@@ -151,7 +176,6 @@ module DSL
151
176
  # All nodes matching model
152
177
  #
153
178
  # @param opt
154
- # - :using
155
179
  # - :root_selector
156
180
  # - :wait
157
181
  # @return [node, ...]
@@ -165,7 +189,6 @@ module DSL
165
189
  # Does option exist
166
190
  #
167
191
  # @param opt
168
- # - :using
169
192
  # - :root_selector
170
193
  # - :wait
171
194
  # @return true | false
@@ -182,7 +205,6 @@ module DSL
182
205
  # Does option not exist
183
206
  #
184
207
  # @param opt
185
- # - :using
186
208
  # - :root_selector
187
209
  # - :wait
188
210
  # @return true | false
@@ -196,7 +218,6 @@ module DSL
196
218
  #
197
219
  # @param opt
198
220
  # - :row
199
- # - :using
200
221
  # - :root_selector
201
222
  # - :wait
202
223
  # @return nth node
@@ -211,7 +232,6 @@ module DSL
211
232
  # All option values matching option
212
233
  #
213
234
  # @param opt
214
- # - :using
215
235
  # - :root_selector
216
236
  # - :wait
217
237
  # @return [node, ...]
@@ -225,7 +245,6 @@ module DSL
225
245
  # Does row exist
226
246
  #
227
247
  # @param opt
228
- # - :using
229
248
  # - :root_selector
230
249
  # - :wait
231
250
  # @return true | false
@@ -241,7 +260,6 @@ module DSL
241
260
  # Does row not exist
242
261
  #
243
262
  # @param opt
244
- # - :using
245
263
  # - :root_selector
246
264
  # - :wait
247
265
  # @return true | false
@@ -255,7 +273,6 @@ module DSL
255
273
  #
256
274
  # @param opt
257
275
  # - :row
258
- # - :using
259
276
  # - :root_selector
260
277
  # - :wait
261
278
  # @return nth node
@@ -271,7 +288,6 @@ module DSL
271
288
  # All nodes matching repeater
272
289
  #
273
290
  # @param opt
274
- # - :using
275
291
  # - :root_selector
276
292
  # - :wait
277
293
  # @return [node, ...]
@@ -286,7 +302,6 @@ module DSL
286
302
  #
287
303
  # @param opt
288
304
  # - :row
289
- # - :using
290
305
  # - :root_selector
291
306
  # - :wait
292
307
  # @return nth node
@@ -301,7 +316,6 @@ module DSL
301
316
  # Node for column binding value in all rows
302
317
  #
303
318
  # @param opt
304
- # - :using
305
319
  # - :root_selector
306
320
  # - :wait
307
321
  # @return [node, ...]
@@ -314,7 +328,6 @@ module DSL
314
328
  #
315
329
  # @param opt
316
330
  # - :row
317
- # - :using
318
331
  # - :root_selector
319
332
  # - :wait
320
333
  # @return nth node
@@ -327,7 +340,6 @@ module DSL
327
340
 
328
341
  #
329
342
  # @param opt
330
- # - :using
331
343
  # - :root_selector
332
344
  # - :wait
333
345
  # @return [node, ...]
data/lib/angular/log.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Log
2
2
  def logger
3
- ::Rails.logger
3
+ ::Angular.logger
4
4
  end
5
5
  end
data/lib/angular/setup.rb CHANGED
@@ -19,28 +19,11 @@ module Angular
19
19
 
20
20
  #
21
21
  # @param opt
22
- # - :using
23
- # - :root_selector
24
- # - :wait
25
- #
26
- def get_nodes(method, params, opt = {})
27
- opt = {
28
- nodes: true,
29
- using: nil,
30
- root_selector: ::Angular.root_selector,
31
- }.merge(opt)
32
- make_call(method, params, opt)
33
- end
34
-
35
- #
36
- # @param opt
37
- # - :using
38
22
  # - :root_selector
39
23
  # - :wait
40
24
  #
41
25
  def get_nodes_2(method, params, opt = {})
42
26
  opt = {
43
- nodes: false,
44
27
  using: nil,
45
28
  root_selector: ::Angular.root_selector,
46
29
  }.merge(opt)
@@ -49,6 +32,11 @@ module Angular
49
32
  make_nodes(ids, opt)
50
33
  end
51
34
 
35
+ #
36
+ # Find nodes matching 'capybara-ng-match' attributes using ids
37
+ #
38
+ # @return nodes matching ids
39
+ #
52
40
  def make_nodes(ids, opt)
53
41
  result = []
54
42
  ids.each do |id|
@@ -65,12 +53,13 @@ module Angular
65
53
 
66
54
  #
67
55
  # @param opt
68
- # - :nodes
56
+ # - :root_selector
69
57
  # - :wait
70
58
  #
59
+ # @return result from page.evaluate_script
60
+ #
71
61
  def make_call(method, params, opt = {})
72
62
  opt = {
73
- nodes: false,
74
63
  wait: true,
75
64
  }.merge(opt)
76
65
 
@@ -94,26 +83,7 @@ module Angular
94
83
  js_result = page.evaluate_script(js);
95
84
  # logger.debug js_result
96
85
 
97
- if opt[:nodes]
98
- make_result method, params, js_result
99
- else
100
- js_result
101
- end
102
- end
103
-
104
-
105
- def make_result(method, params, js_result)
106
- if js_result.nil? || js_result.empty?
107
- raise NotFound.new("#{method}: #{params.inspect}")
108
- end
109
-
110
- if js_result.is_a? String
111
- raise js_result
112
- end
113
-
114
- js_result.map do |el|
115
- el ? Capybara::Selenium::Node.new(page.driver, el) : nil
116
- end
86
+ js_result
117
87
  end
118
88
 
119
89
  def angular_app?
@@ -1,3 +1,3 @@
1
1
  module Angular
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/angular.rb CHANGED
@@ -1,18 +1,32 @@
1
1
  require "angular/version"
2
2
  require 'capybara'
3
+ require 'logger'
3
4
 
4
5
  module Angular
5
6
  class NotFound < StandardError
6
7
  end
7
8
 
9
+ #
10
+ # @return selector to find ng-app, by default 'body'
11
+ #
8
12
  def self.root_selector
9
13
  @root_slector ||= 'body'
10
14
  end
11
15
 
16
+ #
17
+ # Set global default selector for finding ng-app
18
+ #
12
19
  def self.root_selector=(root_selector)
13
20
  @root_selector = root_selector
14
21
  end
15
22
 
23
+ def self.logger
24
+ @logger ||= defined?(::Rails) ? ::Rails.logger : Logger.new('capybara-ng.log')
25
+ end
26
+
27
+ def self.logger=(logger)
28
+ @logger = logger
29
+ end
16
30
  end
17
31
 
18
32
  require 'angular/log'
data/travis/run.sh CHANGED
@@ -1,23 +1,45 @@
1
1
  cd spec/dummy
2
2
  export BUNDLE_GEMFILE=$PWD/Gemfile
3
3
 
4
+ #
5
+ # CUCUMBER
6
+ #
4
7
  echo "cucumber - poltergeist"
5
8
  xvfb-run -a export CAPYBARA_DRIVER=poltergeist && bundle exec cucumber
6
- EXIT_1=$?
9
+ EXIT_1_1=$?
7
10
 
8
11
  echo "cucumber - webkit"
9
12
  xvfb-run -a export CAPYBARA_DRIVER=webkit && bundle exec cucumber
10
- EXIT_2=$?
13
+ EXIT_1_2=$?
11
14
 
15
+ echo "cucumber - selenium"
16
+ xvfb-run -a export CAPYBARA_DRIVER=selenium && bundle exec cucumber
17
+ EXIT_1_3=$?
18
+
19
+ #
20
+ # RSPEC
21
+ #
12
22
  echo "rspec - poltergeist"
13
23
  xvfb-run -a export CAPYBARA_DRIVER=poltergeist && bundle exec rspec
14
- EXIT_3=$?
24
+ EXIT_2_1=$?
15
25
 
16
26
  echo "rspec - webkit"
17
27
  xvfb-run -a export CAPYBARA_DRIVER=webkit && bundle exec rspec
18
- EXIT_4=$?
28
+ EXIT_2_2=$?
29
+
30
+ echo "rspec - selenium"
31
+ xvfb-run -a export CAPYBARA_DRIVER=selenium && bundle exec rspec
32
+ EXIT_2_3=$?
33
+
34
+ #
35
+ # Exit check
36
+ #
37
+ if [[ $EXIT_1_1 != 0 || $EXIT_1_2 != 0 || $EXIT_1_3 != 0 ]]; then
38
+ echo "Cucumber Failed"
39
+ exit 1
40
+ fi
19
41
 
20
- if [[ $EXIT_1 != 0 || $EXIT_2 != 0 || $EXIT_3 != 0 || $EXIT_4 != 0 ]]; then
21
- echo "Failed"
42
+ if [[ $EXIT_2_1 != 0 || $EXIT_2_2 != 0 || $EXIT_2_3 != 0 ]]; then
43
+ echo "Rspec Failed"
22
44
  exit 1
23
45
  fi
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-ng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-19 00:00:00.000000000 Z
11
+ date: 2015-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler