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.
Files changed (111) hide show
  1. data/{History.txt → History.md} +138 -0
  2. data/License.txt +22 -0
  3. data/README.md +850 -0
  4. data/lib/capybara/cucumber.rb +2 -5
  5. data/lib/capybara/driver/base.rb +6 -6
  6. data/lib/capybara/driver/node.rb +3 -2
  7. data/lib/capybara/dsl.rb +13 -124
  8. data/lib/capybara/helpers.rb +33 -0
  9. data/lib/capybara/node/actions.rb +16 -30
  10. data/lib/capybara/node/base.rb +56 -13
  11. data/lib/capybara/node/element.rb +18 -30
  12. data/lib/capybara/node/finders.rb +28 -90
  13. data/lib/capybara/node/matchers.rb +121 -73
  14. data/lib/capybara/node/simple.rb +13 -11
  15. data/lib/capybara/query.rb +78 -0
  16. data/lib/capybara/rack_test/browser.rb +27 -39
  17. data/lib/capybara/rack_test/driver.rb +13 -3
  18. data/lib/capybara/rack_test/node.rb +31 -2
  19. data/lib/capybara/result.rb +72 -0
  20. data/lib/capybara/rspec/features.rb +4 -1
  21. data/lib/capybara/rspec/matchers.rb +33 -63
  22. data/lib/capybara/rspec.rb +7 -4
  23. data/lib/capybara/selector.rb +97 -34
  24. data/lib/capybara/selenium/driver.rb +15 -62
  25. data/lib/capybara/selenium/node.rb +14 -21
  26. data/lib/capybara/server.rb +32 -27
  27. data/lib/capybara/session.rb +90 -50
  28. data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
  29. data/lib/capybara/spec/public/jquery-ui.js +791 -0
  30. data/lib/capybara/spec/public/jquery.js +9046 -0
  31. data/lib/capybara/spec/public/test.js +3 -0
  32. data/lib/capybara/spec/session/all_spec.rb +61 -59
  33. data/lib/capybara/spec/session/assert_selector.rb +123 -0
  34. data/lib/capybara/spec/session/attach_file_spec.rb +72 -55
  35. data/lib/capybara/spec/session/body_spec.rb +21 -0
  36. data/lib/capybara/spec/session/check_spec.rb +68 -48
  37. data/lib/capybara/spec/session/choose_spec.rb +32 -18
  38. data/lib/capybara/spec/session/click_button_spec.rb +263 -232
  39. data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -29
  40. data/lib/capybara/spec/session/click_link_spec.rb +96 -96
  41. data/lib/capybara/spec/session/current_url_spec.rb +88 -10
  42. data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
  43. data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
  44. data/lib/capybara/spec/session/fill_in_spec.rb +119 -103
  45. data/lib/capybara/spec/session/find_button_spec.rb +16 -14
  46. data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
  47. data/lib/capybara/spec/session/find_field_spec.rb +23 -21
  48. data/lib/capybara/spec/session/find_link_spec.rb +15 -14
  49. data/lib/capybara/spec/session/find_spec.rb +93 -115
  50. data/lib/capybara/spec/session/first_spec.rb +51 -85
  51. data/lib/capybara/spec/session/has_button_spec.rb +22 -24
  52. data/lib/capybara/spec/session/has_css_spec.rb +190 -205
  53. data/lib/capybara/spec/session/has_field_spec.rb +170 -144
  54. data/lib/capybara/spec/session/has_link_spec.rb +26 -29
  55. data/lib/capybara/spec/session/has_select_spec.rb +161 -109
  56. data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
  57. data/lib/capybara/spec/session/has_table_spec.rb +22 -88
  58. data/lib/capybara/spec/session/has_text_spec.rb +195 -0
  59. data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
  60. data/lib/capybara/spec/session/headers.rb +4 -17
  61. data/lib/capybara/spec/session/html_spec.rb +15 -0
  62. data/lib/capybara/spec/session/node_spec.rb +205 -0
  63. data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
  64. data/lib/capybara/spec/session/response_code.rb +4 -17
  65. data/lib/capybara/spec/session/save_page_spec.rb +46 -0
  66. data/lib/capybara/spec/session/screenshot.rb +13 -0
  67. data/lib/capybara/spec/session/select_spec.rb +99 -88
  68. data/lib/capybara/spec/session/source_spec.rb +12 -0
  69. data/lib/capybara/spec/session/text_spec.rb +15 -12
  70. data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
  71. data/lib/capybara/spec/session/unselect_spec.rb +69 -58
  72. data/lib/capybara/spec/session/visit_spec.rb +74 -0
  73. data/lib/capybara/spec/session/within_frame_spec.rb +31 -0
  74. data/lib/capybara/spec/session/within_spec.rb +118 -131
  75. data/lib/capybara/spec/session/within_window_spec.rb +38 -0
  76. data/lib/capybara/spec/spec_helper.rb +84 -0
  77. data/lib/capybara/spec/test_app.rb +32 -6
  78. data/lib/capybara/spec/views/form.erb +12 -10
  79. data/lib/capybara/spec/views/host_links.erb +2 -2
  80. data/lib/capybara/spec/views/tables.erb +6 -66
  81. data/lib/capybara/spec/views/with_html.erb +9 -4
  82. data/lib/capybara/spec/views/with_js.erb +11 -7
  83. data/lib/capybara/version.rb +1 -1
  84. data/lib/capybara.rb +125 -6
  85. data/spec/basic_node_spec.rb +17 -5
  86. data/spec/capybara_spec.rb +9 -0
  87. data/spec/dsl_spec.rb +31 -17
  88. data/spec/rack_test_spec.rb +157 -0
  89. data/spec/result_spec.rb +51 -0
  90. data/spec/rspec/features_spec.rb +19 -2
  91. data/spec/rspec/matchers_spec.rb +170 -89
  92. data/spec/rspec_spec.rb +1 -3
  93. data/spec/selenium_spec.rb +53 -0
  94. data/spec/server_spec.rb +37 -25
  95. data/spec/spec_helper.rb +1 -30
  96. metadata +39 -31
  97. data/README.rdoc +0 -722
  98. data/lib/capybara/spec/driver.rb +0 -301
  99. data/lib/capybara/spec/session/current_host_spec.rb +0 -68
  100. data/lib/capybara/spec/session/has_content_spec.rb +0 -106
  101. data/lib/capybara/spec/session/javascript.rb +0 -306
  102. data/lib/capybara/spec/session.rb +0 -154
  103. data/lib/capybara/util/save_and_open_page.rb +0 -44
  104. data/lib/capybara/util/timeout.rb +0 -27
  105. data/spec/driver/rack_test_driver_spec.rb +0 -89
  106. data/spec/driver/selenium_driver_spec.rb +0 -37
  107. data/spec/save_and_open_page_spec.rb +0 -155
  108. data/spec/session/rack_test_session_spec.rb +0 -55
  109. data/spec/session/selenium_session_spec.rb +0 -26
  110. data/spec/string_spec.rb +0 -77
  111. 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
