capybara 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,9 +2,7 @@ History.txt
2
2
  Manifest.txt
3
3
  README.rdoc
4
4
  Rakefile
5
- examples/webcat.rb
6
5
  lib/capybara.rb
7
- lib/capybara/core_ext/tcp_socket.rb
8
6
  lib/capybara/cucumber.rb
9
7
  lib/capybara/driver/culerity_driver.rb
10
8
  lib/capybara/driver/firewatir_driver.rb
@@ -86,6 +86,8 @@ Navigation:
86
86
  Scoping:
87
87
 
88
88
  within – Takes a block which executes in the given scope
89
+ within_fieldset – Execute the block in the fieldset given by id or legend
90
+ within_table – Execute the block in the table given by id or caption
89
91
 
90
92
  Interaction:
91
93
 
@@ -151,8 +153,10 @@ Capybara is hosted on Gemcutter, install it with:
151
153
 
152
154
  == Gotchas:
153
155
 
154
- * Install JRuby and the 'jarib-celerity' gem (not the 'celerity' gem) for
155
- Culerity support.
156
+ * Install JRuby and the 'celerity' gem, version 0.7.4 (0.7.5 has a bug with
157
+ password fields) under JRuby for Culerity support. Also you'll need to install
158
+ teh edge version of Culerity until a new gem release becomes available, since
159
+ 0.2.3 does not work (at all!) with Capybara.
156
160
 
157
161
  * Everything is *case sensitive*. Capybara heavily relies on XPath, which
158
162
  doesn't support case insensitive searches.
@@ -165,7 +169,7 @@ Capybara is hosted on Gemcutter, install it with:
165
169
  * Domain names (including subdomains) don't work under rack-test. Since it's a
166
170
  pain to set up subdomains for the other drivers anyway, you should consider an
167
171
  alternate solution. You might use
