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
@@ -27,6 +27,9 @@ $(function() {
27
27
  $('#with_focus_event').focus(function() {
28
28
  $('body').append('<p id="focus_event_triggered">Focus Event triggered</p>');
29
29
  });
30
+ $('#with_change_event').change(function() {
31
+ if($(this).val() == '') $(this).val("Can't be empty");
32
+ });
30
33
  $('#checkbox_with_event').click(function() {
31
34
  $('body').append('<p id="checkbox_event_triggered">Checkbox event triggered</p>');
32
35
  });
@@ -1,77 +1,79 @@
1
- shared_examples_for "all" do
2
- describe '#all' do
3
- before do
4
- @session.visit('/with_html')
5
- end
1
+ Capybara::SpecHelper.spec "#all" do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
6
5
 
7
- it "should find all elements using the given locator" do
8
- @session.all('//p').should have(3).elements
9
- @session.all('//h1').first.text.should == 'This is a test'
10
- @session.all("//input[@id='test_field']").first[:value].should == 'monkey'
11
- end
6
+ it "should find all elements using the given locator" do
7
+ @session.all('//p').should have(3).elements
8
+ @session.all('//h1').first.text.should == 'This is a test'
9
+ @session.all("//input[@id='test_field']").first[:value].should == 'monkey'
10
+ end
12
11
 
13
- it "should return an empty array when nothing was found" do
14
- @session.all('//div[@id="nosuchthing"]').should be_empty
15
- end
12
+ it "should return an empty array when nothing was found" do
13
+ @session.all('//div[@id="nosuchthing"]').should be_empty
14
+ end
16
15
 
17
- it "should accept an XPath instance" do
18
- @session.visit('/form')
19
- @xpath = XPath::HTML.fillable_field('Name')
20
- @result = @session.all(@xpath).map { |r| r.value }
21
- @result.should include('Smith', 'John', 'John Smith')
22
- end
16
+ it "should accept an XPath instance" do
17
+ @session.visit('/form')
18
+ @xpath = XPath::HTML.fillable_field('Name')
19
+ @result = @session.all(@xpath).map { |r| r.value }
20
+ @result.should include('Smith', 'John', 'John Smith')
21
+ end
23
22
 
24
- context "with css selectors" do
25
- it "should find all elements using the given selector" do
26
- @session.all(:css, 'h1').first.text.should == 'This is a test'
27
- @session.all(:css, "input[id='test_field']").first[:value].should == 'monkey'
28
- end
23
+ it "should raise an error when given invalid options" do
24
+ expect { @session.all('//p', :schmoo => "foo") }.to raise_error(ArgumentError)
25
+ end
29
26
 
30
- it "should find all elements when given a list of selectors" do
31
- @session.all(:css, 'h1, p').should have(4).elements
32
- end
27
+ context "with css selectors" do
28
+ it "should find all elements using the given selector" do
29
+ @session.all(:css, 'h1').first.text.should == 'This is a test'
30
+ @session.all(:css, "input[id='test_field']").first[:value].should == 'monkey'
33
31
  end
34
32
 
35
- context "with xpath selectors" do
36
- it "should find the first element using the given locator" do
37
- @session.all(:xpath, '//h1').first.text.should == 'This is a test'
38
- @session.all(:xpath, "//input[@id='test_field']").first[:value].should == 'monkey'
39
- end
33
+ it "should find all elements when given a list of selectors" do
34
+ @session.all(:css, 'h1, p').should have(4).elements
40
35
  end
36
+ end
41
37
 
42
- context "with css as default selector" do
43
- before { Capybara.default_selector = :css }
44
- it "should find the first element using the given locator" do
45
- @session.all('h1').first.text.should == 'This is a test'
46
- @session.all("input[id='test_field']").first[:value].should == 'monkey'
47
- end
48
- after { Capybara.default_selector = :xpath }
38
+ context "with xpath selectors" do
39
+ it "should find the first element using the given locator" do
40
+ @session.all(:xpath, '//h1').first.text.should == 'This is a test'
41
+ @session.all(:xpath, "//input[@id='test_field']").first[:value].should == 'monkey'
49
42
  end
43
+ end
50
44
 
51
- context "with visible filter" do
52
- after { Capybara.ignore_hidden_elements = false }
53
- it "should only find visible nodes" do
54
- @session.all("//a[@title='awesome title']").should have(2).elements
55
- @session.all("//a[@title='awesome title']", :visible => true).should have(1).elements
56
- Capybara.ignore_hidden_elements = true
57
- @session.all("//a[@title='awesome title']").should have(1).elements
58
- end
45
+ context "with css as default selector" do
46
+ before { Capybara.default_selector = :css }
47
+ it "should find the first element using the given locator" do
48
+ @session.all('h1').first.text.should == 'This is a test'
49
+ @session.all("input[id='test_field']").first[:value].should == 'monkey'
50
+ end
51
+ after { Capybara.default_selector = :xpath }
52
+ end
59
53
 
60
- it "should only find invisible nodes" do
61
- Capybara.ignore_hidden_elements = true
62
- @session.all("//a[@title='awesome title']", :visible => false).should have(2).elements
63
- end
54
+ context "with visible filter" do
55
+ after { Capybara.ignore_hidden_elements = false }
56
+ it "should only find visible nodes" do
57
+ @session.all(:css, "a.simple").should have(2).elements
58
+ @session.all(:css, "a.simple", :visible => true).should have(1).elements
59
+ Capybara.ignore_hidden_elements = true
60
+ @session.all(:css, "a.simple").should have(1).elements
64
61
  end
65
62
 
66
- context "within a scope" do
67
- before do
68
- @session.visit('/with_scope')
69
- end
63
+ it "should only find invisible nodes" do
64
+ Capybara.ignore_hidden_elements = true
65
+ @session.all(:css, "a.simple", :visible => false).should have(2).elements
66
+ end
67
+ end
68
+
69
+ context "within a scope" do
70
+ before do
71
+ @session.visit('/with_scope')
72
+ end
70
73
 
71
- it "should find any element using the given locator" do
72
- @session.within(:xpath, "//div[@id='for_bar']") do
73
- @session.all('.//li').should have(2).elements
74
- end
74
+ it "should find any element using the given locator" do
75
+ @session.within(:xpath, "//div[@id='for_bar']") do
76
+ @session.all('.//li').should have(2).elements
75
77
  end
76
78
  end
77
79
  end
@@ -0,0 +1,123 @@
1
+ Capybara::SpecHelper.spec '#assert_selector' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
5
+
6
+ it "should be true if the given selector is on the page" do
7
+ @session.assert_selector(:xpath, "//p")
8
+ @session.assert_selector(:css, "p a#foo")
9
+ @session.assert_selector("//p[contains(.,'est')]")
10
+ end
11
+
12
+ it "should be false if the given selector is not on the page" do
13
+ expect { @session.assert_selector(:xpath, "//abbr") }.to raise_error(Capybara::ElementNotFound)
14
+ expect { @session.assert_selector(:css, "p a#doesnotexist") }.to raise_error(Capybara::ElementNotFound)
15
+ expect { @session.assert_selector("//p[contains(.,'thisstringisnotonpage')]") }.to raise_error(Capybara::ElementNotFound)
16
+ end
17
+
18
+ it "should use default selector" do
19
+ Capybara.default_selector = :css
20
+ expect { @session.assert_selector("p a#doesnotexist") }.to raise_error(Capybara::ElementNotFound)
21
+ @session.assert_selector("p a#foo")
22
+ end
23
+
24
+ it "should respect scopes" do
25
+ @session.within "//p[@id='first']" do
26
+ @session.assert_selector(".//a[@id='foo']")
27
+ expect { @session.assert_selector(".//a[@id='red']") }.to raise_error(Capybara::ElementNotFound)
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.assert_selector("//p", :count => 3)
34
+ @session.assert_selector("//p//a[@id='foo']", :count => 1)
35
+ @session.assert_selector("//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
+ expect { @session.assert_selector("//p", :count => 6) }.to raise_error(Capybara::ElementNotFound)
40
+ expect { @session.assert_selector("//p//a[@id='foo']", :count => 2) }.to raise_error(Capybara::ElementNotFound)
41
+ expect { @session.assert_selector("//p[contains(.,'est')]", :count => 5) }.to raise_error(Capybara::ElementNotFound)
42
+ end
43
+
44
+ it "should be false if the content isn't on the page at all" do
45
+ expect { @session.assert_selector("//abbr", :count => 2) }.to raise_error(Capybara::ElementNotFound)
46
+ expect { @session.assert_selector("//p//a[@id='doesnotexist']", :count => 1) }.to raise_error(Capybara::ElementNotFound)
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.assert_selector("//p//a", :text => "Redirect", :count => 1)
53
+ expect { @session.assert_selector("//p", :text => "Doesnotexist") }.to raise_error(Capybara::ElementNotFound)
54
+ end
55
+
56
+ it "should discard all matches where the given regexp is not matched" do
57
+ @session.assert_selector("//p//a", :text => /re[dab]i/i, :count => 1)
58
+ expect { @session.assert_selector("//p//a", :text => /Red$/) }.to raise_error(Capybara::ElementNotFound)
59
+ end
60
+ end
61
+ end
62
+
63
+ Capybara::SpecHelper.spec '#assert_no_selector' 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
+ expect { @session.assert_no_selector(:xpath, "//p") }.to raise_error(Capybara::ElementNotFound)
70
+ expect { @session.assert_no_selector(:css, "p a#foo") }.to raise_error(Capybara::ElementNotFound)
71
+ expect { @session.assert_no_selector("//p[contains(.,'est')]") }.to raise_error(Capybara::ElementNotFound)
72
+ end
73
+
74
+ it "should be true if the given selector is not on the page" do
75
+ @session.assert_no_selector(:xpath, "//abbr")
76
+ @session.assert_no_selector(:css, "p a#doesnotexist")
77
+ @session.assert_no_selector("//p[contains(.,'thisstringisnotonpage')]")
78
+ end
79
+
80
+ it "should use default selector" do
81
+ Capybara.default_selector = :css
82
+ @session.assert_no_selector("p a#doesnotexist")
83
+ expect { @session.assert_no_selector("p a#foo") }.to raise_error(Capybara::ElementNotFound)
84
+ end
85
+
86
+ it "should respect scopes" do
87
+ @session.within "//p[@id='first']" do
88
+ expect { @session.assert_no_selector(".//a[@id='foo']") }.to raise_error(Capybara::ElementNotFound)
89
+ @session.assert_no_selector(".//a[@id='red']")
90
+ end
91
+ end
92
+
93
+ context "with count" do
94
+ it "should be false if the content is on the page the given number of times" do
95
+ expect { @session.assert_no_selector("//p", :count => 3) }.to raise_error(Capybara::ElementNotFound)
96
+ expect { @session.assert_no_selector("//p//a[@id='foo']", :count => 1) }.to raise_error(Capybara::ElementNotFound)
97
+ expect { @session.assert_no_selector("//p[contains(.,'est')]", :count => 1) }.to raise_error(Capybara::ElementNotFound)
98
+ end
99
+
100
+ it "should be true if the content is on the page the wrong number of times" do
101
+ @session.assert_no_selector("//p", :count => 6)
102
+ @session.assert_no_selector("//p//a[@id='foo']", :count => 2)
103
+ @session.assert_no_selector("//p[contains(.,'est')]", :count => 5)
104
+ end
105
+
106
+ it "should be true if the content isn't on the page at all" do
107
+ @session.assert_no_selector("//abbr", :count => 2)
108
+ @session.assert_no_selector("//p//a[@id='doesnotexist']", :count => 1)
109
+ end
110
+ end
111
+
112
+ context "with text" do
113
+ it "should discard all matches where the given string is contained" do
114
+ expect { @session.assert_no_selector("//p//a", :text => "Redirect", :count => 1) }.to raise_error(Capybara::ElementNotFound)
115
+ @session.assert_no_selector("//p", :text => "Doesnotexist")
116
+ end
117
+
118
+ it "should discard all matches where the given regexp is matched" do
119
+ expect { @session.assert_no_selector("//p//a", :text => /re[dab]i/i, :count => 1) }.to raise_error(Capybara::ElementNotFound)
120
+ @session.assert_no_selector("//p//a", :text => /Red$/)
121
+ end
122
+ end
123
+ end
@@ -1,73 +1,90 @@
1
- shared_examples_for "attach_file" do
1
+ Capybara::SpecHelper.spec "#attach_file" do
2
+ before do
3
+ @test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
4
+ @another_test_file_path = File.expand_path('../fixtures/another_test_file.txt', File.dirname(__FILE__))
5
+ @test_jpg_file_path = File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))
6
+ @session.visit('/form')
7
+ end
8
+
9
+ context "with normal form" do
10
+ it "should set a file path by id" do
11
+ @session.attach_file "form_image", __FILE__
12
+ @session.click_button('awesome')
13
+ extract_results(@session)['image'].should == File.basename(__FILE__)
14
+ end
2
15
 
3
- describe "#attach_file" do
4
- before do
5
- @test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
6
- @test_jpg_file_path = File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))
7
- @session.visit('/form')
16
+ it "should set a file path by label" do
17
+ @session.attach_file "Image", __FILE__
18
+ @session.click_button('awesome')
19
+ extract_results(@session)['image'].should == File.basename(__FILE__)
8
20
  end
