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
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Capybara::SpecHelper.spec '#reset_session!' do
|
|
2
|
+
it "removes cookies" do
|
|
3
|
+
@session.visit('/set_cookie')
|
|
4
|
+
@session.visit('/get_cookie')
|
|
5
|
+
@session.should have_content('test_cookie')
|
|
6
|
+
|
|
7
|
+
@session.reset_session!
|
|
8
|
+
@session.visit('/get_cookie')
|
|
9
|
+
@session.body.should_not include('test_cookie')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "resets current url, host, path" do
|
|
13
|
+
@session.visit '/foo'
|
|
14
|
+
@session.current_url.should_not be_empty
|
|
15
|
+
@session.current_host.should_not be_empty
|
|
16
|
+
@session.current_path.should == '/foo'
|
|
17
|
+
|
|
18
|
+
@session.reset_session!
|
|
19
|
+
[nil, '', 'about:blank'].should include @session.current_url
|
|
20
|
+
@session.current_host.should be_nil
|
|
21
|
+
@session.current_path.should be_nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "resets page body" do
|
|
25
|
+
@session.visit('/with_html')
|
|
26
|
+
@session.should have_content('This is a test')
|
|
27
|
+
@session.find('.//h1').text.should include('This is a test')
|
|
28
|
+
|
|
29
|
+
@session.reset_session!
|
|
30
|
+
@session.body.should_not include('This is a test')
|
|
31
|
+
@session.should have_no_selector('.//h1')
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "raises any errors caught inside the server" do
|
|
35
|
+
expect do
|
|
36
|
+
quietly { @session.visit("/error") }
|
|
37
|
+
@session.reset_session!
|
|
38
|
+
end.to raise_error(TestApp::TestAppError)
|
|
39
|
+
@session.visit("/")
|
|
40
|
+
@session.current_path.should == "/"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -1,19 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
1
|
+
Capybara::SpecHelper.spec '#status_code' do
|
|
2
|
+
it "should return response codes", :requires => [:status_code] do
|
|
3
|
+
@session.visit('/with_simple_html')
|
|
4
|
+
@session.status_code.should == 200
|
|
18
5
|
end
|
|
19
6
|
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Capybara::SpecHelper.spec '#save_page' do
|
|
2
|
+
let(:alternative_path) { File.join(Dir.pwd, "save_and_open_page_tmp") }
|
|
3
|
+
before do
|
|
4
|
+
@session.visit("/foo")
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
after do
|
|
8
|
+
Capybara.save_and_open_page_path = nil
|
|
9
|
+
Dir.glob("capybara-*.html").each do |file|
|
|
10
|
+
FileUtils.rm(file)
|
|
11
|
+
end
|
|
12
|
+
FileUtils.rm_rf alternative_path
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "saves the page in the root directory" do
|
|
16
|
+
@session.save_page
|
|
17
|
+
path = Dir.glob("capybara-*.html").first
|
|
18
|
+
File.read(path).should include("Another World")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "generates a sensible filename" do
|
|
22
|
+
@session.save_page
|
|
23
|
+
path = Dir.glob("capybara-*.html").first
|
|
24
|
+
filename = path.split("/").last
|
|
25
|
+
filename.should =~ /^capybara-\d+\.html$/
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "can store files in a specified directory" do
|
|
29
|
+
Capybara.save_and_open_page_path = alternative_path
|
|
30
|
+
@session.save_page
|
|
31
|
+
path = Dir.glob(alternative_path + "/capybara-*.html").first
|
|
32
|
+
File.read(path).should include("Another World")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "uses the given filename" do
|
|
36
|
+
@session.save_page("capybara-001122.html")
|
|
37
|
+
File.read("capybara-001122.html").should include("Another World")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "returns the filename" do
|
|
41
|
+
result = @session.save_page
|
|
42
|
+
path = Dir.glob("capybara-*.html").first
|
|
43
|
+
filename = path.split("/").last
|
|
44
|
+
result.should == filename
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Capybara::SpecHelper.spec "#save_screenshot" do
|
|
2
|
+
let(:image_path) { File.join(Dir.tmpdir, 'capybara-screenshot.png') }
|
|
3
|
+
|
|
4
|
+
before do
|
|
5
|
+
@session.visit '/'
|
|
6
|
+
@session.save_screenshot image_path
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should generate PNG file", :requires => [:screenshot] do
|
|
10
|
+
magic = File.read(image_path, 4)
|
|
11
|
+
magic.should eq "\x89PNG"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -1,113 +1,124 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
end
|
|
1
|
+
Capybara::SpecHelper.spec "#select" do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/form')
|
|
4
|
+
end
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
it "should return value of the first option" do
|
|
7
|
+
@session.find_field('Title').value.should == 'Mrs'
|
|
8
|
+
end
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
it "should return value of the selected option" do
|
|
11
|
+
@session.select("Miss", :from => 'Title')
|
|
12
|
+
@session.find_field('Title').value.should == 'Miss'
|
|
13
|
+
end
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
it "should return the value attribute rather than content if present" do
|
|
16
|
+
@session.find_field('Locale').value.should == 'en'
|
|
17
|
+
end
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
it "should select an option from a select box by id" do
|
|
20
|
+
@session.select("Finish", :from => 'form_locale')
|
|
21
|
+
@session.click_button('awesome')
|
|
22
|
+
extract_results(@session)['locale'].should == 'fi'
|
|
23
|
+
end
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
it "should select an option from a select box by label" do
|
|
26
|
+
@session.select("Finish", :from => 'Locale')
|
|
27
|
+
@session.click_button('awesome')
|
|
28
|
+
extract_results(@session)['locale'].should == 'fi'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "should select an option without giving a select box" do
|
|
32
|
+
@session.select("Swedish")
|
|
33
|
+
@session.click_button('awesome')
|
|
34
|
+
extract_results(@session)['locale'].should == 'sv'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should escape quotes" do
|
|
38
|
+
@session.select("John's made-up language", :from => 'Locale')
|
|
39
|
+
@session.click_button('awesome')
|
|
40
|
+
extract_results(@session)['locale'].should == 'jo'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should obey from" do
|
|
44
|
+
@session.select("Miss", :from => "Other title")
|
|
45
|
+
@session.click_button('awesome')
|
|
46
|
+
results = extract_results(@session)
|
|
47
|
+
results['other_title'].should == "Miss"
|
|
48
|
+
results['title'].should_not == "Miss"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "show match labels with preceding or trailing whitespace" do
|
|
52
|
+
@session.select("Lojban", :from => 'Locale')
|
|
53
|
+
@session.click_button('awesome')
|
|
54
|
+
extract_results(@session)['locale'].should == 'jbo'
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "casts to string" do
|
|
58
|
+
@session.select(:"Miss", :from => :'Title')
|
|
59
|
+
@session.find_field('Title').value.should == 'Miss'
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context "with a locator that doesn't exist" do
|
|
63
|
+
it "should raise an error" do
|
|
64
|
+
msg = "Unable to find select box \"does not exist\""
|
|
65
|
+
expect do
|
|
66
|
+
@session.select('foo', :from => 'does not exist')
|
|
67
|
+
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
30
68
|
end
|
|
69
|
+
end
|
|
31
70
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
71
|
+
context "with an option that doesn't exist" do
|
|
72
|
+
it "should raise an error" do
|
|
73
|
+
msg = "Unable to find option \"Does not Exist\""
|
|
74
|
+
expect do
|
|
75
|
+
@session.select('Does not Exist', :from => 'form_locale')
|
|
76
|
+
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
36
77
|
end
|
|
78
|
+
end
|
|
37
79
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
80
|
+
context "on a disabled select" do
|
|
81
|
+
it "should raise an error" do
|
|
82
|
+
expect do
|
|
83
|
+
@session.select('Should not see me', :from => 'Disabled Select')
|
|
84
|
+
end.to raise_error(Capybara::ElementNotFound)
|
|
42
85
|
end
|
|
86
|
+
end
|
|
43
87
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
@session.
|
|
47
|
-
extract_results(@session)['locale'].should == 'jo'
|
|
88
|
+
context "with multiple select" do
|
|
89
|
+
it "should return an empty value" do
|
|
90
|
+
@session.find_field('Language').value.should == []
|
|
48
91
|
end
|
|
49
92
|
|
|
50
|
-
it "should
|
|
51
|
-
@session.select("
|
|
52
|
-
@session.
|
|
53
|
-
|
|
54
|
-
results['other_title'].should == "Miss"
|
|
55
|
-
results['title'].should_not == "Miss"
|
|
93
|
+
it "should return value of the selected options" do
|
|
94
|
+
@session.select("Ruby", :from => 'Language')
|
|
95
|
+
@session.select("Javascript", :from => 'Language')
|
|
96
|
+
@session.find_field('Language').value.should include('Ruby', 'Javascript')
|
|
56
97
|
end
|
|
57
98
|
|
|
58
|
-
it "
|
|
59
|
-
@session.select("
|
|
99
|
+
it "should select one option" do
|
|
100
|
+
@session.select("Ruby", :from => 'Language')
|
|
60
101
|
@session.click_button('awesome')
|
|
61
|
-
extract_results(@session)['
|
|
102
|
+
extract_results(@session)['languages'].should == ['Ruby']
|
|
62
103
|
end
|
|
63
104
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
105
|
+
it "should select multiple options" do
|
|
106
|
+
@session.select("Ruby", :from => 'Language')
|
|
107
|
+
@session.select("Javascript", :from => 'Language')
|
|
108
|
+
@session.click_button('awesome')
|
|
109
|
+
extract_results(@session)['languages'].should include('Ruby', 'Javascript')
|
|
68
110
|
end
|
|
69
111
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
112
|
+
it "should remain selected if already selected" do
|
|
113
|
+
@session.select("Ruby", :from => 'Language')
|
|
114
|
+
@session.select("Javascript", :from => 'Language')
|
|
115
|
+
@session.select("Ruby", :from => 'Language')
|
|
116
|
+
@session.click_button('awesome')
|
|
117
|
+
extract_results(@session)['languages'].should include('Ruby', 'Javascript')
|
|
74
118
|
end
|
|
75
119
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
@session.find_field('Language').value.should == []
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "should return value of the selected options" do
|
|
82
|
-
@session.select("Ruby", :from => 'Language')
|
|
83
|
-
@session.select("Javascript", :from => 'Language')
|
|
84
|
-
@session.find_field('Language').value.should include('Ruby', 'Javascript')
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
it "should select one option" do
|
|
88
|
-
@session.select("Ruby", :from => 'Language')
|
|
89
|
-
@session.click_button('awesome')
|
|
90
|
-
extract_results(@session)['languages'].should == ['Ruby']
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
it "should select multiple options" do
|
|
94
|
-
@session.select("Ruby", :from => 'Language')
|
|
95
|
-
@session.select("Javascript", :from => 'Language')
|
|
96
|
-
@session.click_button('awesome')
|
|
97
|
-
extract_results(@session)['languages'].should include('Ruby', 'Javascript')
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "should remain selected if already selected" do
|
|
101
|
-
@session.select("Ruby", :from => 'Language')
|
|
102
|
-
@session.select("Javascript", :from => 'Language')
|
|
103
|
-
@session.select("Ruby", :from => 'Language')
|
|
104
|
-
@session.click_button('awesome')
|
|
105
|
-
extract_results(@session)['languages'].should include('Ruby', 'Javascript')
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
it "should return value attribute rather than content if present" do
|
|
109
|
-
@session.find_field('Underwear').value.should include('thermal')
|
|
110
|
-
end
|
|
120
|
+
it "should return value attribute rather than content if present" do
|
|
121
|
+
@session.find_field('Underwear').value.should include('thermal')
|
|
111
122
|
end
|
|
112
123
|
end
|
|
113
124
|
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Capybara::SpecHelper.spec '#source' do
|
|
2
|
+
it "should return the unmodified page source" do
|
|
3
|
+
@session.visit('/')
|
|
4
|
+
@session.source.should include('Hello world!')
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
it "should return the original, unmodified source of the page", :requires => [:js, :source] do
|
|
8
|
+
@session.visit('/with_js')
|
|
9
|
+
@session.send(method).should include('This is text')
|
|
10
|
+
@session.send(method).should_not include('I changed it')
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
Capybara::SpecHelper.spec '#text' do
|
|
2
|
+
it "should print the text of the page" do
|
|
3
|
+
@session.visit('/with_simple_html')
|
|
4
|
+
@session.text.should == 'Bar'
|
|
5
|
+
end
|
|
6
6
|
|
|
7
|
+
context "with css as default selector" do
|
|
8
|
+
before { Capybara.default_selector = :css }
|
|
7
9
|
it "should print the text of the page" do
|
|
10
|
+
@session.visit('/with_simple_html')
|
|
8
11
|
@session.text.should == 'Bar'
|
|
9
12
|
end
|
|
13
|
+
after { Capybara.default_selector = :xpath }
|
|
14
|
+
end
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
after { Capybara.default_selector = :xpath }
|
|
17
|
-
end
|
|
16
|
+
it "should strip whitespace" do
|
|
17
|
+
@session.visit('/with_html')
|
|
18
|
+
n = @session.find(:css, '#second')
|
|
19
|
+
@session.find(:css, '#second').text.should =~ \
|
|
20
|
+
/\ADuis aute .* text with whitespace .* est laborum\.\z/
|
|
18
21
|
end
|
|
19
22
|
end
|
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
Capybara::SpecHelper.spec "#uncheck" do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/form')
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
it "should uncheck a checkbox by id" do
|
|
7
|
+
@session.uncheck("form_pets_hamster")
|
|
8
|
+
@session.click_button('awesome')
|
|
9
|
+
extract_results(@session)['pets'].should include('dog')
|
|
10
|
+
extract_results(@session)['pets'].should_not include('hamster')
|
|
11
|
+
end
|
|
6
12
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
it "should uncheck a checkbox by label" do
|
|
14
|
+
@session.uncheck("Hamster")
|
|
15
|
+
@session.click_button('awesome')
|
|
16
|
+
extract_results(@session)['pets'].should include('dog')
|
|
17
|
+
extract_results(@session)['pets'].should_not include('hamster')
|
|
18
|
+
end
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
end
|
|
20
|
+
it "casts to string" do
|
|
21
|
+
@session.uncheck(:"form_pets_hamster")
|
|
22
|
+
@session.click_button('awesome')
|
|
23
|
+
extract_results(@session)['pets'].should include('dog')
|
|
24
|
+
extract_results(@session)['pets'].should_not include('hamster')
|
|
20
25
|
end
|
|
21
26
|
end
|
|
@@ -1,61 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
1
|
+
Capybara::SpecHelper.spec "#unselect" do
|
|
2
|
+
before do
|
|
3
|
+
@session.visit('/form')
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
context "with multiple select" do
|
|
7
|
+
it "should unselect an option from a select box by id" do
|
|
8
|
+
@session.unselect('Commando', :from => 'form_underwear')
|
|
9
|
+
@session.click_button('awesome')
|
|
10
|
+
extract_results(@session)['underwear'].should include('Briefs', 'Boxerbriefs')
|
|
11
|
+
extract_results(@session)['underwear'].should_not include('Commando')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should unselect an option without a select box" do
|
|
15
|
+
@session.unselect('Commando')
|
|
16
|
+
@session.click_button('awesome')
|
|
17
|
+
extract_results(@session)['underwear'].should include('Briefs', 'Boxerbriefs')
|
|
18
|
+
extract_results(@session)['underwear'].should_not include('Commando')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should unselect an option from a select box by label" do
|
|
22
|
+
@session.unselect('Commando', :from => 'Underwear')
|
|
23
|
+
@session.click_button('awesome')
|
|
24
|
+
extract_results(@session)['underwear'].should include('Briefs', 'Boxerbriefs')
|
|
25
|
+
extract_results(@session)['underwear'].should_not include('Commando')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should favour exact matches to option labels" do
|
|
29
|
+
@session.unselect("Briefs", :from => 'Underwear')
|
|
30
|
+
@session.click_button('awesome')
|
|
31
|
+
extract_results(@session)['underwear'].should include('Commando', 'Boxerbriefs')
|
|
32
|
+
extract_results(@session)['underwear'].should_not include('Briefs')
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should escape quotes" do
|
|
36
|
+
@session.unselect("Frenchman's Pantalons", :from => 'Underwear')
|
|
37
|
+
@session.click_button('awesome')
|
|
38
|
+
extract_results(@session)['underwear'].should_not include("Frenchman's Pantalons")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "casts to string" do
|
|
42
|
+
@session.unselect(:"Briefs", :from => :'Underwear')
|
|
43
|
+
@session.click_button('awesome')
|
|
44
|
+
extract_results(@session)['underwear'].should include('Commando', 'Boxerbriefs')
|
|
45
|
+
extract_results(@session)['underwear'].should_not include('Briefs')
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "with single select" do
|
|
50
|
+
it "should raise an error" do
|
|
51
|
+
expect { @session.unselect("English", :from => 'form_locale') }.to raise_error(Capybara::UnselectNotAllowed)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context "with a locator that doesn't exist" do
|
|
56
|
+
it "should raise an error" do
|
|
57
|
+
msg = "Unable to find select box \"does not exist\""
|
|
58
|
+
expect do
|
|
59
|
+
@session.unselect('foo', :from => 'does not exist')
|
|
60
|
+
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context "with an option that doesn't exist" do
|
|
65
|
+
it "should raise an error" do
|
|
66
|
+
msg = "Unable to find option \"Does not Exist\""
|
|
67
|
+
expect do
|
|
68
|
+
@session.unselect('Does not Exist', :from => 'form_underwear')
|
|
69
|
+
end.to raise_error(Capybara::ElementNotFound, msg)
|
|
59
70
|
end
|
|
60
71
|
end
|
|
61
72
|
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Capybara::SpecHelper.spec '#visit' do
|
|
2
|
+
it "should fetch a response from the driver with a relative url" do
|
|
3
|
+
@session.visit('/')
|
|
4
|
+
@session.should have_content('Hello world!')
|
|
5
|
+
@session.visit('/foo')
|
|
6
|
+
@session.should have_content('Another World')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should fetch a response from the driver with an absolute url with a port" do
|
|
10
|
+
# Preparation
|
|
11
|
+
@session.visit('/')
|
|
12
|
+
root_uri = URI.parse(@session.current_url)
|
|
13
|
+
|
|
14
|
+
@session.visit("http://#{root_uri.host}:#{root_uri.port}/")
|
|
15
|
+
@session.should have_content('Hello world!')
|
|
16
|
+
@session.visit("http://#{root_uri.host}:#{root_uri.port}/foo")
|
|
17
|
+
@session.should have_content('Another World')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context "when Capybara.always_include_port is true" do
|
|
21
|
+
|
|
22
|
+
let(:root_uri) do
|
|
23
|
+
@session.visit('/')
|
|
24
|
+
URI.parse(@session.current_url)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
before(:each) do
|
|
28
|
+
Capybara.always_include_port = true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
after(:each) do
|
|
32
|
+
Capybara.always_include_port = false
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should fetch a response from the driver with an absolute url without a port" do
|
|
36
|
+
@session.visit("http://#{root_uri.host}/")
|
|
37
|
+
URI.parse(@session.current_url).port.should == root_uri.port
|
|
38
|
+
@session.should have_content('Hello world!')
|
|
39
|
+
|
|
40
|
+
@session.visit("http://#{root_uri.host}/foo")
|
|
41
|
+
URI.parse(@session.current_url).port.should == root_uri.port
|
|
42
|
+
@session.should have_content('Another World')
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should send no referer when visiting a page" do
|
|
47
|
+
@session.visit '/get_referer'
|
|
48
|
+
@session.should have_content 'No referer'
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "should send no referer when visiting a second page" do
|
|
52
|
+
@session.visit '/get_referer'
|
|
53
|
+
@session.visit '/get_referer'
|
|
54
|
+
@session.should have_content 'No referer'
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "should send a referer when following a link" do
|
|
58
|
+
@session.visit '/referer_base'
|
|
59
|
+
@session.find('//a[@href="/get_referer"]').click
|
|
60
|
+
@session.body.should match %r{http://.*/referer_base}
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should preserve the original referer URL when following a redirect" do
|
|
64
|
+
@session.visit('/referer_base')
|
|
65
|
+
@session.find('//a[@href="/redirect_to_get_referer"]').click
|
|
66
|
+
@session.body.should match %r{http://.*/referer_base}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "should send a referer when submitting a form" do
|
|
70
|
+
@session.visit '/referer_base'
|
|
71
|
+
@session.find('//input').click
|
|
72
|
+
@session.body.should match %r{http://.*/referer_base}
|
|
73
|
+
end
|
|
74
|
+
end
|