capybara 1.1.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{History.txt → History.md} +138 -0
- data/License.txt +22 -0
- data/README.md +850 -0
- data/lib/capybara/cucumber.rb +2 -5
- data/lib/capybara/driver/base.rb +6 -6
- data/lib/capybara/driver/node.rb +3 -2
- data/lib/capybara/dsl.rb +13 -124
- data/lib/capybara/helpers.rb +33 -0
- data/lib/capybara/node/actions.rb +16 -30
- data/lib/capybara/node/base.rb +56 -13
- data/lib/capybara/node/element.rb +18 -30
- data/lib/capybara/node/finders.rb +28 -90
- data/lib/capybara/node/matchers.rb +121 -73
- data/lib/capybara/node/simple.rb +13 -11
- data/lib/capybara/query.rb +78 -0
- data/lib/capybara/rack_test/browser.rb +27 -39
- data/lib/capybara/rack_test/driver.rb +13 -3
- data/lib/capybara/rack_test/node.rb +31 -2
- data/lib/capybara/result.rb +72 -0
- data/lib/capybara/rspec/features.rb +4 -1
- data/lib/capybara/rspec/matchers.rb +33 -63
- data/lib/capybara/rspec.rb +7 -4
- data/lib/capybara/selector.rb +97 -34
- data/lib/capybara/selenium/driver.rb +15 -62
- data/lib/capybara/selenium/node.rb +14 -21
- data/lib/capybara/server.rb +32 -27
- data/lib/capybara/session.rb +90 -50
- data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
- data/lib/capybara/spec/public/jquery-ui.js +791 -0
- data/lib/capybara/spec/public/jquery.js +9046 -0
- data/lib/capybara/spec/public/test.js +3 -0
- data/lib/capybara/spec/session/all_spec.rb +61 -59
- data/lib/capybara/spec/session/assert_selector.rb +123 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +72 -55
- data/lib/capybara/spec/session/body_spec.rb +21 -0
- data/lib/capybara/spec/session/check_spec.rb +68 -48
- data/lib/capybara/spec/session/choose_spec.rb +32 -18
- data/lib/capybara/spec/session/click_button_spec.rb +263 -232
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -29
- data/lib/capybara/spec/session/click_link_spec.rb +96 -96
- data/lib/capybara/spec/session/current_url_spec.rb +88 -10
- data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
- data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +119 -103
- data/lib/capybara/spec/session/find_button_spec.rb +16 -14
- data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
- data/lib/capybara/spec/session/find_field_spec.rb +23 -21
- data/lib/capybara/spec/session/find_link_spec.rb +15 -14
- data/lib/capybara/spec/session/find_spec.rb +93 -115
- data/lib/capybara/spec/session/first_spec.rb +51 -85
- data/lib/capybara/spec/session/has_button_spec.rb +22 -24
- data/lib/capybara/spec/session/has_css_spec.rb +190 -205
- data/lib/capybara/spec/session/has_field_spec.rb +170 -144
- data/lib/capybara/spec/session/has_link_spec.rb +26 -29
- data/lib/capybara/spec/session/has_select_spec.rb +161 -109
- data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
- data/lib/capybara/spec/session/has_table_spec.rb +22 -88
- data/lib/capybara/spec/session/has_text_spec.rb +195 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
- data/lib/capybara/spec/session/headers.rb +4 -17
- data/lib/capybara/spec/session/html_spec.rb +15 -0
- data/lib/capybara/spec/session/node_spec.rb +205 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
- data/lib/capybara/spec/session/response_code.rb +4 -17
- data/lib/capybara/spec/session/save_page_spec.rb +46 -0
- data/lib/capybara/spec/session/screenshot.rb +13 -0
- data/lib/capybara/spec/session/select_spec.rb +99 -88
- data/lib/capybara/spec/session/source_spec.rb +12 -0
- data/lib/capybara/spec/session/text_spec.rb +15 -12
- data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
- data/lib/capybara/spec/session/unselect_spec.rb +69 -58
- data/lib/capybara/spec/session/visit_spec.rb +74 -0
- data/lib/capybara/spec/session/within_frame_spec.rb +31 -0
- data/lib/capybara/spec/session/within_spec.rb +118 -131
- data/lib/capybara/spec/session/within_window_spec.rb +38 -0
- data/lib/capybara/spec/spec_helper.rb +84 -0
- data/lib/capybara/spec/test_app.rb +32 -6
- data/lib/capybara/spec/views/form.erb +12 -10
- data/lib/capybara/spec/views/host_links.erb +2 -2
- data/lib/capybara/spec/views/tables.erb +6 -66
- data/lib/capybara/spec/views/with_html.erb +9 -4
- data/lib/capybara/spec/views/with_js.erb +11 -7
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara.rb +125 -6
- data/spec/basic_node_spec.rb +17 -5
- data/spec/capybara_spec.rb +9 -0
- data/spec/dsl_spec.rb +31 -17
- data/spec/rack_test_spec.rb +157 -0
- data/spec/result_spec.rb +51 -0
- data/spec/rspec/features_spec.rb +19 -2
- data/spec/rspec/matchers_spec.rb +170 -89
- data/spec/rspec_spec.rb +1 -3
- data/spec/selenium_spec.rb +53 -0
- data/spec/server_spec.rb +37 -25
- data/spec/spec_helper.rb +1 -30
- metadata +39 -31
- data/README.rdoc +0 -722
- data/lib/capybara/spec/driver.rb +0 -301
- data/lib/capybara/spec/session/current_host_spec.rb +0 -68
- data/lib/capybara/spec/session/has_content_spec.rb +0 -106
- data/lib/capybara/spec/session/javascript.rb +0 -306
- data/lib/capybara/spec/session.rb +0 -154
- data/lib/capybara/util/save_and_open_page.rb +0 -44
- data/lib/capybara/util/timeout.rb +0 -27
- data/spec/driver/rack_test_driver_spec.rb +0 -89
- data/spec/driver/selenium_driver_spec.rb +0 -37
- data/spec/save_and_open_page_spec.rb +0 -155
- data/spec/session/rack_test_session_spec.rb +0 -55
- data/spec/session/selenium_session_spec.rb +0 -26
- data/spec/string_spec.rb +0 -77
- data/spec/timeout_spec.rb +0 -28
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
require 'capybara/util/save_and_open_page'
|
|
4
|
-
require 'launchy'
|
|
5
|
-
describe Capybara do
|
|
6
|
-
describe ".save_page & .save_and_open_page" do
|
|
7
|
-
before do
|
|
8
|
-
@temp_file = mock("FILE")
|
|
9
|
-
@temp_file.stub!(:write)
|
|
10
|
-
@temp_file.stub!(:close)
|
|
11
|
-
|
|
12
|
-
@html = <<-HTML
|
|
13
|
-
<html>
|
|
14
|
-
<head>
|
|
15
|
-
<script type="text/javascript" src="/javascripts/prototype.js?123"/>
|
|
16
|
-
</head>
|
|
17
|
-
<body>
|
|
18
|
-
<h1>test</h1>
|
|
19
|
-
<p>
|
|
20
|
-
Some images (note differing whitespace closing tag):
|
|
21
|
-
<img src="/images/image1.jpeg" />
|
|
22
|
-
<img src="/images/image2.jpeg"/>
|
|
23
|
-
</p>
|
|
24
|
-
<p>
|
|
25
|
-
Some more in a non-existent directory:
|
|
26
|
-
<img src="/img/image3.jpeg" />
|
|
27
|
-
<img src="/img/image4.jpeg"/>
|
|
28
|
-
</p>
|
|
29
|
-
<p>
|
|
30
|
-
<a href="/not-here/foo.html">
|
|
31
|
-
A link to a file in a non-existent directory.
|
|
32
|
-
</a>
|
|
33
|
-
</p>
|
|
34
|
-
</body>
|
|
35
|
-
<html>
|
|
36
|
-
HTML
|
|
37
|
-
|
|
38
|
-
Launchy.stub(:open)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def default_file_expectations
|
|
42
|
-
@temp_file.stub!(:path).and_return('page.html')
|
|
43
|
-
|
|
44
|
-
File.should_receive(:exist?).and_return true
|
|
45
|
-
File.should_receive(:new).and_return @temp_file
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
describe "defaults" do
|
|
49
|
-
before do
|
|
50
|
-
default_file_expectations
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it "should create a new temporary file" do
|
|
54
|
-
@temp_file.should_receive(:write).with @html
|
|
55
|
-
Capybara.save_page @html, 'page.html'
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "should open the file in the browser" do
|
|
59
|
-
Capybara.should_receive(:open_in_browser).with('page.html')
|
|
60
|
-
Capybara.save_and_open_page @html, 'page.html'
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
describe "custom output path" do
|
|
65
|
-
before do
|
|
66
|
-
@custom_path = File.join('tmp', 'capybara')
|
|
67
|
-
@custom_name = File.join(@custom_path, 'page.html')
|
|
68
|
-
|
|
69
|
-
@temp_file.stub!(:path).and_return(@custom_name)
|
|
70
|
-
|
|
71
|
-
Capybara.should_receive(:save_and_open_page_path).at_least(:once).and_return(@custom_path)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "should create a new temporary file in the custom path" do
|
|
75
|
-
File.should_receive(:directory?).and_return true
|
|
76
|
-
File.should_receive(:exist?).and_return true
|
|
77
|
-
File.should_receive(:new).and_return @temp_file
|
|
78
|
-
|
|
79
|
-
@temp_file.should_receive(:write).with @html
|
|
80
|
-
Capybara.save_page @html, 'page.html'
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "should open the file - in the custom path - in the browser" do
|
|
84
|
-
Capybara.should_receive(:open_in_browser).with(@custom_name)
|
|
85
|
-
Capybara.save_and_open_page @html, 'page.html'
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it "should be possible to configure output path" do
|
|
89
|
-
Capybara.should respond_to(:save_and_open_page_path)
|
|
90
|
-
default_setting = Capybara.save_and_open_page_path
|
|
91
|
-
lambda {
|
|
92
|
-
Capybara.save_and_open_page_path = File.join('tmp', 'capybara')
|
|
93
|
-
Capybara.save_and_open_page_path.should == File.join('tmp', 'capybara')
|
|
94
|
-
}.should_not raise_error
|
|
95
|
-
Capybara.save_and_open_page_path = default_setting
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
describe "rewrite_css_and_image_references" do
|
|
100
|
-
before do
|
|
101
|
-
default_file_expectations
|
|
102
|
-
@asset_root_dir = "/path/to/rails/public"
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def mock_asset_root_with(directories)
|
|
106
|
-
@asset_root = Pathname.new(@asset_root_dir)
|
|
107
|
-
Capybara.should_receive(:asset_root).and_return @asset_root
|
|
108
|
-
|
|
109
|
-
dir = mock('asset_root mock dir')
|
|
110
|
-
Dir.should_receive(:new).with(@asset_root).and_return dir
|
|
111
|
-
|
|
112
|
-
dirents = [ '.', '..', 'file.html' ] + directories
|
|
113
|
-
dir.should_receive(:entries).and_return dirents
|
|
114
|
-
|
|
115
|
-
directories_regexp = directories.join('|')
|
|
116
|
-
FileTest.should_receive(:directory?) \
|
|
117
|
-
.at_least(dirents.size - 2).times \
|
|
118
|
-
.and_return { |dir|
|
|
119
|
-
dir =~ %r!#{@asset_root_dir}/(#{directories_regexp})$!
|
|
120
|
-
}
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def expected_html_for_asset_root_with(directories)
|
|
124
|
-
mock_asset_root_with(directories)
|
|
125
|
-
|
|
126
|
-
expected_html = @html.clone
|
|
127
|
-
if not directories.empty?
|
|
128
|
-
directories_regexp = directories.join('|')
|
|
129
|
-
expected_html.gsub!(/"(\/(#{directories_regexp})\/)/,
|
|
130
|
-
'"%s\1' % @asset_root_dir)
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
return expected_html
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
def test_with_directories(directories)
|
|
137
|
-
@temp_file.should_receive(:write) \
|
|
138
|
-
.with expected_html_for_asset_root_with(directories)
|
|
139
|
-
Capybara.save_page @html, 'page.html'
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
context "asset_root contains some directories" do
|
|
143
|
-
it "should rewrite relative paths to absolute local paths" do
|
|
144
|
-
test_with_directories([ 'javascripts', 'images' ])
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
context "asset_root path contains no directories" do
|
|
149
|
-
it "should not rewrite any relative paths" do
|
|
150
|
-
test_with_directories([ ])
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Capybara::Session do
|
|
4
|
-
context 'with rack test driver' do
|
|
5
|
-
before do
|
|
6
|
-
@session = TestSessions::RackTest
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
describe '#driver' do
|
|
10
|
-
it "should be a rack test driver" do
|
|
11
|
-
@session.driver.should be_an_instance_of(Capybara::RackTest::Driver)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
describe '#mode' do
|
|
16
|
-
it "should remember the mode" do
|
|
17
|
-
@session.mode.should == :rack_test
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe '#click_link' do
|
|
22
|
-
it "should use data-method if available" do
|
|
23
|
-
@session.visit "/with_html"
|
|
24
|
-
@session.click_link "A link with data-method"
|
|
25
|
-
@session.body.should include('The requested object was deleted')
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "should not use data-method if option is false" do
|
|
29
|
-
@session.driver.options[:respect_data_method] = false
|
|
30
|
-
@session.visit "/with_html"
|
|
31
|
-
@session.click_link "A link with data-method"
|
|
32
|
-
@session.body.should include('Not deleted')
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
after do
|
|
36
|
-
@session.driver.options[:respect_data_method] = true
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
describe "#attach_file" do
|
|
41
|
-
context "with multipart form" do
|
|
42
|
-
it "should submit an empty form-data section if no file is submitted" do
|
|
43
|
-
@session.visit("/form")
|
|
44
|
-
@session.click_button("Upload Empty")
|
|
45
|
-
@session.body.should include('Successfully ignored empty file field.')
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it_should_behave_like "session"
|
|
51
|
-
it_should_behave_like "session without javascript support"
|
|
52
|
-
it_should_behave_like "session with headers support"
|
|
53
|
-
it_should_behave_like "session with status code support"
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Capybara::Session do
|
|
4
|
-
context 'with selenium driver' do
|
|
5
|
-
before do
|
|
6
|
-
@session = TestSessions::Selenium
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
describe '#driver' do
|
|
10
|
-
it "should be a selenium driver" do
|
|
11
|
-
@session.driver.should be_an_instance_of(Capybara::Selenium::Driver)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
describe '#mode' do
|
|
16
|
-
it "should remember the mode" do
|
|
17
|
-
@session.mode.should == :selenium
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it_should_behave_like "session"
|
|
22
|
-
it_should_behave_like "session with javascript support"
|
|
23
|
-
it_should_behave_like "session without headers support"
|
|
24
|
-
it_should_behave_like "session without status code support"
|
|
25
|
-
end
|
|
26
|
-
end
|
data/spec/string_spec.rb
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe Capybara do
|
|
4
|
-
describe '.string' do
|
|
5
|
-
let :string do
|
|
6
|
-
Capybara.string <<-STRING
|
|
7
|
-
<div id="page">
|
|
8
|
-
<div id="content">
|
|
9
|
-
<h1 data="fantastic">Awesome</h1>
|
|
10
|
-
<p>Yes it is</p>
|
|
11
|
-
</div>
|
|
12
|
-
|
|
13
|
-
<div id="footer" style="display: none">
|
|
14
|
-
<p>c2010</p>
|
|
15
|
-
<p>Jonas Nicklas</p>
|
|
16
|
-
<input type="text" name="foo" value="bar"/>
|
|
17
|
-
<select name="animal">
|
|
18
|
-
<option>Monkey</option>
|
|
19
|
-
<option selected="selected">Capybara</option>
|
|
20
|
-
</select>
|
|
21
|
-
</div>
|
|
22
|
-
</div>
|
|
23
|
-
STRING
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "allows using matchers" do
|
|
27
|
-
string.should have_css('#page')
|
|
28
|
-
string.should_not have_css('#does-not-exist')
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "allows using custom matchers" do
|
|
32
|
-
Capybara.add_selector :lifeform do
|
|
33
|
-
xpath { |name| "//option[contains(.,'#{name}')]" }
|
|
34
|
-
end
|
|
35
|
-
string.should have_selector(:page)
|
|
36
|
-
string.should_not have_selector(:'does-not-exist')
|
|
37
|
-
string.should have_selector(:lifeform, "Monkey")
|
|
38
|
-
string.should_not have_selector(:lifeform, "Gorilla")
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "allows using matchers with text option" do
|
|
42
|
-
string.should have_css('h1', :text => 'Awesome')
|
|
43
|
-
string.should_not have_css('h1', :text => 'Not so awesome')
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "allows finding only visible nodes" do
|
|
47
|
-
string.all('//p', :text => 'c2010', :visible => true).should be_empty
|
|
48
|
-
string.all('//p', :text => 'c2010', :visible => false).should have(1).element
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "allows finding elements and extracting text from them" do
|
|
52
|
-
string.find('//h1').text.should == 'Awesome'
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "allows finding elements and extracting attributes from them" do
|
|
56
|
-
string.find('//h1')[:data].should == 'fantastic'
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "allows finding elements and extracting the tag name from them" do
|
|
60
|
-
string.find('//h1').tag_name.should == 'h1'
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it "allows finding elements and extracting the path" do
|
|
64
|
-
string.find('//h1').path.should == '/html/body/div/div[1]/h1'
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it "allows finding elements and extracting the value" do
|
|
68
|
-
string.find('//input').value.should == 'bar'
|
|
69
|
-
string.find('//select').value.should == 'Capybara'
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "allows finding elements and checking if they are visible" do
|
|
73
|
-
string.find('//h1').should be_visible
|
|
74
|
-
string.find('//input').should_not be_visible
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
data/spec/timeout_spec.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
require 'capybara'
|
|
4
|
-
require 'capybara/util/timeout'
|
|
5
|
-
|
|
6
|
-
module Capybara
|
|
7
|
-
|
|
8
|
-
describe '.timeout' do
|
|
9
|
-
|
|
10
|
-
it "should return result of yield if it returns true value within timeout" do
|
|
11
|
-
Capybara.timeout { "hello" }.should == "hello"
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "should keep trying within timeout" do
|
|
15
|
-
count = 0
|
|
16
|
-
Capybara.timeout { count += 1; count == 5 ? count : nil }.should == 5
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "should raise Capybara::TimeoutError if block fails to return true within timeout" do
|
|
20
|
-
running do
|
|
21
|
-
Capybara.timeout(0.1) { false }
|
|
22
|
-
end.should raise_error(::Capybara::TimeoutError)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
end
|
|
28
|
-
|