9
21
 
10
- context "with normal form" do
11
- it "should set a file path by id" do
12
- @session.attach_file "form_image", __FILE__
13
- @session.click_button('awesome')
14
- extract_results(@session)['image'].should == File.basename(__FILE__)
15
- end
22
+ it "casts to string" do
23
+ @session.attach_file :"form_image", __FILE__
24
+ @session.click_button('awesome')
25
+ extract_results(@session)['image'].should == File.basename(__FILE__)
26
+ end
27
+ end
16
28
 
17
- it "should set a file path by label" do
18
- @session.attach_file "Image", __FILE__
19
- @session.click_button('awesome')
20
- extract_results(@session)['image'].should == File.basename(__FILE__)
21
- end
29
+ context "with multipart form" do
30
+ it "should set a file path by id" do
31
+ @session.attach_file "form_document", @test_file_path
32
+ @session.click_button('Upload Single')
33
+ @session.should have_content(File.read(@test_file_path))
22
34
  end
23
35
 
24
- context "with multipart form" do
25
- it "should set a file path by id" do
26
- @session.attach_file "form_document", @test_file_path
27
- @session.click_button('Upload')
28
- @session.body.should include(File.read(@test_file_path))
29
- end
36
+ it "should set a file path by label" do
37
+ @session.attach_file "Single Document", @test_file_path
38
+ @session.click_button('Upload Single')
39
+ @session.should have_content(File.read(@test_file_path))
40
+ end
30
41
 
