capybara 0.3.0 → 0.3.5

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.
Files changed (60) hide show
  1. data/Manifest.txt +4 -0
  2. data/README.rdoc +45 -5
  3. data/lib/capybara.rb +11 -4
  4. data/lib/capybara/driver/base.rb +3 -0
  5. data/lib/capybara/driver/celerity_driver.rb +44 -9
  6. data/lib/capybara/driver/rack_test_driver.rb +80 -16
  7. data/lib/capybara/driver/selenium_driver.rb +41 -9
  8. data/lib/capybara/dsl.rb +4 -10
  9. data/lib/capybara/node.rb +8 -0
  10. data/lib/capybara/rails.rb +8 -2
  11. data/lib/capybara/save_and_open_page.rb +5 -1
  12. data/lib/capybara/searchable.rb +17 -9
  13. data/lib/capybara/server.rb +35 -23
  14. data/lib/capybara/session.rb +91 -22
  15. data/lib/capybara/xpath.rb +66 -27
  16. data/spec/driver/celerity_driver_spec.rb +2 -2
  17. data/spec/driver/culerity_driver_spec.rb +1 -2
  18. data/spec/driver/rack_test_driver_spec.rb +0 -1
  19. data/spec/driver/remote_culerity_driver_spec.rb +9 -5
  20. data/spec/driver/selenium_driver_spec.rb +0 -1
  21. data/spec/drivers_spec.rb +24 -32
  22. data/spec/dsl/all_spec.rb +56 -25
  23. data/spec/dsl/attach_file_spec.rb +49 -51
  24. data/spec/dsl/check_spec.rb +12 -1
  25. data/spec/dsl/choose_spec.rb +19 -21
  26. data/spec/dsl/click_button_spec.rb +140 -87
  27. data/spec/dsl/click_link_spec.rb +88 -68
  28. data/spec/dsl/click_spec.rb +20 -22
  29. data/spec/dsl/current_url_spec.rb +6 -8
  30. data/spec/dsl/fill_in_spec.rb +75 -67
  31. data/spec/dsl/find_button_spec.rb +12 -14
  32. data/spec/dsl/find_by_id_spec.rb +16 -0
  33. data/spec/dsl/find_field_spec.rb +17 -19
  34. data/spec/dsl/find_link_spec.rb +13 -15
  35. data/spec/dsl/find_spec.rb +44 -23
  36. data/spec/dsl/has_button_spec.rb +32 -0
  37. data/spec/dsl/has_content_spec.rb +79 -81
  38. data/spec/dsl/has_css_spec.rb +81 -83
  39. data/spec/dsl/has_field_spec.rb +96 -0
  40. data/spec/dsl/has_link_spec.rb +33 -0
  41. data/spec/dsl/has_xpath_spec.rb +97 -89
  42. data/spec/dsl/locate_spec.rb +47 -26
  43. data/spec/dsl/select_spec.rb +61 -17
  44. data/spec/dsl/uncheck_spec.rb +17 -25
  45. data/spec/dsl/within_spec.rb +112 -104
  46. data/spec/public/test.js +3 -0
  47. data/spec/searchable_spec.rb +1 -1
  48. data/spec/server_spec.rb +7 -7
  49. data/spec/session/celerity_session_spec.rb +2 -2
  50. data/spec/session/culerity_session_spec.rb +1 -1
  51. data/spec/session_spec.rb +7 -0
  52. data/spec/session_with_javascript_support_spec.rb +139 -120
  53. data/spec/spec_helper.rb +7 -2
  54. data/spec/test_app.rb +8 -4
  55. data/spec/views/form.erb +50 -2
  56. data/spec/views/tables.erb +61 -1
  57. data/spec/views/with_html.erb +8 -2
  58. data/spec/views/with_js.erb +4 -0
  59. data/spec/xpath_spec.rb +17 -0
  60. metadata +6 -2
@@ -1,29 +1,21 @@
1
- module UncheckSpec
2
- shared_examples_for "uncheck" do
3
- describe "#uncheck" do
4
- before do
5
- @session.visit('/form')
6
- end
7
-
8
- it "should uncheck a checkbox by id" do
9
- @session.uncheck("form_pets_hamster")
10
- @session.click_button('awesome')
11
- extract_results(@session)['pets'].should include('dog')
12
- extract_results(@session)['pets'].should_not include('hamster')
13
- end
1
+ shared_examples_for "uncheck" do
2
+ describe "#uncheck" do
3
+ before do
4
+ @session.visit('/form')
5
+ end
14
6
 
