capybara_minitest_spec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +4 -0
  3. data/.gitmodules +3 -0
  4. data/.rvmrc +1 -0
  5. data/Gemfile +7 -0
  6. data/README.md +31 -0
  7. data/Rakefile +9 -0
  8. data/capybara_minitest_spec.gemspec +25 -0
  9. data/lib/capybara_minitest_spec/version.rb +3 -0
  10. data/lib/capybara_minitest_spec.rb +45 -0
  11. data/test/matchers_spec.rb +447 -0
  12. data/test/spec_helper.rb +28 -0
  13. data/test_app/driver.rb +297 -0
  14. data/test_app/fixtures/capybara.jpg +3 -0
  15. data/test_app/fixtures/test_file.txt +1 -0
  16. data/test_app/public/test.js +43 -0
  17. data/test_app/session/all_spec.rb +78 -0
  18. data/test_app/session/attach_file_spec.rb +73 -0
  19. data/test_app/session/check_spec.rb +65 -0
  20. data/test_app/session/choose_spec.rb +26 -0
  21. data/test_app/session/click_button_spec.rb +304 -0
  22. data/test_app/session/click_link_or_button_spec.rb +36 -0
  23. data/test_app/session/click_link_spec.rb +119 -0
  24. data/test_app/session/current_host_spec.rb +68 -0
  25. data/test_app/session/current_url_spec.rb +15 -0
  26. data/test_app/session/fill_in_spec.rb +125 -0
  27. data/test_app/session/find_button_spec.rb +18 -0
  28. data/test_app/session/find_by_id_spec.rb +18 -0
  29. data/test_app/session/find_field_spec.rb +26 -0
  30. data/test_app/session/find_link_spec.rb +19 -0
  31. data/test_app/session/find_spec.rb +149 -0
  32. data/test_app/session/first_spec.rb +105 -0
  33. data/test_app/session/has_button_spec.rb +32 -0
  34. data/test_app/session/has_content_spec.rb +106 -0
  35. data/test_app/session/has_css_spec.rb +243 -0
  36. data/test_app/session/has_field_spec.rb +192 -0
  37. data/test_app/session/has_link_spec.rb +37 -0
  38. data/test_app/session/has_select_spec.rb +129 -0
  39. data/test_app/session/has_selector_spec.rb +129 -0
  40. data/test_app/session/has_table_spec.rb +96 -0
  41. data/test_app/session/has_xpath_spec.rb +123 -0
  42. data/test_app/session/headers.rb +19 -0
  43. data/test_app/session/javascript.rb +289 -0
  44. data/test_app/session/response_code.rb +19 -0
  45. data/test_app/session/select_spec.rb +113 -0
  46. data/test_app/session/text_spec.rb +19 -0
  47. data/test_app/session/uncheck_spec.rb +21 -0
  48. data/test_app/session/unselect_spec.rb +61 -0
  49. data/test_app/session/within_spec.rb +178 -0
  50. data/test_app/session.rb +154 -0
  51. data/test_app/test_app.rb +142 -0
  52. data/test_app/views/buttons.erb +4 -0
  53. data/test_app/views/fieldsets.erb +29 -0
  54. data/test_app/views/form.erb +365 -0
  55. data/test_app/views/frame_one.erb +8 -0
  56. data/test_app/views/frame_two.erb +8 -0
  57. data/test_app/views/header_links.erb +7 -0
  58. data/test_app/views/host_links.erb +12 -0
  59. data/test_app/views/popup_one.erb +8 -0
  60. data/test_app/views/popup_two.erb +8 -0
  61. data/test_app/views/postback.erb +13 -0
  62. data/test_app/views/tables.erb +122 -0
  63. data/test_app/views/with_html.erb +74 -0
  64. data/test_app/views/with_html_entities.erb +1 -0
  65. data/test_app/views/with_js.erb +48 -0
  66. data/test_app/views/with_scope.erb +36 -0
  67. data/test_app/views/with_simple_html.erb +1 -0
  68. data/test_app/views/within_frames.erb +10 -0
  69. data/test_app/views/within_popups.erb +25 -0
  70. metadata +158 -0