31
- it "should set a file path by label" do
32
- @session.attach_file "Document", @test_file_path
33
- @session.click_button('Upload')
34
- @session.body.should include(File.read(@test_file_path))
35
- end
42
+ it "should not break if no file is submitted" do
43
+ @session.click_button('Upload Single')
44
+ @session.should have_content('No file uploaded')
45
+ end
36
46
 
37
- it "should not break if no file is submitted" do
38
- @session.click_button('Upload')
39
- @session.body.should include('No file uploaded')
40
- end
47
+ it "should send content type text/plain when uploading a text file" do
48
+ @session.attach_file "Single Document", @test_file_path
49
+ @session.click_button 'Upload Single'
50
+ @session.should have_content('text/plain')
51
+ end
41
52
 
42
- it "should send content type text/plain when uploading a text file" do
43
- @session.attach_file "Document", @test_file_path
44
- @session.click_button 'Upload'
45
- @session.body.should include('text/plain')
46
- end
53
+ it "should send content type image/jpeg when uploading an image" do
54
+ @session.attach_file "Single Document", @test_jpg_file_path
55
+ @session.click_button 'Upload Single'
56
+ @session.should have_content('image/jpeg')
57
+ end
47
58
 
48
- it "should send content type image/jpeg when uploading an image" do
49
- @session.attach_file "Document", @test_jpg_file_path
50
- @session.click_button 'Upload'
51
- @session.body.should include('image/jpeg')
52
- end
59
+ it "should not break when using HTML5 multiple file input" do
60
+ @session.attach_file "Multiple Documents", @test_file_path
61
+ @session.click_button('Upload Multiple')
62
+ @session.body.should include("1 | ")#number of files
63
+ @session.should have_content(File.read(@test_file_path))
64
+ end
53
65
 