15
- it "should uncheck a checkbox by label" do
16
- @session.uncheck("Hamster")
17
- @session.click_button('awesome')
18
- extract_results(@session)['pets'].should include('dog')
19
- extract_results(@session)['pets'].should_not include('hamster')
20
- end
7
+ it "should uncheck a checkbox by id" do
8
+ @session.uncheck("form_pets_hamster")
9
+ @session.click_button('awesome')
10
+ extract_results(@session)['pets'].should include('dog')
11
+ extract_results(@session)['pets'].should_not include('hamster')
12
+ end
21
13
 
22
- context "with a locator that doesn't exist" do
23
- it "should raise an error" do
24
- running { @session.uncheck('does not exist') }.should raise_error(Capybara::ElementNotFound)
25
- end
26
- end
14
+ it "should uncheck a checkbox by label" do
15
+ @session.uncheck("Hamster")
16
+ @session.click_button('awesome')
17
+ extract_results(@session)['pets'].should include('dog')
18
+ extract_results(@session)['pets'].should_not include('hamster')
27
19
  end
28
20
  end
29
- end
21
+ end
@@ -1,145 +1,153 @@
1
- module WithinSpec
2
- shared_examples_for "within" do
3
- describe '#within' do
4
- before do
5
- @session.visit('/with_scope')
6
- end
1
+ shared_examples_for "within" do
2
+ describe '#within' do
3
+ before do
4
+ @session.visit('/with_scope')
5
+ end
7
6
 
8
- context "with CSS selector" do
9
- it "should click links in the given scope" do
10
- @session.within(:css, "ul li[contains('With Simple HTML')]") do
11
- @session.click_link('Go')
12
- end
13
- @session.body.should include('Bar')
7
+ context "with CSS selector" do
8
+ it "should click links in the given scope" do
9
+ @session.within(:css, "ul li[contains('With Simple HTML')]") do
10
+ @session.click_link('Go')
14
11
  end
12
+ @session.body.should include('Bar')
15
13
  end
14
+ end
16
15
 
17
- context "with XPath selector" do
18
- it "should click links in the given scope" do
19
- @session.within(:xpath, "//li[contains(.,'With Simple HTML')]") do
20
- @session.click_link('Go')
21
- end
22
- @session.body.should include('Bar')
16
+ context "with XPath selector" do
17
+ it "should click links in the given scope" do
18
+ @session.within(:xpath, "//li[contains(.,'With Simple HTML')]") do
19
+ @session.click_link('Go')
23
20
  end
21
+ @session.body.should include('Bar')
24
22
  end
23
+ end
25
24
 
26
- context "with the default selector" do
27
- it "should use XPath" do
28
- @session.within("//li[contains(., 'With Simple HTML')]") do
29
- @session.click_link('Go')
30
- end
31
- @session.body.should include('Bar')
25
+ context "with the default selector" do
26
+ it "should use XPath" do
27
+ @session.within("//li[contains(., 'With Simple HTML')]") do
28
+ @session.click_link('Go')
32
29
  end
30
+ @session.body.should include('Bar')
33
31
  end
32
+ end
34
33
 
35
- context "with the default selector set to CSS" do
36
- after do
37
- Capybara.default_selector = :xpath
38
- end
39
-
40
- it "should use CSS" do
41
- Capybara.default_selector = :css
42
- @session.within("ul li[contains('With Simple HTML')]") do
43
- @session.click_link('Go')
44
- end
45
- @session.body.should include('Bar')
34
+ context "with the default selector set to CSS" do
35
+ before { Capybara.default_selector = :css }
36
+ it "should use CSS" do
37
+ @session.within("ul li[contains('With Simple HTML')]") do
38
+ @session.click_link('Go')
46
39
  end
40
+ @session.body.should include('Bar')
47
41
  end
42
+ after { Capybara.default_selector = :xpath }
43
+ end
48
44
 
49
- context "with click_link" do
50
- it "should click links in the given scope" do
51
- @session.within("//li[contains(.,'With Simple HTML')]") do
52
- @session.click_link('Go')
53
- end
54
- @session.body.should include('Bar')
45
+ context "with click_link" do
46
+ it "should click links in the given scope" do
47
+ @session.within("//li[contains(.,'With Simple HTML')]") do
48
+ @session.click_link('Go')
55
49
  end
