capybara 2.0.0.beta2 → 2.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/History.txt +30 -1
  2. data/README.md +52 -31
  3. data/lib/capybara.rb +1 -0
  4. data/lib/capybara/driver/base.rb +1 -1
  5. data/lib/capybara/driver/node.rb +1 -0
  6. data/lib/capybara/dsl.rb +12 -5
  7. data/lib/capybara/helpers.rb +33 -0
  8. data/lib/capybara/node/actions.rb +4 -2
  9. data/lib/capybara/node/base.rb +52 -1
  10. data/lib/capybara/node/element.rb +0 -12
  11. data/lib/capybara/node/finders.rb +1 -1
  12. data/lib/capybara/node/matchers.rb +57 -47
  13. data/lib/capybara/node/simple.rb +4 -0
  14. data/lib/capybara/query.rb +11 -11
  15. data/lib/capybara/rack_test/browser.rb +14 -15
  16. data/lib/capybara/rack_test/driver.rb +2 -2
  17. data/lib/capybara/rack_test/node.rb +15 -2
  18. data/lib/capybara/result.rb +7 -19
  19. data/lib/capybara/rspec.rb +7 -4
  20. data/lib/capybara/rspec/features.rb +4 -1
  21. data/lib/capybara/rspec/matchers.rb +8 -3
  22. data/lib/capybara/selector.rb +1 -2
  23. data/lib/capybara/selenium/driver.rb +2 -2
  24. data/lib/capybara/selenium/node.rb +9 -7
  25. data/lib/capybara/session.rb +47 -31
  26. data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
  27. data/lib/capybara/spec/public/test.js +1 -1
  28. data/lib/capybara/spec/session/all_spec.rb +60 -62
  29. data/lib/capybara/spec/session/assert_selector.rb +123 -0
  30. data/lib/capybara/spec/session/attach_file_spec.rb +72 -58
  31. data/lib/capybara/spec/session/body_spec.rb +21 -0
  32. data/lib/capybara/spec/session/check_spec.rb +67 -50
  33. data/lib/capybara/spec/session/choose_spec.rb +32 -21
  34. data/lib/capybara/spec/session/click_button_spec.rb +261 -221
  35. data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -30
  36. data/lib/capybara/spec/session/click_link_spec.rb +95 -81
  37. data/lib/capybara/spec/session/current_url_spec.rb +70 -60
  38. data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
  39. data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
  40. data/lib/capybara/spec/session/fill_in_spec.rb +118 -92
  41. data/lib/capybara/spec/session/find_button_spec.rb +16 -14
  42. data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
  43. data/lib/capybara/spec/session/find_field_spec.rb +23 -21
  44. data/lib/capybara/spec/session/find_link_spec.rb +15 -14
  45. data/lib/capybara/spec/session/find_spec.rb +96 -91
  46. data/lib/capybara/spec/session/first_spec.rb +53 -55
  47. data/lib/capybara/spec/session/has_button_spec.rb +22 -24
  48. data/lib/capybara/spec/session/has_css_spec.rb +190 -205
  49. data/lib/capybara/spec/session/has_field_spec.rb +167 -169
  50. data/lib/capybara/spec/session/has_link_spec.rb +26 -29
  51. data/lib/capybara/spec/session/has_select_spec.rb +175 -176
  52. data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
  53. data/lib/capybara/spec/session/has_table_spec.rb +22 -26
  54. data/lib/capybara/spec/session/has_text_spec.rb +159 -132
  55. data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
  56. data/lib/capybara/spec/session/headers.rb +4 -17
  57. data/lib/capybara/spec/session/html_spec.rb +15 -0
  58. data/lib/capybara/spec/session/node_spec.rb +172 -82
  59. data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
  60. data/lib/capybara/spec/session/response_code.rb +4 -17
  61. data/lib/capybara/spec/session/save_page_spec.rb +46 -0
  62. data/lib/capybara/spec/session/screenshot.rb +8 -24
  63. data/lib/capybara/spec/session/select_spec.rb +100 -89
  64. data/lib/capybara/spec/session/source_spec.rb +12 -0
  65. data/lib/capybara/spec/session/text_spec.rb +15 -17
  66. data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
  67. data/lib/capybara/spec/session/unselect_spec.rb +57 -52
  68. data/lib/capybara/spec/session/visit_spec.rb +58 -60
  69. data/lib/capybara/spec/session/within_frame_spec.rb +24 -26
  70. data/lib/capybara/spec/session/within_spec.rb +119 -121
  71. data/lib/capybara/spec/session/within_window_spec.rb +29 -31
  72. data/lib/capybara/spec/spec_helper.rb +84 -0
  73. data/lib/capybara/spec/test_app.rb +5 -3
  74. data/lib/capybara/spec/views/form.erb +1 -0
  75. data/lib/capybara/spec/views/with_html.erb +6 -1
  76. data/lib/capybara/spec/views/with_js.erb +1 -0
  77. data/lib/capybara/version.rb +1 -1
  78. data/spec/basic_node_spec.rb +2 -2
  79. data/spec/capybara_spec.rb +9 -0
  80. data/spec/dsl_spec.rb +22 -10
  81. data/spec/rack_test_spec.rb +28 -23
  82. data/spec/result_spec.rb +51 -0
  83. data/spec/rspec/features_spec.rb +19 -0
  84. data/spec/rspec/matchers_spec.rb +6 -0
  85. data/spec/rspec_spec.rb +1 -1
  86. data/spec/selenium_spec.rb +11 -25
  87. data/spec/server_spec.rb +2 -2
  88. data/spec/spec_helper.rb +1 -46
  89. metadata +41 -98
  90. data/lib/capybara/spec/session.rb +0 -183
  91. data/lib/capybara/spec/session/javascript.rb +0 -290
  92. data/lib/capybara/util/save_and_open_page.rb +0 -45
  93. data/spec/save_and_open_page_spec.rb +0 -155