54
- it "should not break when using HTML5 multiple file input" do
55
- @session.attach_file "Multiple Documents", @test_file_path
56
- @session.click_button('Upload Multiple')
57
- @session.body.should include(File.read(@test_file_path))
58
- end
66
+ it "should not break when using HTML5 multiple file input uploading multiple files" do
67
+ pending "Selenium is buggy on this, see http://code.google.com/p/selenium/issues/detail?id=2239" if @session.respond_to?(:mode) && @session.mode == :selenium
68
+ @session.attach_file "Multiple Documents", [@test_file_path, @another_test_file_path]
69
+ @session.click_button('Upload Multiple')
70
+ @session.body.should include("2 | ")#number of files
71
+ @session.body.should include(File.read(@test_file_path))
72
+ @session.body.should include(File.read(@another_test_file_path))
59
73
  end
74
+ end
60
75
 
61
- context "with a locator that doesn't exist" do
62
- it "should raise an error" do
63
- running { @session.attach_file('does not exist', @test_file_path) }.should raise_error(Capybara::ElementNotFound)
64
- end
76
+ context "with a locator that doesn't exist" do
77
+ it "should raise an error" do
78
+ msg = "Unable to find file field \"does not exist\""
79
+ expect do
80
+ @session.attach_file('does not exist', @test_file_path)
81
+ end.to raise_error(Capybara::ElementNotFound, msg)
65
82
  end