- 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
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
- shared_examples_for "select" do
2
- describe "#select" do
3
- before do
4
- @session.visit('/form')
5
- end
1
+ Capybara::SpecHelper.spec "#select" do
2
+ before do
3
+ @session.visit('/form')
4
+ end
6
5
 
7
- it "should return value of the first option" do
8
- @session.find_field('Title').value.should == 'Mrs'
9
- end
6
+ it "should return value of the first option" do
7
+ @session.find_field('Title').value.should == 'Mrs'
8
+ end
10
9
 
11
- it "should return value of the selected option" do
12
- @session.select("Miss", :from => 'Title')
13
- @session.find_field('Title').value.should == 'Miss'
14
- end
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
- it "should return the value attribute rather than content if present" do
17
- @session.find_field('Locale').value.should == 'en'
18
- end
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
- it "should select an option from a select box by id" do
21
- @session.select("Finish", :from => 'form_locale')
22
- @session.click_button('awesome')
23
- extract_results(@session)['locale'].should == 'fi'
24
- end
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
- it "should select an option from a select box by label" do
27
- @session.select("Finish", :from => 'Locale')
28
- @session.click_button('awesome')
29
- extract_results(@session)['locale'].should == 'fi'
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
- it "should select an option without giving a select box" do
33
- @session.select("Mr")
34
- @session.click_button('awesome')
35
- extract_results(@session)['title'].should == 'Mr'
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
- it "should favour exact matches to option labels" do
39
- @session.select("Mr", :from => 'Title')
40
- @session.click_button('awesome')
41
- extract_results(@session)['title'].should == 'Mr'
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
- it "should escape quotes" do
45
- @session.select("John's made-up language", :from => 'Locale')
46
- @session.click_button('awesome')
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 obey from" do
51
- @session.select("Miss", :from => "Other title")
52
- @session.click_button('awesome')
53
- results = extract_results(@session)
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 "show match labels with preceding or trailing whitespace" do
59
- @session.select("Lojban", :from => 'Locale')
99
+ it "should select one option" do
100
+ @session.select("Ruby", :from => 'Language')
60
101
  @session.click_button('awesome')