50
+ @session.body.should include('Bar')
51
+ end
56
52
 
57
- context "with nested scopes" do
58
- it "should respect the inner scope" do
59
- @session.within("//div[@id='for_bar']") do
60
- @session.within("//li[contains(.,'Bar')]") do
61
- @session.click_link('Go')
62
- end
63
- end
64
- @session.body.should include('Another World')
65
- end
66
-
67
- it "should respect the outer scope" do
68
- @session.within("//div[@id='another_foo']") do
69
- @session.within("//li[contains(.,'With Simple HTML')]") do
70
- @session.click_link('Go')
71
- end
53
+ context "with nested scopes" do
54
+ it "should respect the inner scope" do
55
+ @session.within("//div[@id='for_bar']") do
56
+ @session.within("//li[contains(.,'Bar')]") do
57
+ @session.click_link('Go')
72
58
  end
73
- @session.body.should include('Hello world')
74
59
  end
60
+ @session.body.should include('Another World')
75
61
  end
76
62
 
77
- it "should raise an error if the scope is not found on the page" do
78
- running {
79
- @session.within("//div[@id='doesnotexist']") do
63
+ it "should respect the outer scope" do
64
+ @session.within("//div[@id='another_foo']") do
65
+ @session.within("//li[contains(.,'With Simple HTML')]") do
66
+ @session.click_link('Go')
80
67
  end
81
- }.should raise_error(Capybara::ElementNotFound)
68
+ end
69
+ @session.body.should include('Hello world')
82
70
  end
83
71
  end
84
72
 
85
- context "with forms" do
86
- it "should fill in a field and click a button" do
87
- @session.within("//li[contains(.,'Bar')]") do
88
- @session.click_button('Go')
73
+ it "should raise an error if the scope is not found on the page" do
74
+ running {
75
+ @session.within("//div[@id='doesnotexist']") do
89
76
  end
90
- extract_results(@session)['first_name'].should == 'Peter'
91
- @session.visit('/with_scope')
92
- @session.within("//li[contains(.,'Bar')]") do
93
- @session.fill_in('First Name', :with => 'Dagobert')
94
- @session.click_button('Go')
95
- end
96
- extract_results(@session)['first_name'].should == 'Dagobert'
97
- end
77
+ }.should raise_error(Capybara::ElementNotFound)
98
78
  end
99
- end
100
79
 
101
- describe '#within_fieldset' do
102
- before do
103
- @session.visit('/fieldsets')
80
+ it "should restore the scope when an error is raised" do
81
+ running {
82
+ @session.within("//div[@id='for_bar']") do
83
+ running {
84
+ running {
85
+ @session.within("//div[@id='doesnotexist']") do
86
+ end
87
+ }.should raise_error(Capybara::ElementNotFound)
88
+ }.should_not change { @session.has_xpath?("//div[@id='another_foo']") }.from(false)
89
+ end
90
+ }.should_not change { @session.has_xpath?("//div[@id='another_foo']") }.from(true)
104
91
  end
92
+ end
105
93
 
106
- it "should restrict scope to a fieldset given by id" do
107
- @session.within_fieldset("villain_fieldset") do
108
- @session.fill_in("Name", :with => 'Goldfinger')
109
- @session.click_button("Create")
94
+ context "with forms" do
95
+ it "should fill in a field and click a button" do
96
+ @session.within("//li[contains(.,'Bar')]") do
97
+ @session.click_button('Go')
110
98
  end
111
- extract_results(@session)['villain_name'].should == 'Goldfinger'
99
+ extract_results(@session)['first_name'].should == 'Peter'
100
+ @session.visit('/with_scope')
101
+ @session.within("//li[contains(.,'Bar')]") do
102
+ @session.fill_in('First Name', :with => 'Dagobert')
103
+ @session.click_button('Go')
104
+ end
105
+ extract_results(@session)['first_name'].should == 'Dagobert'
112
106
  end
107
+ end
108
+ end
113
109
 
114
- it "should restrict scope to a fieldset given by legend" do
115
- @session.within_fieldset("Villain") do
116
- @session.fill_in("Name", :with => 'Goldfinger')
117
- @session.click_button("Create")
118
- end
119
- extract_results(@session)['villain_name'].should == 'Goldfinger'
110
+ describe '#within_fieldset' do
111
+ before do
112
+ @session.visit('/fieldsets')
113
+ end
114
+
115
+ it "should restrict scope to a fieldset given by id" do
116
+ @session.within_fieldset("villain_fieldset") do
117
+ @session.fill_in("Name", :with => 'Goldfinger')
118
+ @session.click_button("Create")
120
119
  end