@@ -0,0 +1,129 @@
1
+ shared_examples_for "has_selector" do
2
+ describe '#has_selector?' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ it "should be true if the given selector is on the page" do
8
+ @session.should have_selector(:xpath, "//p")
9
+ @session.should have_selector(:css, "p a#foo")
10
+ @session.should have_selector(:foo)
11
+ @session.should have_selector("//p[contains(.,'est')]")
12
+ end
13
+
14
+ it "should be false if the given selector is not on the page" do
15
+ @session.should_not have_selector(:xpath, "//abbr")
16
+ @session.should_not have_selector(:css, "p a#doesnotexist")
17
+ @session.should_not have_selector(:doesnotexist)
18
+ @session.should_not have_selector("//p[contains(.,'thisstringisnotonpage')]")
19
+ end
20
+
21
+ it "should use default selector" do
22
+ Capybara.default_selector = :css
23
+ @session.should_not have_selector("p a#doesnotexist")
24
+ @session.should have_selector("p a#foo")
25
+ end
26
+
27
+ it "should respect scopes" do
28
+ @session.within "//p[@id='first']" do
29
+ @session.should have_selector(".//a[@id='foo']")
30
+ @session.should_not have_selector(".//a[@id='red']")
31
+ end
32
+ end
33
+
34
+ context "with count" do
35
+ it "should be true if the content is on the page the given number of times" do
36
+ @session.should have_selector("//p", :count => 3)
37
+ @session.should have_selector("//p//a[@id='foo']", :count => 1)
38
+ @session.should have_selector("//p[contains(.,'est')]", :count => 1)
39
+ end
40
+
41
+ it "should be false if the content is on the page the given number of times" do
42
+ @session.should_not have_selector("//p", :count => 6)
43
+ @session.should_not have_selector("//p//a[@id='foo']", :count => 2)
44
+ @session.should_not have_selector("//p[contains(.,'est')]", :count => 5)
45
+ end
46
+
47
+ it "should be false if the content isn't on the page at all" do
48
+ @session.should_not have_selector("//abbr", :count => 2)
49
+ @session.should_not have_selector("//p//a[@id='doesnotexist']", :count => 1)
50
+ end
51
+ end
52
+
53
+ context "with text" do
54
+ it "should discard all matches where the given string is not contained" do
55
+ @session.should have_selector("//p//a", :text => "Redirect", :count => 1)
56
+ @session.should_not have_selector("//p", :text => "Doesnotexist")
57
+ end
58
+
59
+ it "should discard all matches where the given regexp is not matched" do
60
+ @session.should have_selector("//p//a", :text => /re[dab]i/i, :count => 1)
61
+ @session.should_not have_selector("//p//a", :text => /Red$/)
62
+ end
63
+ end
64
+ end
65
+
66
+ describe '#has_no_selector?' do
67
+ before do
68
+ @session.visit('/with_html')
69
+ end
70
+
71
+ it "should be false if the given selector is on the page" do
72
+ @session.should_not have_no_selector(:xpath, "//p")
73
+ @session.should_not have_no_selector(:css, "p a#foo")
74
+ @session.should_not have_no_selector(:foo)
75
+ @session.should_not have_no_selector("//p[contains(.,'est')]")
76
+ end
77
+
78
+ it "should be true if the given selector is not on the page" do
79
+ @session.should have_no_selector(:xpath, "//abbr")
80
+ @session.should have_no_selector(:css, "p a#doesnotexist")
81
+ @session.should have_no_selector(:doesnotexist)
82
+ @session.should have_no_selector("//p[contains(.,'thisstringisnotonpage')]")
83
+ end
84
+
85
+ it "should use default selector" do
86
+ Capybara.default_selector = :css
87
+ @session.should have_no_selector("p a#doesnotexist")
88
+ @session.should_not have_no_selector("p a#foo")
89
+ end
90
+
91
+ it "should respect scopes" do
92
+ @session.within "//p[@id='first']" do
93
+ @session.should_not have_no_selector(".//a[@id='foo']")
94
+ @session.should have_no_selector(".//a[@id='red']")
95
+ end
96
+ end
97
+
98
+ context "with count" do
99
+ it "should be false if the content is on the page the given number of times" do
100
+ @session.should_not have_no_selector("//p", :count => 3)
101
+ @session.should_not have_no_selector("//p//a[@id='foo']", :count => 1)
102
+ @session.should_not have_no_selector("//p[contains(.,'est')]", :count => 1)
103
+ end
104
+
105
+ it "should be true if the content is on the page the wrong number of times" do
106
+ @session.should have_no_selector("//p", :count => 6)
107
+ @session.should have_no_selector("//p//a[@id='foo']", :count => 2)
108
+ @session.should have_no_selector("//p[contains(.,'est')]", :count => 5)
109
+ end
110
+
111
+ it "should be true if the content isn't on the page at all" do
112
+ @session.should have_no_selector("//abbr", :count => 2)
113
+ @session.should have_no_selector("//p//a[@id='doesnotexist']", :count => 1)
114
+ end
115
+ end
116
+
117
+ context "with text" do
118
+ it "should discard all matches where the given string is contained" do
119
+ @session.should_not have_no_selector("//p//a", :text => "Redirect", :count => 1)
120
+ @session.should have_no_selector("//p", :text => "Doesnotexist")
121
+ end
122
+
123
+ it "should discard all matches where the given regexp is matched" do
124
+ @session.should_not have_no_selector("//p//a", :text => /re[dab]i/i, :count => 1)
125
+ @session.should have_no_selector("//p//a", :text => /Red$/)
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,96 @@
1
+ shared_examples_for "has_table" do
2
+ describe '#has_table?' do
3
+ before do
4
+ @session.visit('/tables')
5
+ end
6
+
7
+ it "should be true if the field is on the page" do
8
+ @session.should have_table('Deaths')
9
+ @session.should have_table('villain_table')
10
+ end
11
+
12
+ it "should be false if the field is not on the page" do
13
+ @session.should_not have_table('Monkey')
14
+ end
15
+
16
+ context 'with rows' do
17
+ it "should be true if a table with the given rows is on the page" do
18
+ @session.should have_table('Ransom', :rows => [['2007', '$300', '$100']])
19
+ @session.should have_table('Deaths', :rows => [['2007', '66', '7'], ['2008', '123', '12']])
20
+ end
21
+
22
+ it "should be true if the given rows are incomplete" do
23
+ @session.should have_table('Ransom', :rows => [['$300', '$100']])
24
+ end
25
+
26
+ it "should be false if the given table is not on the page" do
27
+ @session.should_not have_table('Does not exist', :selected => 'John')
28
+ end
29
+
30
+ it "should be false if the given rows contain incorrect elements" do
31
+ @session.should_not have_table('Ransom', :rows => [['2007', '$1000000000', '$100']])
32
+ end
33
+
34
+ it "should be false if the given rows are incorrectly ordered" do
35
+ @session.should_not have_table('Ransom', :rows => [['2007', '$100', '$300']])
36
+ end
37
+
38
+ it "should be false if the only some of the given rows are correct" do
39
+ @session.should_not have_table('Deaths', :rows => [['2007', '66', '7'], ['2007', '99999999', '12']])
40
+ end
41
+
42
+ it "should be false if the given rows are out of order" do
43
+ @session.should_not have_table('Deaths', :rows => [['2007', '123', '12'], ['2007', '66', '7']])
44
+ end
45
+ end
46
+ end
47
+
48
+ describe '#has_no_table?' do
49
+ before do
50
+ @session.visit('/tables')
51
+ end
52
+
53
+ it "should be false if the field is on the page" do
54
+ @session.should_not have_no_table('Deaths')
55
+ @session.should_not have_no_table('villain_table')
56
+ end
57
+
58
+ it "should be true if the field is not on the page" do
59
+ @session.should have_no_table('Monkey')
60
+ end
61
+
62
+ context 'with rows' do
63
+ it "should be false if a table with the given rows is on the page" do
64
+ @session.should_not have_no_table('Ransom', :rows => [['2007', '$300', '$100']])
65
+ @session.should_not have_no_table('Deaths', :rows => [['2007', '66', '7'], ['2008', '123', '12']])
66
+ end
67
+
68
+ it "should be false if the given rows are incomplete" do
69
+ @session.should_not have_no_table('Ransom', :rows => [['$300', '$100']])
70
+ end
71
+
72
+ it "should be true if the given table is not on the page" do
73
+ @session.should have_no_table('Does not exist', :selected => 'John')
74
+ end
75
+
76
+ it "should be true if the given rows contain incorrect elements" do
77
+ @session.should have_no_table('Ransom', :rows => [['2007', '$1000000000', '$100']])
78
+ end
79
+
80
+ it "should be true if the given rows are incorrectly ordered" do
81
+ @session.should have_no_table('Ransom', :rows => [['2007', '$100', '$300']])
82
+ end
83
+
84
+ it "should be true if the only some of the given rows are correct" do
85
+ @session.should have_no_table('Deaths', :rows => [['2007', '66', '7'], ['2007', '99999999', '12']])
86
+ end
87
+
88
+ it "should be true if the given rows are out of order" do
89
+ @session.should have_no_table('Deaths', :rows => [['2007', '123', '12'], ['2007', '66', '7']])
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+
96
+
@@ -0,0 +1,123 @@
1
+ shared_examples_for "has_xpath" do
2
+ describe '#has_xpath?' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ it "should be true if the given selector is on the page" do
8
+ @session.should have_xpath("//p")
9
+ @session.should have_xpath("//p//a[@id='foo']")
10
+ @session.should have_xpath("//p[contains(.,'est')]")
11
+ end
12
+
13
+ it "should be false if the given selector is not on the page" do
14
+ @session.should_not have_xpath("//abbr")
15
+ @session.should_not have_xpath("//p//a[@id='doesnotexist']")
16
+ @session.should_not have_xpath("//p[contains(.,'thisstringisnotonpage')]")
17
+ end
18
+
19
+ it "should use xpath even if default selector is CSS" do
20
+ Capybara.default_selector = :css
21
+ @session.should_not have_xpath("//p//a[@id='doesnotexist']")
22
+ end
23
+
24
+ it "should respect scopes" do
25
+ @session.within "//p[@id='first']" do
26
+ @session.should have_xpath(".//a[@id='foo']")
27
+ @session.should_not have_xpath(".//a[@id='red']")
28
+ end
29
+ end
30
+
31
+ context "with count" do
32
+ it "should be true if the content is on the page the given number of times" do
33
+ @session.should have_xpath("//p", :count => 3)
34
+ @session.should have_xpath("//p//a[@id='foo']", :count => 1)
35
+ @session.should have_xpath("//p[contains(.,'est')]", :count => 1)
36
+ end
37
+
38
+ it "should be false if the content is on the page the given number of times" do
39
+ @session.should_not have_xpath("//p", :count => 6)
40
+ @session.should_not have_xpath("//p//a[@id='foo']", :count => 2)
41
+ @session.should_not have_xpath("//p[contains(.,'est')]", :count => 5)
42
+ end
43
+
44
+ it "should be false if the content isn't on the page at all" do
45
+ @session.should_not have_xpath("//abbr", :count => 2)
46
+ @session.should_not have_xpath("//p//a[@id='doesnotexist']", :count => 1)
47
+ end
48
+ end
49
+
50
+ context "with text" do
51
+ it "should discard all matches where the given string is not contained" do
52
+ @session.should have_xpath("//p//a", :text => "Redirect", :count => 1)
53
+ @session.should_not have_xpath("//p", :text => "Doesnotexist")
54
+ end
55
+
56
+ it "should discard all matches where the given regexp is not matched" do
57
+ @session.should have_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
58
+ @session.should_not have_xpath("//p//a", :text => /Red$/)
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '#has_no_xpath?' do
64
+ before do
65
+ @session.visit('/with_html')
66
+ end
67
+
68
+ it "should be false if the given selector is on the page" do
69
+ @session.should_not have_no_xpath("//p")
70
+ @session.should_not have_no_xpath("//p//a[@id='foo']")
71
+ @session.should_not have_no_xpath("//p[contains(.,'est')]")
72
+ end
73
+
74
+ it "should be true if the given selector is not on the page" do
75
+ @session.should have_no_xpath("//abbr")
76
+ @session.should have_no_xpath("//p//a[@id='doesnotexist']")
77
+ @session.should have_no_xpath("//p[contains(.,'thisstringisnotonpage')]")
78
+ end
79
+
80
+ it "should use xpath even if default selector is CSS" do
81
+ Capybara.default_selector = :css
82
+ @session.should have_no_xpath("//p//a[@id='doesnotexist']")
83
+ end
84
+
85
+ it "should respect scopes" do
86
+ @session.within "//p[@id='first']" do
87
+ @session.should_not have_no_xpath(".//a[@id='foo']")
88
+ @session.should have_no_xpath(".//a[@id='red']")
89
+ end
90
+ end
91
+
92
+ context "with count" do
93
+ it "should be false if the content is on the page the given number of times" do
94
+ @session.should_not have_no_xpath("//p", :count => 3)
95
+ @session.should_not have_no_xpath("//p//a[@id='foo']", :count => 1)
96
+ @session.should_not have_no_xpath("//p[contains(.,'est')]", :count => 1)
97
+ end
98
+
99
+ it "should be true if the content is on the page the wrong number of times" do
100
+ @session.should have_no_xpath("//p", :count => 6)
101
+ @session.should have_no_xpath("//p//a[@id='foo']", :count => 2)
102
+ @session.should have_no_xpath("//p[contains(.,'est')]", :count => 5)
103
+ end
104
+
105
+ it "should be true if the content isn't on the page at all" do
106
+ @session.should have_no_xpath("//abbr", :count => 2)
107
+ @session.should have_no_xpath("//p//a[@id='doesnotexist']", :count => 1)
108
+ end
109
+ end
110
+
111
+ context "with text" do
112
+ it "should discard all matches where the given string is contained" do
113
+ @session.should_not have_no_xpath("//p//a", :text => "Redirect", :count => 1)
114
+ @session.should have_no_xpath("//p", :text => "Doesnotexist")
115
+ end
116
+
117
+ it "should discard all matches where the given regexp is matched" do
118
+ @session.should_not have_no_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
119
+ @session.should have_no_xpath("//p//a", :text => /Red$/)
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,19 @@
1
+ shared_examples_for "session with headers support" do
2
+ describe '#response_headers' do
3
+ it "should return response headers" do
4
+ @session.visit('/with_simple_html')
5
+ @session.response_headers['Content-Type'].should =~ %r(text/html)
6
+ end
7
+ end
8
+ end
9
+
10
+ shared_examples_for "session without headers support" do
11
+ describe "#response_headers" do
12
+ before{ @session.visit('/with_simple_html') }
13
+ it "should raise an error" do
14
+ running {
15
+ @session.response_headers
16
+ }.should raise_error(Capybara::NotSupportedByDriverError)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,289 @@
1
+ shared_examples_for "session with javascript support" do
2
+ describe 'all JS specs' do
3
+ before do
4
+ Capybara.default_wait_time = 1
5
+ end
6
+
7
+ after do
8
+ Capybara.default_wait_time = 0
9
+ end
10
+
11
+ describe 'Node#drag_to' do
12
+ it "should drag and drop an object" do
13
+ @session.visit('/with_js')
14
+ element = @session.find('//div[@id="drag"]')
15
+ target = @session.find('//div[@id="drop"]')
16
+ element.drag_to(target)
17
+ @session.find('//div[contains(., "Dropped!")]').should_not be_nil
18
+ end
19
+ end
20
+
21
+ describe 'Node#reload' do
22
+ context "without automatic reload" do
23
+ before { Capybara.automatic_reload = false }
24
+ it "should reload the current context of the node" do
25
+ @session.visit('/with_js')
26
+ node = @session.find(:css, '#reload-me')
27
+ @session.click_link('Reload!')
28
+ sleep(0.3)
29
+ node.reload.text.should == 'RELOADED'
30
+ node.text.should == 'RELOADED'
31
+ end
32
+
33
+ it "should reload a parent node" do
34
+ @session.visit('/with_js')
35
+ node = @session.find(:css, '#reload-me').find(:css, 'em')
36
+ @session.click_link('Reload!')
37
+ sleep(0.3)
38
+ node.reload.text.should == 'RELOADED'
39
+ node.text.should == 'RELOADED'
40
+ end
41
+
42
+ it "should not automatically reload" do
43
+ @session.visit('/with_js')
44
+ node = @session.find(:css, '#reload-me')
45
+ @session.click_link('Reload!')
46
+ sleep(0.3)
47
+ running { node.text.should == 'RELOADED' }.should raise_error
48
+ end
49
+ after { Capybara.automatic_reload = true }
50
+ end
51
+
52
+ context "with automatic reload" do
53
+ it "should reload the current context of the node automatically" do
54
+ @session.visit('/with_js')
55
+ node = @session.find(:css, '#reload-me')
56
+ @session.click_link('Reload!')
57
+ sleep(0.3)
58
+ node.text.should == 'RELOADED'
59
+ end
60
+
61
+ it "should reload a parent node automatically" do
62
+ @session.visit('/with_js')
63
+ node = @session.find(:css, '#reload-me').find(:css, 'em')
64
+ @session.click_link('Reload!')
65
+ sleep(0.3)
66
+ node.text.should == 'RELOADED'
67
+ end
68
+
69
+ it "should reload a node automatically when using find" do
70
+ @session.visit('/with_js')
71
+ node = @session.find(:css, '#reload-me')
72
+ @session.click_link('Reload!')
73
+ sleep(0.3)
74
+ node.find(:css, 'a').text.should == 'RELOADED'
75
+ end
76
+ end
77
+ end
78
+
79
+ describe '#find' do
80
+ it "should allow triggering of custom JS events" do
81
+ pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
82
+ @session.visit('/with_js')
83
+ @session.find(:css, '#with_focus_event').trigger(:focus)
84
+ @session.should have_css('#focus_event_triggered')
85
+ end
86
+ end
87
+
88
+ describe '#body' do
89
+ it "should return the current state of the page" do
90
+ @session.visit('/with_js')
91
+ @session.body.should include('I changed it')
92
+ @session.body.should_not include('This is text')
93
+ end
94
+ end
95
+
96
+ describe '#source' do
97
+ it "should return the original, unmodified source of the page" do
98
+ pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
99
+ @session.visit('/with_js')
100
+ @session.source.should include('This is text')
101
+ @session.source.should_not include('I changed it')
102
+ end
103
+ end
104
+
105
+ describe "#evaluate_script" do
106
+ it "should evaluate the given script and return whatever it produces" do
107
+ @session.visit('/with_js')
108
+ @session.evaluate_script("1+3").should == 4
109
+ end
110
+ end
111
+
112
+ describe "#execute_script" do
113
+ it "should execute the given script and return nothing" do
114
+ @session.visit('/with_js')
115
+ @session.execute_script("$('#change').text('Funky Doodle')").should be_nil
116
+ @session.should have_css('#change', :text => 'Funky Doodle')
117
+ end
118
+ end
119
+
120
+ describe '#find' do
121
+ it "should wait for asynchronous load" do
122
+ @session.visit('/with_js')
123
+ @session.click_link('Click me')
124
+ @session.find(:css, "a#has-been-clicked").text.should include('Has been clicked')
125
+ end
126
+
127
+ context "with frozen time" do
128
+ it "raises an error suggesting that Capybara is stuck in time" do
129
+ @session.visit('/with_js')
130
+ now = Time.now
131
+ Time.stub(:now).and_return(now)
132
+ expect { @session.find('//isnotthere') }.to raise_error(Capybara::FrozenInTime)
133
+ end
134
+ end
135
+ end
136
+
137
+ describe '#wait_until' do
138
+ before do
139
+ @default_timeout = Capybara.default_wait_time
140
+ end
141
+
142
+ after do
143
+ Capybara.default_wait_time = @default_wait_time
144
+ end
145
+
146
+ it "should wait for block to return true" do
147
+ @session.visit('/with_js')
148
+ @session.select('My Waiting Option', :from => 'waiter')
149
+ @session.evaluate_script('activeRequests == 1').should be_true
150
+ @session.wait_until do
151
+ @session.evaluate_script('activeRequests == 0')
152
+ end
153
+ @session.evaluate_script('activeRequests == 0').should be_true
154
+ end
155
+
156
+ it "should raise Capybara::TimeoutError if block doesn't return true within timeout" do
157
+ @session.visit('/with_html')
158
+ Proc.new do
159
+ @session.wait_until(0.1) do
160
+ @session.all('//div[@id="nosuchthing"]').first
161
+ end
162
+ end.should raise_error(::Capybara::TimeoutError)
163
+ end
164
+
165
+ it "should accept custom timeout in seconds" do
166
+ start = Time.now
167
+ Capybara.default_wait_time = 5
168
+ begin
169
+ @session.wait_until(0.1) { false }
170
+ rescue Capybara::TimeoutError; end
171
+ (Time.now - start).should be_within(0.1).of(0.1)
172
+ end
173
+
174
+ it "should default to Capybara.default_wait_time before timeout" do
175
+ @session.driver # init the driver to exclude init timing from test
176
+ start = Time.now
177
+ Capybara.default_wait_time = 0.2
178
+ begin
179
+ @session.wait_until { false }
180
+ rescue Capybara::TimeoutError; end
181
+ if @session.driver.has_shortcircuit_timeout?
182
+ (Time.now - start).should be_within(0.1).of(0)
183
+ else
184
+ (Time.now - start).should be_within(0.1).of(0.2)
185
+ end
186
+ end
187
+ end
188
+
189
+ describe '#click_link_or_button' do
190
+ it "should wait for asynchronous load" do
191
+ @session.visit('/with_js')
192
+ @session.click_link('Click me')
193
+ @session.click_link_or_button('Has been clicked')
194
+ end
195
+ end
196
+
197
+ describe '#click_link' do
198
+ it "should wait for asynchronous load" do
199
+ @session.visit('/with_js')
200
+ @session.click_link('Click me')
201
+ @session.click_link('Has been clicked')
202
+ end
203
+ end
204
+
205
+ describe '#click_button' do
206
+ it "should wait for asynchronous load" do
207
+ @session.visit('/with_js')
208
+ @session.click_link('Click me')
209
+ @session.click_button('New Here')
210
+ end
211
+ end
212
+
213
+ describe '#fill_in' do
214
+ it "should wait for asynchronous load" do
215
+ @session.visit('/with_js')
216
+ @session.click_link('Click me')
217
+ @session.fill_in('new_field', :with => 'Testing...')
218
+ end
219
+ end
220
+
221
+ describe '#check' do
222
+ it "should trigger associated events" do
223
+ @session.visit('/with_js')
224
+ @session.check('checkbox_with_event')
225
+ @session.should have_css('#checkbox_event_triggered');
226
+ end
227
+ end
228
+
229
+ describe '#has_xpath?' do
230
+ it "should wait for content to appear" do
231
+ @session.visit('/with_js')
232
+ @session.click_link('Click me')
233
+ @session.should have_xpath("//input[@type='submit' and @value='New Here']")
234
+ end
235
+ end
236
+
237
+ describe '#has_no_xpath?' do
238
+ it "should wait for content to disappear" do
239
+ @session.visit('/with_js')
240
+ @session.click_link('Click me')
241
+ @session.should have_no_xpath("//p[@id='change']")
242
+ end
243
+ end
244
+
245
+ describe '#has_css?' do
246
+ it "should wait for content to appear" do
247
+ @session.visit('/with_js')
248
+ @session.click_link('Click me')
249
+ @session.should have_css("input[type='submit'][value='New Here']")
250
+ end
251
+ end
252
+
253
+ describe '#has_no_xpath?' do
254
+ it "should wait for content to disappear" do
255
+ @session.visit('/with_js')
256
+ @session.click_link('Click me')
257
+ @session.should have_no_css("p#change")
258
+ end
259
+ end
260
+
261
+ describe '#has_content?' do
262
+ it "should wait for content to appear" do
263
+ @session.visit('/with_js')
264
+ @session.click_link('Click me')
265
+ @session.should have_content("Has been clicked")
266
+ end
267
+ end
268
+
269
+ describe '#has_no_content?' do
270
+ it "should wait for content to disappear" do
271
+ @session.visit('/with_js')
272
+ @session.click_link('Click me')
273
+ @session.should have_no_content("I changed it")
274
+ end
275
+ end
276
+
277
+ end
278
+ end
279
+
280
+ shared_examples_for "session without javascript support" do
281
+ describe "#evaluate_script" do
282
+ before{ @session.visit('/with_simple_html') }
283
+ it "should raise an error" do
284
+ running {
285
+ @session.evaluate_script('3 + 3')
286
+ }.should raise_error(Capybara::NotSupportedByDriverError)
287
+ end
288
+ end
289
+ end
@@ -0,0 +1,19 @@
1
+ shared_examples_for "session with status code support" do
2
+ describe '#status_code' do
3
+ it "should return response codes" do
4
+ @session.visit('/with_simple_html')
5
+ @session.status_code.should == 200
6
+ end
7
+ end
8
+ end
9
+
10
+ shared_examples_for "session without status code support" do
11
+ describe "#status_code" do
12
+ before{ @session.visit('/with_simple_html') }
13
+ it "should raise an error" do
14
+ running {
15
+ @session.status_code
16
+ }.should raise_error(Capybara::NotSupportedByDriverError)
17
+ end
18
+ end
19
+ end