capybara-envjs 0.1.5 → 0.1.6

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.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,10 @@
1
+ === 0.1.6 / 2010-07-05
2
+
3
+ * scope select to node
4
+ * Select bug fix and bring up to date with recent capy changes
5
+ * implement value for textareas
6
+ * doc tweaks [Kurt Werle]
7
+
1
8
  === 0.1.5 / 2010-06-02
2
9
 
3
10
  * Finish cleanup of rack-test host handling
data/README.rdoc CHANGED
@@ -23,6 +23,11 @@ Install as a gem:
23
23
 
24
24
  See the Capybara docs. Use the symbol :envjs for the driver/default_driver as appropriate.
25
25
 
26
+ If you are using cucumber, you might add the following lines to your features/support/env.rb
27
+
28
+ require 'capybara/envjs'
29
+ Capybara.javascript_driver = :envjs
30
+
26
31
  == License:
27
32
 
28
33
  (The MIT License)
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # -*- Mode: Ruby -*-
2
+
1
3
  require 'rubygems'
2
4
 
3
5
  gem 'hoe', '>= 2.5'
@@ -9,18 +11,18 @@ Hoe.plugins.delete :rubyforge
9
11
 
10
12
  Hoe.spec 'capybara-envjs' do
11
13
  developer 'Steven Parkes', 'smparkes@smparkes.net'
12
- self.version = "0.1.5"
14
+ self.version = "0.1.6"
13
15
 
14
16
  self.readme_file = 'README.rdoc'
15
17
  self.extra_rdoc_files = Dir['*.rdoc']
16
18
 
17
19
  self.extra_deps = [
18
- ['capybara', '>= 0.3.8'],
19
- ['envjs', '>= 0.3.6']
20
+ ['capybara', '>= 0.3.9'],
21
+ ['envjs', '>= 0.3.7']
20
22
  ]
21
23
 
22
24
  self.extra_dev_deps = [
23
- ['rack-test', '>= 0.5.3'],
25
+ ['rack-test', '>= 0.5.4'],
24
26
  ['rspec', '>= 1.3.0']
25
27
  ]
26
28
  end
@@ -53,6 +53,14 @@ class Capybara::Driver::Envjs < Capybara::Driver::Base
53
53
  end
54
54
  end
55
55
 
56
+ def value
57
+ if tag_name == 'textarea'
58
+ node.innerText
59
+ else
60
+ super
61
+ end
62
+ end
63
+
56
64
  def set(value)
57
65
  case node.tagName
58
66
  when "TEXTAREA"
@@ -68,8 +76,8 @@ class Capybara::Driver::Envjs < Capybara::Driver::Base
68
76
 
69
77
  def select(option)
70
78
  escaped = Capybara::XPath.escape(option)
71
- option_node = all_unfiltered("//option[text()=#{escaped}]") || all_unfiltered("//option[contains(.,#{escaped})]")
72
- option_node[0].node.selected = true
79
+ option_node = all_unfiltered(".//option[text()=#{escaped}]").first || all_unfiltered(".//option[contains(.,#{escaped})]").first
80
+ option_node.node.selected = true
73
81
  rescue Exception => e
74
82
  options = all_unfiltered(".//option").map { |o| "'#{o.text}'" }.join(', ')
75
83
  raise Capybara::OptionNotFound, "No such option '#{option}' in this select box. Available options: #{options}"
@@ -82,7 +90,7 @@ class Capybara::Driver::Envjs < Capybara::Driver::Base
82
90
 
83
91
  begin
84
92
  escaped = Capybara::XPath.escape(option)
85
- option_node = (all_unfiltered("//option[text()=#{escaped}]") || all_unfiltered("//option[contains(.,#{escaped})]")).first
93
+ option_node = (all_unfiltered(".//option[text()=#{escaped}]") || all_unfiltered(".//option[contains(.,#{escaped})]")).first
86
94
  option_node.node.selected = false
87
95
  rescue Exception => e
88
96
  options = all_unfiltered(".//option").map { |o| "'#{o.text}'" }.join(', ')
@@ -196,6 +204,7 @@ class Capybara::Driver::Envjs < Capybara::Driver::Base
196
204
  if e["CONTENT_TYPE"] =~ %r{^multipart/form-data;}
197
205
  e["CONTENT_LENGTH"] ||= params.length
198
206
  end
207
+ times = 0
199
208
  begin
200
209
  if url.index(app_host) == 0
201
210
  url.slice! 0..(app_host.length-1)
