nimboids-capybara 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/History.txt +289 -0
  2. data/README.rdoc +722 -0
  3. data/lib/capybara.rb +252 -0
  4. data/lib/capybara/cucumber.rb +28 -0
  5. data/lib/capybara/driver/base.rb +64 -0
  6. data/lib/capybara/driver/node.rb +74 -0
  7. data/lib/capybara/dsl.rb +168 -0
  8. data/lib/capybara/node/actions.rb +162 -0
  9. data/lib/capybara/node/base.rb +63 -0
  10. data/lib/capybara/node/document.rb +25 -0
  11. data/lib/capybara/node/element.rb +201 -0
  12. data/lib/capybara/node/finders.rb +197 -0
  13. data/lib/capybara/node/matchers.rb +417 -0
  14. data/lib/capybara/node/simple.rb +132 -0
  15. data/lib/capybara/rack_test/browser.rb +121 -0
  16. data/lib/capybara/rack_test/driver.rb +80 -0
  17. data/lib/capybara/rack_test/form.rb +80 -0
  18. data/lib/capybara/rack_test/node.rb +105 -0
  19. data/lib/capybara/rails.rb +17 -0
  20. data/lib/capybara/rspec.rb +26 -0
  21. data/lib/capybara/rspec/features.rb +22 -0
  22. data/lib/capybara/rspec/matchers.rb +154 -0
  23. data/lib/capybara/selector.rb +89 -0
  24. data/lib/capybara/selenium/driver.rb +163 -0
  25. data/lib/capybara/selenium/node.rb +91 -0
  26. data/lib/capybara/server.rb +90 -0
  27. data/lib/capybara/session.rb +321 -0
  28. data/lib/capybara/spec/driver.rb +301 -0
  29. data/lib/capybara/spec/fixtures/capybara.jpg +3 -0
  30. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  31. data/lib/capybara/spec/public/test.js +43 -0
  32. data/lib/capybara/spec/session.rb +154 -0
  33. data/lib/capybara/spec/session/all_spec.rb +78 -0
  34. data/lib/capybara/spec/session/attach_file_spec.rb +73 -0
  35. data/lib/capybara/spec/session/check_spec.rb +65 -0
  36. data/lib/capybara/spec/session/choose_spec.rb +26 -0
  37. data/lib/capybara/spec/session/click_button_spec.rb +304 -0
  38. data/lib/capybara/spec/session/click_link_or_button_spec.rb +36 -0
  39. data/lib/capybara/spec/session/click_link_spec.rb +119 -0
  40. data/lib/capybara/spec/session/current_host_spec.rb +68 -0
  41. data/lib/capybara/spec/session/current_url_spec.rb +15 -0
  42. data/lib/capybara/spec/session/fill_in_spec.rb +125 -0
  43. data/lib/capybara/spec/session/find_button_spec.rb +18 -0
  44. data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
  45. data/lib/capybara/spec/session/find_field_spec.rb +26 -0
  46. data/lib/capybara/spec/session/find_link_spec.rb +19 -0
  47. data/lib/capybara/spec/session/find_spec.rb +149 -0
  48. data/lib/capybara/spec/session/first_spec.rb +105 -0
  49. data/lib/capybara/spec/session/has_button_spec.rb +32 -0
  50. data/lib/capybara/spec/session/has_content_spec.rb +106 -0
  51. data/lib/capybara/spec/session/has_css_spec.rb +243 -0
  52. data/lib/capybara/spec/session/has_field_spec.rb +192 -0
  53. data/lib/capybara/spec/session/has_link_spec.rb +37 -0
  54. data/lib/capybara/spec/session/has_select_spec.rb +129 -0
  55. data/lib/capybara/spec/session/has_selector_spec.rb +129 -0
  56. data/lib/capybara/spec/session/has_table_spec.rb +96 -0
  57. data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
  58. data/lib/capybara/spec/session/headers.rb +19 -0
  59. data/lib/capybara/spec/session/javascript.rb +289 -0
  60. data/lib/capybara/spec/session/response_code.rb +19 -0
  61. data/lib/capybara/spec/session/select_spec.rb +113 -0
  62. data/lib/capybara/spec/session/text_spec.rb +19 -0
  63. data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
  64. data/lib/capybara/spec/session/unselect_spec.rb +61 -0
  65. data/lib/capybara/spec/session/within_spec.rb +178 -0
  66. data/lib/capybara/spec/test_app.rb +142 -0
  67. data/lib/capybara/spec/views/buttons.erb +4 -0
  68. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  69. data/lib/capybara/spec/views/form.erb +365 -0
  70. data/lib/capybara/spec/views/frame_one.erb +8 -0
  71. data/lib/capybara/spec/views/frame_two.erb +8 -0
  72. data/lib/capybara/spec/views/header_links.erb +7 -0
  73. data/lib/capybara/spec/views/host_links.erb +12 -0
  74. data/lib/capybara/spec/views/popup_one.erb +8 -0
  75. data/lib/capybara/spec/views/popup_two.erb +8 -0
  76. data/lib/capybara/spec/views/postback.erb +13 -0
  77. data/lib/capybara/spec/views/tables.erb +122 -0
  78. data/lib/capybara/spec/views/with_html.erb +78 -0
  79. data/lib/capybara/spec/views/with_html_entities.erb +1 -0
  80. data/lib/capybara/spec/views/with_js.erb +48 -0
  81. data/lib/capybara/spec/views/with_scope.erb +36 -0
  82. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  83. data/lib/capybara/spec/views/within_frames.erb +10 -0
  84. data/lib/capybara/spec/views/within_popups.erb +25 -0
  85. data/lib/capybara/util/save_and_open_page.rb +44 -0
  86. data/lib/capybara/util/timeout.rb +27 -0
  87. data/lib/capybara/version.rb +3 -0
  88. data/spec/basic_node_spec.rb +77 -0
  89. data/spec/capybara_spec.rb +46 -0
  90. data/spec/driver/rack_test_driver_spec.rb +89 -0
  91. data/spec/driver/selenium_driver_spec.rb +50 -0
  92. data/spec/dsl_spec.rb +253 -0
  93. data/spec/fixtures/selenium_driver_rspec_failure.rb +8 -0
  94. data/spec/fixtures/selenium_driver_rspec_success.rb +8 -0
  95. data/spec/rspec/features_spec.rb +45 -0
  96. data/spec/rspec/matchers_spec.rb +495 -0
  97. data/spec/rspec_spec.rb +53 -0
  98. data/spec/save_and_open_page_spec.rb +155 -0
  99. data/spec/server_spec.rb +89 -0
  100. data/spec/session/rack_test_session_spec.rb +55 -0
  101. data/spec/session/selenium_session_spec.rb +26 -0
  102. data/spec/spec_helper.rb +30 -0
  103. data/spec/string_spec.rb +77 -0
  104. data/spec/timeout_spec.rb +28 -0
  105. metadata +346 -0
@@ -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