168
- [default_url_options](https://gist.github.com/643a758320a2926bd2ed) in Rails
172
+ {default_url_options}[https://gist.github.com/643a758320a2926bd2ed] in Rails
169
173
  for example.
170
174
 
171
175
  * The <tt>set_hidden_field</tt> method from Webrat is not implemented, since it doesn't
data/Rakefile CHANGED
@@ -18,11 +18,17 @@ $hoe = Hoe.spec 'capybara' do
18
18
 
19
19
  self.extra_deps = [
20
20
  ['nokogiri', '>= 1.3.3'],
21
- ['culerity', '>= 0.2.3'],
21
+ ['culerity', '>= 0.2.4'],
22
22
  ['selenium-webdriver', '>= 0.0.3'],
23
23
  ['rack', '>= 1.0.0'],
24
+ ['rack-test', '>= 0.5.2'],
24
25
  ['database_cleaner', '>= 0.2.3']
25
26
  ]
27
+
28
+ self.extra_dev_deps = [
29
+ ['sinatra', '>= 0.9.4'],
30
+ ['rspec', '>= 1.2.9']
31
+ ]
26
32
  end
27
33
 
28
34
  require 'newgem/tasks'
@@ -1,7 +1,7 @@
1
1
  require 'nokogiri'
2
2
 
3
3
  module Capybara
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
 
6
6
  class CapybaraError < StandardError; end
7
7
  class DriverNotFoundError < CapybaraError; end
@@ -44,8 +44,9 @@ module Capybara
44
44
 
45
45
  SESSION_METHODS = [
46
46
  :visit, :body, :click_link, :click_button, :fill_in, :choose, :has_xpath?, :has_css?,
47
- :check, :uncheck, :attach_file, :select, :has_content?, :within, :save_and_open_page,
48
- :find_field, :find_link, :find_button, :field_labeled
47
+ :check, :uncheck, :attach_file, :select, :has_content?, :within, :within_fieldset,
48
+ :within_table, :save_and_open_page, :find_field, :find_link, :find_button,
49
+ :field_labeled
49
50
  ]
50
51
  SESSION_METHODS.each do |method|
51
52
  class_eval <<-RUBY, __FILE__, __LINE__+1
@@ -1,4 +1,16 @@
1
1
  class Capybara::Session
2
+
3
+ FIELDS_PATHS = {
4
+ :text_field => proc { |id| "//input[@type='text'][@id='#{id}']" },
5
+ :text_area => proc { |id| "//textarea[@id='#{id}']" },
6
+ :password_field => proc { |id| "//input[@type='password'][@id='#{id}']" },
7
+ :radio => proc { |id| "//input[@type='radio'][@id='#{id}']" },
8
+ :hidden_field => proc { |id| "//input[@type='hidden'][@id='#{id}']" },
9
+ :checkbox => proc { |id| "//input[@type='checkbox'][@id='#{id}']" },
10
+ :select => proc { |id| "//select[@id='#{id}']" },
11
+ :file_field => proc { |id| "//input[@type='file'][@id='#{id}']" }
12
+ }
13
+
2
14
  attr_reader :mode, :app
3
15
 
4
16
  def initialize(mode, app)
@@ -88,6 +100,18 @@ class Capybara::Session
88
100
  scopes.pop
89
101
  end
90
102
 
103
+ def within_fieldset(locator)
104
+ within "//fieldset[@id='#{locator}' or contains(legend,'#{locator}')]" do
105
+ yield
106
+ end
107
+ end
108
+
109
+ def within_table(locator)
110
+ within "//table[@id='#{locator}' or contains(caption,'#{locator}')]" do
111
+ yield
112
+ end
113
+ end
114
+
91
115
  def save_and_open_page
92
116
  require 'capybara/save_and_open_page'
93
117
  Capybara::SaveAndOpenPage.save_and_open_page(body)
@@ -102,18 +126,13 @@ class Capybara::Session
102
126
  alias_method :field_labeled, :find_field
103
127
 
104
128
  def find_link(locator)
105
- link = find_element("//a[@id='#{locator}']", "//a[contains(.,'#{locator}')]", "//a[@title='#{locator}']")
129
+ link = find("//a[@id='#{locator}' or contains(.,'#{locator}') or @title='#{locator}']").first
106
130
  raise Capybara::ElementNotFound, "no link with title, id or text '#{locator}' found" unless link
107
131
  link
108
132
  end
109
133
 
110
134
  def find_button(locator)
111
- button = find_element(
112
- "//input[@type='submit'][@id='#{locator}']",
113
- "//input[@type='submit'][@value='#{locator}']",
114
- "//input[@type='image'][@id='#{locator}']",
115
- "//input[@type='image'][@value='#{locator}']"
116
- )
135
+ button = find("//input[@type='submit' or @type='image'][@id='#{locator}' or @value='#{locator}']").first
117
136
  raise Capybara::ElementNotFound, "no button with value or id '#{locator}' found" unless button
118
137
  button
119
138
  end
@@ -143,17 +162,6 @@ private
143
162
  @scopes ||= []
144
163
  end
145
164
 
146
- FIELDS_PATHS = {
147
- :text_field => proc { |id| "//input[@type='text'][@id='#{id}']" },
148
- :text_area => proc { |id| "//textarea[@id='#{id}']" },
149
- :password_field => proc { |id| "//input[@type='password'][@id='#{id}']" },
150
- :radio => proc { |id| "//input[@type='radio'][@id='#{id}']" },
151
- :hidden_field => proc { |id| "//input[@type='hidden'][@id='#{id}']" },
152
- :checkbox => proc { |id| "//input[@type='checkbox'][@id='#{id}']" },
153
- :select => proc { |id| "//select[@id='#{id}']" },
154
- :file_field => proc { |id| "//input[@type='file'][@id='#{id}']" }
155
- }
156
-
157
165
  def find_field_by_id(locator, *kinds)
158
166
  kinds.each do |kind|
159
167
  path = FIELDS_PATHS[kind]
@@ -173,14 +181,6 @@ private
173
181
  end
174
182
  return nil
175
183
  end
176
-
177
- def find_element(*locators)
178
- locators.each do |locator|
179
- element = find(locator).first
180
- return element if element
181
- end
182
- return nil
183
- end
184
184
 
185
185
  def find(locator)
186
186
  locator = current_scope.to_s + locator
@@ -1,10 +1,10 @@
1
1
  require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
 
3
- describe Capybara::Driver::FireWatir do
4
- before do
5
- @driver = Capybara::Driver::FireWatir.new(TestApp)
6
- end
7
-
8
- # it_should_behave_like "driver"
9
- # it_should_behave_like "driver with javascript support"
10
- end
3
+ # describe Capybara::Driver::FireWatir do
4
+ # before do
5
+ # @driver = Capybara::Driver::FireWatir.new(TestApp)
6
+ # end
7
+ #
8
+ # it_should_behave_like "driver"
9
+ # it_should_behave_like "driver with javascript support"
10
+ # end
@@ -1,10 +1,10 @@
1
1
  require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
 
3
- describe Capybara::Driver::SafariWatir do
4
- before do
5
- @driver = Capybara::Driver::SafariWatir.new(TestApp)
6
- end
7
-
8
- # it_should_behave_like "driver"
9
- # it_should_behave_like "driver with javascript support"
10
- end
3
+ # describe Capybara::Driver::SafariWatir do
4
+ # before do
5
+ # @driver = Capybara::Driver::SafariWatir.new(TestApp)
6
+ # end
7
+ #
8
+ # it_should_behave_like "driver"
9
+ # it_should_behave_like "driver with javascript support"
10
+ # end
@@ -594,6 +594,50 @@ shared_examples_for "session" do
594
594
  end
595
595
  end
596
596
  end
597
+
598
+ describe '#within_fieldset' do
599
+ before do
600
+ @session.visit('/fieldsets')
601
+ end
602
+
603
+ it "should restrict scope to a fieldset given by id" do
604
+ @session.within_fieldset("villain_fieldset") do
605
+ @session.fill_in("Name", :with => 'Goldfinger')
606
+ @session.click_button("Create")
607
+ end
608
+ extract_results(@session)['villain_name'].should == 'Goldfinger'
609
+ end
610
+
611
+ it "should restrict scope to a fieldset given by legend" do
612
+ @session.within_fieldset("Villain") do
613
+ @session.fill_in("Name", :with => 'Goldfinger')
614
+ @session.click_button("Create")
615
+ end
616
+ extract_results(@session)['villain_name'].should == 'Goldfinger'
617
+ end
618
+ end
619
+
620
+ describe '#within_table' do
621
+ before do
622
+ @session.visit('/tables')
623
+ end
624
+
625
+ it "should restrict scope to a fieldset given by id" do
626
+ @session.within_table("girl_table") do
627
+ @session.fill_in("Name", :with => 'Christmas')
628
+ @session.click_button("Create")
629
+ end
630
+ extract_results(@session)['girl_name'].should == 'Christmas'
631
+ end
632
+
633
+ it "should restrict scope to a fieldset given by legend" do
634
+ @session.within_table("Villain") do
635
+ @session.fill_in("Name", :with => 'Quantum')
636
+ @session.click_button("Create")
637
+ end
638
+ extract_results(@session)['villain_name'].should == 'Quantum'
639
+ end
640
+ end
597
641
  end
598
642
 
599
643
  describe Capybara::Session do
@@ -12,31 +12,7 @@ class TestApp < Sinatra::Base
12
12
  get '/foo' do
13
13
  'Another World'
14
14
  end
15
-
16
- get '/with_html' do
17
- erb :with_html
18
- end
19
-
20
- get '/with_js' do
21
- erb :with_js
22
- end
23
-
24
- get '/with_simple_html' do
25
- erb :with_simple_html
26
- end
27
-
28
- get '/with_scope' do
29
- erb :with_scope
30
- end
31
-
32
- get '/form' do
33
- erb :form
34
- end
35
-
36
- post '/redirect' do
37
- redirect '/redirect_again'
38
- end
39
-
15
+
40
16
  get '/redirect' do
41
17
  redirect '/redirect_again'
42
18
  end
@@ -48,12 +24,24 @@ class TestApp < Sinatra::Base
48
24
  get '/landed' do
49
25
  "You landed"
50
26
  end
51
-
52
- post '/form' do
27
+
28
+ get '/form/get' do
53
29
  '<pre id="results">' + params[:form].to_yaml + '</pre>'
54
30
  end
55
31
 
56
- get '/form/get' do
32
+ get '/favicon.ico' do
33
+ nil
34
+ end
35
+
36
+ get '/:view' do |view|
37
+ erb view.to_sym
38
+ end
39
+
40
+ post '/redirect' do
41
+ redirect '/redirect_again'
42
+ end
43
+
44
+ post '/form' do
57
45
  '<pre id="results">' + params[:form].to_yaml + '</pre>'
58
46
  end
59
47
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-20 00:00:00 +01:00
12
+ date: 2009-11-25 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.3
33
+ version: 0.2.4
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: selenium-webdriver
@@ -52,6 +52,16 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: 1.0.0
54
54
  version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 0.5.2
64
+ version:
55
65
  - !ruby/object:Gem::Dependency
56
66
  name: database_cleaner
57
67
  type: :runtime
@@ -62,6 +72,26 @@ dependencies:
62
72
  - !ruby/object:Gem::Version
63
73
  version: 0.2.3
64
74
  version:
75
+ - !ruby/object:Gem::Dependency
76
+ name: sinatra
77
+ type: :development
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 0.9.4
84
+ version:
85
+ - !ruby/object:Gem::Dependency
86
+ name: rspec
87
+ type: :development
88
+ version_requirement:
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 1.2.9
94
+ version:
65
95
  - !ruby/object:Gem::Dependency
66
96
  name: hoe
67
97
  type: :development
@@ -93,9 +123,7 @@ files:
93
123
  - Manifest.txt
94
124
  - README.rdoc
95
125
  - Rakefile
96
- - examples/webcat.rb
97
126
  - lib/capybara.rb
98
- - lib/capybara/core_ext/tcp_socket.rb
99
127
  - lib/capybara/cucumber.rb
100
128
  - lib/capybara/driver/culerity_driver.rb
101
129
  - lib/capybara/driver/firewatir_driver.rb
@@ -1,36 +0,0 @@
1
- session = Capybara::Session.new('http://localhost:3000')
2
-
3
- session.visit '/'
4
-
5
- session.driver.trigger :click, '//div[@id=foo]//a'
6
- session.driver.trigger :mouseover, '#foo a.bar' # will be ignored by drivers who do not support it
7
-
8
- nodelist = session.find 'li#foo a'
9
- nodelist.empty?
10
- nodelist.first.tag_name # => 'a'
11
- nodelist.first.text # => 'a cute link'
12
- nodelist.first.html # => 'a <em>cute</em> link'
13
- nodelist.first.attributes # => { :href => '/blah' }
14
- nodelist.first.trigger :click
15
-
16
- session.request.url # => '/blah'
17
- session.response.ok? # => true
18
-
19
- # fancy stuff, just builds on the stuff above!
20
-
21
- session.click_link 'a cute link'
22
- session.click_button 'an awesome button'
23
- session.within '#foo' do
24
- click_link 'a cute link'
25
- end
26
- session.fill_in 'foo', :with => 'bar'
27
- session.choose 'Monkey'
28
- session.check 'I am awesome'
29
- session.wait_for '#fooo"
30
-
31
- # In cuke:
32
-
33
- When 'I am awesome' do
34
- page.check 'I am awesome'
35
- page.click_button 'FooBar'
36
- end
@@ -1,26 +0,0 @@
1
- class TCPSocket
2
- def self.wait_for_service_with_timeout(options)
3
- start_time = Time.now
4
-
5
- until listening_service?(options)
6
- verbose_wait
7
-
8
- if options[:timeout] && (Time.now > start_time + options[:timeout])
9
- raise SocketError.new("Socket did not open within #{options[:timeout]} seconds")
10
- end
11
- end
12
- end
13
-
14
- def self.wait_for_service_termination_with_timeout(options)
15
- start_time = Time.now
16
-
17
- while listening_service?(options)
18
- verbose_wait
19
-
20
- if options[:timeout] && (Time.now > start_time + options[:timeout])
21
- raise SocketError.new("Socket did not terminate within #{options[:timeout]} seconds")
22
- end
23
- end
24
- end
25
- end
26
-