120
+ extract_results(@session)['villain_name'].should == 'Goldfinger'
121
121
  end
122
122
 
123
- describe '#within_table' do
124
- before do
125
- @session.visit('/tables')
123
+ it "should restrict scope to a fieldset given by legend" do
124
+ @session.within_fieldset("Villain") do
125
+ @session.fill_in("Name", :with => 'Goldfinger')
126
+ @session.click_button("Create")
126
127
  end
128
+ extract_results(@session)['villain_name'].should == 'Goldfinger'
129
+ end
130
+ end
127
131
 
128
- it "should restrict scope to a fieldset given by id" do
129
- @session.within_table("girl_table") do
130
- @session.fill_in("Name", :with => 'Christmas')
131
- @session.click_button("Create")
132
- end
133
- extract_results(@session)['girl_name'].should == 'Christmas'
132
+ describe '#within_table' do
133
+ before do
134
+ @session.visit('/tables')
135
+ end
136
+
137
+ it "should restrict scope to a fieldset given by id" do
138
+ @session.within_table("girl_table") do
139
+ @session.fill_in("Name", :with => 'Christmas')
140
+ @session.click_button("Create")
134
141
  end
142
+ extract_results(@session)['girl_name'].should == 'Christmas'
143
+ end
135
144
 
136
- it "should restrict scope to a fieldset given by legend" do
137
- @session.within_table("Villain") do
138
- @session.fill_in("Name", :with => 'Quantum')
139
- @session.click_button("Create")
140
- end
141
- extract_results(@session)['villain_name'].should == 'Quantum'
145
+ it "should restrict scope to a fieldset given by legend" do
146
+ @session.within_table("Villain") do
147
+ @session.fill_in("Name", :with => 'Quantum')
148
+ @session.click_button("Create")
142
149
  end
150
+ extract_results(@session)['villain_name'].should == 'Quantum'
143
151
  end
144
152
  end
145
- end
153
+ end
@@ -24,4 +24,7 @@ $(function() {
24
24
  activeRequests = 0;
25
25
  }, 500);
26
26
  });
27
+ $('#with_focus_event').focus(function() {
28
+ $('body').append('<p id="focus_event_triggered">Focus Event triggered</p>')
29
+ });
27
30
  });
@@ -58,4 +58,4 @@ module Capybara
58
58
  end #all
59
59
  end
60
60
 
61
- end
61
+ end
@@ -4,7 +4,7 @@ describe Capybara::Server do
4
4
 
5
5
  it "should spool up a rack server" do
6
6
  @app = proc { |env| [200, {}, "Hello Server!"]}
7
- @server = Capybara::Server.new(@app)
7
+ @server = Capybara::Server.new(@app).boot
8
8
 
9
9
  @res = Net::HTTP.start(@server.host, @server.port) { |http| http.get('/') }
10
10
 
@@ -15,8 +15,8 @@ describe Capybara::Server do
15
15
  @app1 = proc { |env| [200, {}, "Hello Server!"]}
16
16
  @app2 = proc { |env| [200, {}, "Hello Second Server!"]}
17
17
 
18
- @server1 = Capybara::Server.new(@app1)
19
- @server2 = Capybara::Server.new(@app2)
18
+ @server1 = Capybara::Server.new(@app1).boot
19
+ @server2 = Capybara::Server.new(@app2).boot
20
20
 
21
21
  @res1 = Net::HTTP.start(@server1.host, @server1.port) { |http| http.get('/') }
22
22
  @res1.body.should include('Hello Server')
@@ -29,10 +29,10 @@ describe Capybara::Server do
29
29
  @app1 = proc { |env| [200, {}, "Hello Server!"]}
30
30
  @app2 = proc { |env| [200, {}, "Hello Second Server!"]}
31
31
 
32
- @server1a = Capybara::Server.new(@app1)
33
- @server1b = Capybara::Server.new(@app1)
34
- @server2a = Capybara::Server.new(@app2)
35
- @server2b = Capybara::Server.new(@app2)
32
+ @server1a = Capybara::Server.new(@app1).boot
33
+ @server1b = Capybara::Server.new(@app1).boot
34
+ @server2a = Capybara::Server.new(@app2).boot
35
+ @server2b = Capybara::Server.new(@app2).boot
36
36
 