83
+ end
66
84
 
67
- context "with a path that doesn't exist" do
68
- it "should raise an error" do
69
- running { @session.attach_file('Image', '/no_such_file.png') }.should raise_error(Capybara::FileNotFound)
70
- end
85
+ context "with a path that doesn't exist" do
86
+ it "should raise an error" do
87
+ expect { @session.attach_file('Image', '/no_such_file.png') }.to raise_error(Capybara::FileNotFound)
71
88
  end
72
89
  end
73
90
  end
@@ -0,0 +1,21 @@
1
+ Capybara::SpecHelper.spec '#body' do
2
+ it "should return the unmodified page body" do
3
+ @session.visit('/')
4
+ @session.should have_content('Hello world!') # wait for content to appear if visit is async
5
+ @session.body.should include('Hello world!')
6
+ end
7
+
8
+ if "".respond_to?(:encoding)
9
+ context "encoding of response between ascii and utf8" do
10
+ it "should be valid with html entities" do
11
+ @session.visit('/with_html_entities')
12
+ lambda { @session.body.encode!("UTF-8") }.should_not raise_error
13
+ end
14
+
15
+ it "should be valid without html entities" do
16
+ @session.visit('/with_html')
17
+ lambda { @session.body.encode!("UTF-8") }.should_not raise_error
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,65 +1,85 @@
1
- shared_examples_for "check" do
1
+ Capybara::SpecHelper.spec "#check" do
2
+ before do
3
+ @session.visit('/form')
4
+ end
2
5
 
3
- describe "#check" do
4
- before do
5
- @session.visit('/form')
6
+ describe "'checked' attribute" do
7
+ it "should be true if checked" do
8
+ @session.check("Terms of Use")
9
+ @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_true
6
10
  end
7
-
8
- describe "'checked' attribute" do
9
- it "should be true if checked" do
10
- @session.check("Terms of Use")
11
- @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_true
12
- end
13
-
14
- it "should be false if unchecked" do
15
- @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_false
16
- end
11
+
12
+ it "should be false if unchecked" do
13
+ @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_false
17
14
  end
15
+ end
18
16
 
19
- describe "checking" do
20
- it "should not change an already checked checkbox" do
21
- @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
22
- @session.check('form_pets_dog')
23
- @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
24
- end
17
+ it "should trigger associated events", :requires => [:js] do
18
+ @session.visit('/with_js')
19
+ @session.check('checkbox_with_event')
20
+ @session.should have_css('#checkbox_event_triggered');
21
+ end
25
22
 
26
- it "should check an unchecked checkbox" do
27
- @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
28
- @session.check('form_pets_cat')
29
- @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_true
30
- end
23
+ describe "checking" do
24
+ it "should not change an already checked checkbox" do
25
+ @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
26
+ @session.check('form_pets_dog')
27
+ @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
31
28
  end
32
29
 
33
- describe "unchecking" do
34
- it "should not change an already unchecked checkbox" do
35
- @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
36
- @session.uncheck('form_pets_cat')
37
- @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
38
- end
30
+ it "should check an unchecked checkbox" do
31
+ @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
32
+ @session.check('form_pets_cat')
33
+ @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_true
34
+ end
35
+ end
39
36
 