61
- extract_results(@session)['locale'].should == 'jbo'
102
+ extract_results(@session)['languages'].should == ['Ruby']
62
103
  end
63
104
 
64
- context "with a locator that doesn't exist" do
65
- it "should raise an error" do
66
- running { @session.select('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
67
- end
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
- context "with an option that doesn't exist" do
71
- it "should raise an error" do
72
- running { @session.select('Does not Exist', :from => 'form_locale') }.should raise_error(Capybara::ElementNotFound)
73
- end
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
- context "with multiple select" do
77
- it "should return an empty value" do
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
- shared_examples_for "text" do
2
- describe '#text' do
3
- before do
4
- @session.visit('/with_simple_html')
5
- end
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
- context "with css as default selector" do
12
- before { Capybara.default_selector = :css }
13
- it "should print the text of the page" do
14
- @session.text.should == 'Bar'
15
- end
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
- shared_examples_for "uncheck" do
2
- describe "#uncheck" do
3
- before do
4
- @session.visit('/form')
5
- end
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
- it "should uncheck a checkbox by id" do
8
- @session.uncheck("form_pets_hamster")
9
- @session.click_button('awesome')
10
- extract_results(@session)['pets'].should include('dog')
11
- extract_results(@session)['pets'].should_not include('hamster')
12
- end
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
- it "should uncheck a checkbox by label" do
15
- @session.uncheck("Hamster")
16
- @session.click_button('awesome')
17
- extract_results(@session)['pets'].should include('dog')
18
- extract_results(@session)['pets'].should_not include('hamster')
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
- shared_examples_for "unselect" do
2
- describe "#unselect" do
3
- before do
4
- @session.visit('/form')
5
- end
6
-
7
- context "with multiple select" do
8
- it "should unselect an option from a select box by id" do
9
- @session.unselect('Commando', :from => 'form_underwear')
10
- @session.click_button('awesome')
11
- extract_results(@session)['underwear'].should include('Briefs', 'Boxer Briefs')
12
- extract_results(@session)['underwear'].should_not include('Commando')
13
- end
14
-
15
- it "should unselect an option without a select box" do
16
- @session.unselect('Commando')
17
- @session.click_button('awesome')
18
- extract_results(@session)['underwear'].should include('Briefs', 'Boxer Briefs')
19
- extract_results(@session)['underwear'].should_not include('Commando')
20
- end
21
-
22
- it "should unselect an option from a select box by label" do
23
- @session.unselect('Commando', :from => 'Underwear')
24
- @session.click_button('awesome')
25
- extract_results(@session)['underwear'].should include('Briefs', 'Boxer Briefs')
26
- extract_results(@session)['underwear'].should_not include('Commando')
27
- end
28
-
29
- it "should favour exact matches to option labels" do
30
- @session.unselect("Briefs", :from => 'Underwear')
31
- @session.click_button('awesome')
32
- extract_results(@session)['underwear'].should include('Commando', 'Boxer Briefs')
33
- extract_results(@session)['underwear'].should_not include('Briefs')
34
- end
35
-
36
- it "should escape quotes" do
37
- @session.unselect("Frenchman's Pantalons", :from => 'Underwear')
38
- @session.click_button('awesome')
39
- extract_results(@session)['underwear'].should_not include("Frenchman's Pantalons")
40
- end
41
- end
42
-
43
- context "with single select" do
44
- it "should raise an error" do
45
- running { @session.unselect("English", :from => 'form_locale') }.should raise_error(Capybara::UnselectNotAllowed)
46
- end
47
- end
48
-
49
- context "with a locator that doesn't exist" do
50
- it "should raise an error" do
51
- running { @session.unselect('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
52
- end
53
- end
54
-
55
- context "with an option that doesn't exist" do
56
- it "should raise an error" do
57
- running { @session.unselect('Does not Exist', :from => 'form_underwear') }.should raise_error(Capybara::ElementNotFound)
58
- end
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