37
37
  @res1 = Net::HTTP.start(@server1b.host, @server1b.port) { |http| http.get('/') }
38
38
  @res1.body.should include('Hello Server')
@@ -2,7 +2,7 @@ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
 
3
3
  if RUBY_PLATFORM =~ /java/
4
4
  describe Capybara::Driver::Celerity do
5
- before do
5
+ before(:all) do
6
6
  @session = Capybara::Session.new(:celerity, TestApp)
7
7
  end
8
8
 
@@ -24,4 +24,4 @@ if RUBY_PLATFORM =~ /java/
24
24
  end
25
25
  else
26
26
  puts "#{File.basename(__FILE__)} requires JRuby; skipping.."
27
- end
27
+ end
@@ -2,7 +2,7 @@ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
 
3
3
  describe Capybara::Session do
4
4
  context 'with culerity driver' do
5
- before do
5
+ before(:all) do
6
6
  @session = Capybara::Session.new(:culerity, TestApp)
7
7
  end
8
8
 
@@ -46,13 +46,20 @@ shared_examples_for "session" do
46
46
  it_should_behave_like "find_button"
47
47
  it_should_behave_like "find_field"
48
48
  it_should_behave_like "find_link"
49
+ it_should_behave_like "find_by_id"
49
50
  it_should_behave_like "find"
50
51
  it_should_behave_like "has_content"
51
52
  it_should_behave_like "has_css"
52
53
  it_should_behave_like "has_css"
53
54
  it_should_behave_like "has_xpath"
55
+ it_should_behave_like "has_link"
56
+ it_should_behave_like "has_button"
57
+ it_should_behave_like "has_field"
58
+ it_should_behave_like "has_select"
59
+ it_should_behave_like "has_table"
54
60
  it_should_behave_like "select"
55
61
  it_should_behave_like "uncheck"
62
+ it_should_behave_like "unselect"
56
63
  it_should_behave_like "locate"
57
64
  it_should_behave_like "within"
58
65
  it_should_behave_like "current_url"
@@ -3,163 +3,182 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
3
3
  require 'nokogiri'
4
4
 
5
5
  shared_examples_for "session with javascript support" do
6
- describe '#body' do
7
- it "should return the current state of the page" do
8
- @session.visit('/with_js')
9
- @session.body.should include('I changed it')
10
- @session.body.should_not include('This is text')
6
+ describe 'all JS specs' do
7
+ before do
8
+ Capybara.default_wait_time = 1
11
9
  end
12
- end
13
10
 
14
- describe '#source' do
15
- it "should return the original, unmodified source of the page" do
16
- pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
17
- @session.visit('/with_js')
18
- @session.source.should include('This is text')
19
- @session.source.should_not include('I changed it')
11
+ after do
12
+ Capybara.default_wait_time = 0
13
+ end
14
+
15
+ describe '#find' do
16
+ it "should allow triggering of custom JS events" do
17
+ pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
18
+ @session.visit('/with_js')
19
+ @session.find(:css, '#with_focus_event').trigger(:focus)
20
+ @session.should have_css('#focus_event_triggered')
21
+ end
20
22
  end
21
- end
22
23
 
23
- describe "#evaluate_script" do
24
- it "should return the evaluated script" do
25
- @session.visit('/with_js')
26
- @session.evaluate_script("1+3").should == 4
24
+ describe '#body' do
25
+ it "should return the current state of the page" do
26
+ @session.visit('/with_js')
27
+ @session.body.should include('I changed it')
28
+ @session.body.should_not include('This is text')
29
+ end
27
30
  end
28
- end
29
31
 
30
- describe '#locate' do
31
- it "should wait for asynchronous load" do
32
- @session.visit('/with_js')
33
- @session.click_link('Click me')
34
- @session.locate("//a[contains(.,'Has been clicked')]")[:href].should == '#'
32
+ describe '#source' do
33
+ it "should return the original, unmodified source of the page" do
34
+ pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
35
+ @session.visit('/with_js')
36
+ @session.source.should include('This is text')
37
+ @session.source.should_not include('I changed it')
38
+ end
35
39
  end
36
- end
37
40
 