40
- it "should uncheck a checked checkbox" do
41
- @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
42
- @session.uncheck('form_pets_dog')
43
- @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_false
44
- end
37
+ describe "unchecking" do
38
+ it "should not change an already unchecked checkbox" do
39
+ @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
40
+ @session.uncheck('form_pets_cat')
41
+ @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false
45
42
  end
46
43
 
47
- it "should check a checkbox by id" do
48
- @session.check("form_pets_cat")
49
- @session.click_button('awesome')
50
- extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
44
+ it "should uncheck a checked checkbox" do
45
+ @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true
46
+ @session.uncheck('form_pets_dog')
47
+ @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_false
51
48
  end
49
+ end
52
50
 
53
- it "should check a checkbox by label" do
54
- @session.check("Cat")
55
- @session.click_button('awesome')
56
- extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
51
+ it "should check a checkbox by id" do
52
+ @session.check("form_pets_cat")
53
+ @session.click_button('awesome')
54
+ extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
55
+ end
56
+
57
+ it "should check a checkbox by label" do
58
+ @session.check("Cat")
59
+ @session.click_button('awesome')
60
+ extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
61
+ end
62
+
63
+ it "casts to string" do
64
+ @session.check(:"form_pets_cat")
65
+ @session.click_button('awesome')
66
+ extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
67
+ end
68
+
69
+ context "with a locator that doesn't exist" do
70
+ it "should raise an error" do
71
+ msg = "Unable to find checkbox \"does not exist\""
72
+ expect do
73
+ @session.check('does not exist')
74
+ end.to raise_error(Capybara::ElementNotFound, msg)
57
75
  end
76
+ end
58
77
 
59
- context "with a locator that doesn't exist" do
60
- it "should raise an error" do
61
- running { @session.check('does not exist') }.should raise_error(Capybara::ElementNotFound)
62
- end
78
+ context "with a disabled checkbox" do
79
+ it "should raise an error" do
80
+ expect do
81
+ @session.check('Disabled Checkbox')
82
+ end.to raise_error(Capybara::ElementNotFound)
63
83
  end
64
84
  end
65
85
  end
@@ -1,26 +1,40 @@
1
- shared_examples_for "choose" do
1
+ Capybara::SpecHelper.spec "#choose" do
2
+ before do
3
+ @session.visit('/form')
4
+ end
2
5
 
3
- describe "#choose" do
4
- before do
5
- @session.visit('/form')
6
- end
6
+ it "should choose a radio button by id" do
7
+ @session.choose("gender_male")
8
+ @session.click_button('awesome')
9
+ extract_results(@session)['gender'].should == 'male'
10
+ end
7
11
 
8
- it "should choose a radio button by id" do
9
- @session.choose("gender_male")
10
- @session.click_button('awesome')
11
- extract_results(@session)['gender'].should == 'male'
12
- end
12
+ it "should choose a radio button by label" do
13
+ @session.choose("Both")
14
+ @session.click_button('awesome')
15
+ extract_results(@session)['gender'].should == 'both'
16
+ end
17
+
18
+ it "casts to string" do
19
+ @session.choose("Both")
20
+ @session.click_button(:'awesome')
21
+ extract_results(@session)['gender'].should == 'both'
22
+ end
13
23
 
14
- it "should choose a radio button by label" do
15
- @session.choose("Both")
16
- @session.click_button('awesome')
17
- extract_results(@session)['gender'].should == 'both'
24
+ context "with a locator that doesn't exist" do
25
+ it "should raise an error" do
26
+ msg = "Unable to find radio button \"does not exist\""
27
+ expect do
28
+ @session.choose('does not exist')
29
+ end.to raise_error(Capybara::ElementNotFound, msg)
18
30
  end
31
+ end
19
32
 
20
- context "with a locator that doesn't exist" do
21
- it "should raise an error" do
22
- running { @session.choose('does not exist') }.should raise_error(Capybara::ElementNotFound)
23
- end
33
+ context "with a disabled radio button" do
34
+ it "should raise an error" do
35
+ expect do
36
+ @session.choose('Disabled Radio')
37
+ end.to raise_error(Capybara::ElementNotFound)
24
38
  end
25
39
  end
26
40
  end