@@ -0,0 +1 @@
1
+ ThisIsTheOtherTestFile
@@ -40,7 +40,7 @@ $(function() {
40
40
  });
41
41
  $('#reload-link').click(function() {
42
42
  setTimeout(function() {
43
- $('#reload-me').replaceWith('<div id="reload-me"><em><a>RELOADED</a></em></div>');
43
+ $('#reload-me').replaceWith('<div id="reload-me"><em><a>has been reloaded</a></em></div>');
44
44
  }, 250)
45
45
  });
46
46
  $('#reload-list').click(function() {
@@ -1,81 +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
- it "should raise an error when given invalid options" do
25
- expect { @session.all('//p', :schmoo => "foo") }.to raise_error(ArgumentError)
26
- 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
27
26
 
28
- context "with css selectors" do
29
- it "should find all elements using the given selector" do
30
- @session.all(:css, 'h1').first.text.should == 'This is a test'
31
- @session.all(:css, "input[id='test_field']").first[:value].should == 'monkey'
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'
31
+ end
33
32
 
34
- it "should find all elements when given a list of selectors" do
35
- @session.all(:css, 'h1, p').should have(4).elements
36
- end
33
+ it "should find all elements when given a list of selectors" do
34
+ @session.all(:css, 'h1, p').should have(4).elements
37
35
  end
36
+ end
38
37
 
39
- context "with xpath selectors" do
40
- it "should find the first element using the given locator" do
41
- @session.all(:xpath, '//h1').first.text.should == 'This is a test'
42
- @session.all(:xpath, "//input[@id='test_field']").first[:value].should == 'monkey'
43
- end
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'
44
42
  end
43
+ end
45
44
 
46
- context "with css as default selector" do
47
- before { Capybara.default_selector = :css }
48
- it "should find the first element using the given locator" do
49
- @session.all('h1').first.text.should == 'This is a test'
50
- @session.all("input[id='test_field']").first[:value].should == 'monkey'
51
- end
52
- after { Capybara.default_selector = :xpath }
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'
53
50
  end
51
+ after { Capybara.default_selector = :xpath }
52
+ end
54
53
 
55
- context "with visible filter" do
56
- after { Capybara.ignore_hidden_elements = false }
57
- it "should only find visible nodes" do
58
- @session.all(:css, "a.simple").should have(2).elements
59
- @session.all(:css, "a.simple", :visible => true).should have(1).elements
60
- Capybara.ignore_hidden_elements = true
61
- @session.all(:css, "a.simple").should have(1).elements
62
- 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
61
+ end
63
62
 
64
- it "should only find invisible nodes" do
65
- Capybara.ignore_hidden_elements = true
66
- @session.all(:css, "a.simple", :visible => false).should have(2).elements
67
- 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
68
66
  end
67
+ end
69
68
 
70
- context "within a scope" do
71
- before do
72
- @session.visit('/with_scope')
73
- end
69
+ context "within a scope" do
70
+ before do
71
+ @session.visit('/with_scope')
72
+ end
74
73
 
75
- it "should find any element using the given locator" do
76
- @session.within(:xpath, "//div[@id='for_bar']") do
77
- @session.all('.//li').should have(2).elements
78
- 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
79
77
  end
80
78
  end
81
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,76 +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 Single')
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 "Single Document", @test_file_path
33
- @session.click_button('Upload Single')
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 Single')
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 "Single Document", @test_file_path
44
- @session.click_button 'Upload Single'
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 "Single Document", @test_jpg_file_path
50
- @session.click_button 'Upload Single'
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
- msg = "Unable to find file field \"does not exist\""
64
- running do
65
- @session.attach_file('does not exist', @test_file_path)
66
- end.should raise_error(Capybara::ElementNotFound, msg)
67
- 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)
68
82
  end
83
+ end
69
84
 
70
- context "with a path that doesn't exist" do
71
- it "should raise an error" do
72
- running { @session.attach_file('Image', '/no_such_file.png') }.should raise_error(Capybara::FileNotFound)
73
- 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)
74
88
  end
75
89
  end
76
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