38
- describe '#wait_until' do
39
- before do
40
- @default_timeout = Capybara.default_wait_time
41
+ describe "#evaluate_script" do
42
+ it "should return the evaluated script" do
43
+ @session.visit('/with_js')
44
+ @session.evaluate_script("1+3").should == 4
45
+ end
41
46
  end
42
47
 
43
- after do
44
- Capybara.default_wait_time = @default_wait_time
48
+ describe '#locate' do
49
+ it "should wait for asynchronous load" do
50
+ @session.visit('/with_js')
51
+ @session.click_link('Click me')
52
+ @session.locate("//a[contains(.,'Has been clicked')]")[:href].should == '#'
53
+ end
45
54
  end
46
55
 
47
- it "should wait for block to return true" do
48
- @session.visit('/with_js')
49
- @session.select('My Waiting Option', :from => 'waiter')
50
- @session.evaluate_script('activeRequests == 1').should be_true
51
- @session.wait_until do
52
- @session.evaluate_script('activeRequests == 0')
56
+ describe '#wait_until' do
57
+ before do
58
+ @default_timeout = Capybara.default_wait_time
59
+ end
60
+
61
+ after do
62
+ Capybara.default_wait_time = @default_wait_time
53
63
  end
54
- @session.evaluate_script('activeRequests == 0').should be_true
55
- end
56
64
 
57
- it "should raise Capybara::TimeoutError if block doesn't return true within timeout" do
58
- @session.visit('/with_html')
59
- Proc.new do
60
- @session.wait_until(0.1) do
61
- @session.find('//div[@id="nosuchthing"]')
65
+ it "should wait for block to return true" do
66
+ @session.visit('/with_js')
67
+ @session.select('My Waiting Option', :from => 'waiter')
68
+ @session.evaluate_script('activeRequests == 1').should be_true
69
+ @session.wait_until do
70
+ @session.evaluate_script('activeRequests == 0')
62
71
  end
63
- end.should raise_error(::Capybara::TimeoutError)
64
- end
72
+ @session.evaluate_script('activeRequests == 0').should be_true
73
+ end
65
74
 
66
- it "should accept custom timeout in seconds" do
67
- start = Time.now
68
- Capybara.default_wait_time = 5
69
- begin
70
- @session.wait_until(0.1) { false }
71
- rescue Capybara::TimeoutError; end
72
- (Time.now - start).should be_close(0.1, 0.1)
73
- end
75
+ it "should raise Capybara::TimeoutError if block doesn't return true within timeout" do
76
+ @session.visit('/with_html')
77
+ Proc.new do
78
+ @session.wait_until(0.1) do
79
+ @session.find('//div[@id="nosuchthing"]')
80
+ end
81
+ end.should raise_error(::Capybara::TimeoutError)
82
+ end
74
83
 
75
- it "should default to Capybara.default_wait_time before timeout" do
76
- start = Time.now
77
- Capybara.default_wait_time = 0.2
78
- begin
79
- @session.wait_until { false }
80
- rescue Capybara::TimeoutError; end
81
- (Time.now - start).should be_close(0.2, 0.1)
84
+ it "should accept custom timeout in seconds" do
85
+ start = Time.now
86
+ Capybara.default_wait_time = 5
87
+ begin
88
+ @session.wait_until(0.1) { false }
89
+ rescue Capybara::TimeoutError; end
90
+ (Time.now - start).should be_close(0.1, 0.1)
91
+ end
92
+
93
+ it "should default to Capybara.default_wait_time before timeout" do
94
+ start = Time.now
95
+ Capybara.default_wait_time = 0.2
96
+ begin
97
+ @session.wait_until { false }
98
+ rescue Capybara::TimeoutError; end
99
+ (Time.now - start).should be_close(0.2, 0.1)
100
+ end
82
101
  end
83
- end
84
102
 
85
- describe '#click' do
86
- it "should wait for asynchronous load" do
87
- @session.visit('/with_js')
88
- @session.click_link('Click me')
89
- @session.click('Has been clicked')
103
+ describe '#click' do
104
+ it "should wait for asynchronous load" do
105
+ @session.visit('/with_js')
106
+ @session.click_link('Click me')
107
+ @session.click('Has been clicked')
108
+ end
90
109
  end
91
- end
92
110
 