@@ -203,6 +212,9 @@ class Capybara::Driver::Envjs < Capybara::Driver::Base
203
212
  # puts "send #{method} #{url} #{params}"
204
213
  send method, url, params, e
205
214
  while response.status == 302 || response.status == 301
215
+ if (times += 1) > 5
216
+ raise Capybara::InfiniteRedirectError, "redirected more than 5 times, check for infinite redirects."
217
+ end
206
218
  params = {}
207
219
  method = :get
208
220
  url = response.location
@@ -213,7 +225,7 @@ class Capybara::Driver::Envjs < Capybara::Driver::Base
213
225
  send method, url, params, e
214
226
  end
215
227
  rescue Exception => e
216
- print "got #{e} #{response.inspect}\n"
228
+ # print "got #{e} #{response.inspect}\n"
217
229
  raise e
218
230
  end
219
231
  @source = response.body
@@ -254,6 +266,10 @@ class Capybara::Driver::Envjs < Capybara::Driver::Base
254
266
  browser["window"].document.xml
255
267
  end
256
268
 
269
+ def cleanup!
270
+ clear_cookies
271
+ end
272
+
257
273
  class Headers
258
274
  def initialize hash
259
275
  @hash = hash
@@ -268,11 +284,14 @@ class Capybara::Driver::Envjs < Capybara::Driver::Base
268
284
  Headers.new(browser["window"]["document"]["__headers__"])
269
285
  end
270
286
 
287
+ def status_code
288
+ response.status
289
+ end
290
+
271
291
  def find(selector)
272
292
  window = browser["window"]
273
293
  null = browser["null"]
274
294
  type = window["XPathResult"]["ANY_TYPE"]
275
- # print window.document.xml
276
295
  result_set = window.document.evaluate selector, window.document, null, type, null
277
296
  nodes = []
278
297
  while n = result_set.iterateNext()
@@ -288,6 +307,11 @@ class Capybara::Driver::Envjs < Capybara::Driver::Base
288
307
  raise Capybara::TimeoutError if !fired && wait.nil?
289
308
  end
290
309
 
310
+ def execute_script(script)
311
+ browser["window"]["evaluate"].call(script)
312
+ nil
313
+ end
314
+
291
315
  def evaluate_script(script)
292
316
  browser["window"]["evaluate"].call(script)
293
317
  end
@@ -10,7 +10,9 @@ describe Capybara::Driver::Envjs do
10
10
  end
11
11
 
12
12
  it_should_behave_like "driver"
13
- it_should_behave_like "driver with javascript support"
14
13
  it_should_behave_like "driver with header support"
15
-
14
+ it_should_behave_like "driver with status code support"
15
+ it_should_behave_like "driver with cookies support"
16
+ it_should_behave_like "driver with infinite redirect detection"
17
+ it_should_behave_like "driver with javascript support"
16
18
  end
@@ -24,5 +24,5 @@ describe Capybara::Driver::Envjs do
24
24
  it_should_behave_like "session"
25
25
  it_should_behave_like "session with javascript support"
26
26
  it_should_behave_like "session with headers support"
27
-
27
+ it_should_behave_like "session with status code support"
28
28
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-envjs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 5
10
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Steven Parkes
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-02 00:00:00 -07:00
18
+ date: 2010-07-05 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,12 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 3
29
+ hash: 1
30
30
  segments:
31
31
  - 0
32
32
  - 3
33
- - 8
34
- version: 0.3.8
33
+ - 9
34
+ version: 0.3.9
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -42,12 +42,12 @@ dependencies:
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- hash: 31
45
+ hash: 29
46
46
  segments:
47
47
  - 0
48
48
  - 3
49
- - 6
50
- version: 0.3.6
49
+ - 7
50
+ version: 0.3.7
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
@@ -58,12 +58,12 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- hash: 13
61
+ hash: 3
62
62
  segments:
63
63
  - 0
64
64
  - 5
65
- - 3
66
- version: 0.5.3
65
+ - 4
66
+ version: 0.5.4
67
67
  type: :development
68
68
  version_requirements: *id003
69
69
  - !ruby/object:Gem::Dependency
@@ -90,12 +90,12 @@ dependencies:
90
90
  requirements:
91
91
  - - ">="
92
92
  - !ruby/object:Gem::Version
93
- hash: 23
93
+ hash: 21
94
94
  segments:
95
95
  - 2
96
96
  - 6
97
- - 0
98
- version: 2.6.0
97
+ - 1
98
+ version: 2.6.1
99
99
  type: :development
100
100
  version_requirements: *id005
101
101
  description: |-