93
- describe '#click_link' do
94
- it "should wait for asynchronous load" do
95
- @session.visit('/with_js')
96
- @session.click_link('Click me')
97
- @session.click_link('Has been clicked')
111
+ describe '#click_link' do
112
+ it "should wait for asynchronous load" do
113
+ @session.visit('/with_js')
114
+ @session.click_link('Click me')
115
+ @session.click_link('Has been clicked')
116
+ end
98
117
  end
99
- end
100
118
 
101
- describe '#click_button' do
102
- it "should wait for asynchronous load" do
103
- @session.visit('/with_js')
104
- @session.click_link('Click me')
105
- @session.click_button('New Here')
119
+ describe '#click_button' do
120
+ it "should wait for asynchronous load" do
121
+ @session.visit('/with_js')
122
+ @session.click_link('Click me')
123
+ @session.click_button('New Here')
124
+ end
106
125
  end
107
- end
108
126
 
109
- describe '#fill_in' do
110
- it "should wait for asynchronous load" do
111
- @session.visit('/with_js')
112
- @session.click_link('Click me')
113
- @session.fill_in('new_field', :with => 'Testing...')
127
+ describe '#fill_in' do
128
+ it "should wait for asynchronous load" do
129
+ @session.visit('/with_js')
130
+ @session.click_link('Click me')
131
+ @session.fill_in('new_field', :with => 'Testing...')
132
+ end
114
133
  end
115
- end
116
134
 
117
- describe '#has_xpath?' do
118
- it "should wait for content to appear" do
119
- @session.visit('/with_js')
120
- @session.click_link('Click me')
121
- @session.should have_xpath("//input[@type='submit' and @value='New Here']")
135
+ describe '#has_xpath?' do
136
+ it "should wait for content to appear" do
137
+ @session.visit('/with_js')
138
+ @session.click_link('Click me')
139
+ @session.should have_xpath("//input[@type='submit' and @value='New Here']")
140
+ end
122
141
  end
123
- end
124
142
 
125
- describe '#has_no_xpath?' do
126
- it "should wait for content to disappear" do
127
- @session.visit('/with_js')
128
- @session.click_link('Click me')
129
- @session.should have_no_xpath("//p[@id='change']")
143
+ describe '#has_no_xpath?' do
144
+ it "should wait for content to disappear" do
145
+ @session.visit('/with_js')
146
+ @session.click_link('Click me')
147
+ @session.should have_no_xpath("//p[@id='change']")
148
+ end
130
149
  end
131
- end
132
150
 
133
- describe '#has_css?' do
134
- it "should wait for content to appear" do
135
- @session.visit('/with_js')
136
- @session.click_link('Click me')
137
- @session.should have_css("input[type='submit'][value='New Here']")
151
+ describe '#has_css?' do
152
+ it "should wait for content to appear" do
153
+ @session.visit('/with_js')
154
+ @session.click_link('Click me')
155
+ @session.should have_css("input[type='submit'][value='New Here']")
156
+ end
138
157
  end
139
- end
140
158
 
141
- describe '#has_no_xpath?' do
142
- it "should wait for content to disappear" do
143
- @session.visit('/with_js')
144
- @session.click_link('Click me')
145
- @session.should have_no_css("p#change")
159
+ describe '#has_no_xpath?' do
160
+ it "should wait for content to disappear" do
161
+ @session.visit('/with_js')
162
+ @session.click_link('Click me')
163
+ @session.should have_no_css("p#change")
164
+ end
146
165
  end
147
- end
148
166
 
149
- describe '#has_content?' do
150
- it "should wait for content to appear" do
151
- @session.visit('/with_js')
152
- @session.click_link('Click me')
153
- @session.should have_content("Has been clicked")
167
+ describe '#has_content?' do
168
+ it "should wait for content to appear" do
169
+ @session.visit('/with_js')
170
+ @session.click_link('Click me')
171
+ @session.should have_content("Has been clicked")
172
+ end
154
173
  end
155
- end
156
174
 
157
- describe '#has_no_content?' do
158
- it "should wait for content to disappear" do
159
- @session.visit('/with_js')
160
- @session.click_link('Click me')
161
- @session.should have_no_content("I changed it")
175
+ describe '#has_no_content?' do
176
+ it "should wait for content to disappear" do
177
+ @session.visit('/with_js')
178
+ @session.click_link('Click me')
179
+ @session.should have_no_content("I changed it")
180
+ end
162
181
  end
163
- end
164
182
 
183
+ end
165
184
  end