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,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
@@ -1,29 +1,13 @@
1
- shared_examples_for "session with screenshot support" do
2
- describe "#save_screenshot" do
3
- let(:image_path) { File.join(Dir.tmpdir, 'capybara-screenshot.png') }
1
+ Capybara::SpecHelper.spec "#save_screenshot" do
2
+ let(:image_path) { File.join(Dir.tmpdir, 'capybara-screenshot.png') }
4
3
 
5
- before do
6
- @session.visit '/'
7
- @session.save_screenshot image_path
8
- end
9
-
10
- it "should generate PNG file" do
11
- magic = File.read(image_path, 4)
12
- magic.should eq "\x89PNG"
13
- end
4
+ before do
5
+ @session.visit '/'
6
+ @session.save_screenshot image_path
14
7
  end
15
- end
16
-
17
- shared_examples_for "session without screenshot support" do
18
- describe "#save_screenshot" do
19
- before do
20
- @session.visit('/')
21
- end
22
8
 
23
- it "should raise an error" do
24
- running {
25
- @session.save_screenshot 'raise_error.png'
26
- }.should raise_error(Capybara::NotSupportedByDriverError)
27
- end
9
+ it "should generate PNG file", :requires => [:screenshot] do
10
+ magic = File.read(image_path, 4)
11
+ magic.should eq "\x89PNG"
28
12
  end
29
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'
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
24
+
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)
24
68
  end
69
+ end
25
70
 
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'
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)
30
77
  end
78
+ end
31
79
 
32
- it "should select an option without giving a select box" do
33
- @session.select("Swedish")
34
- @session.click_button('awesome')
35
- extract_results(@session)['locale'].should == 'sv'
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)
36
85
  end
86
+ end
37
87
 
38
- it "should escape quotes" do
39
- @session.select("John's made-up language", :from => 'Locale')
40
- @session.click_button('awesome')
41
- 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 == []
42
91
  end
43
92
 
44
- it "should obey from" do
45
- @session.select("Miss", :from => "Other title")
46
- @session.click_button('awesome')
47
- results = extract_results(@session)
48
- results['other_title'].should == "Miss"
49
- 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')
50
97
  end
51
98
 
52
- it "show match labels with preceding or trailing whitespace" do
53
- @session.select("Lojban", :from => 'Locale')
99
+ it "should select one option" do
100
+ @session.select("Ruby", :from => 'Language')
54
101
  @session.click_button('awesome')
55
- extract_results(@session)['locale'].should == 'jbo'
102
+ extract_results(@session)['languages'].should == ['Ruby']
56
103
  end
57
104
 
58
- context "with a locator that doesn't exist" do
59
- it "should raise an error" do
60
- msg = "Unable to find select box \"does not exist\""
61
- running do
62
- @session.select('foo', :from => 'does not exist')
63
- end.should raise_error(Capybara::ElementNotFound, msg)
64
- 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')
65
110
  end
66
111
 
67
- context "with an option that doesn't exist" do
68
- it "should raise an error" do
69
- msg = "Unable to find option \"Does not Exist\""
70
- running do
71
- @session.select('Does not Exist', :from => 'form_locale')
72
- end.should raise_error(Capybara::ElementNotFound, msg)
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,24 +1,22 @@
1
- shared_examples_for "text" do
2
- describe '#text' do
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
+
7
+ context "with css as default selector" do
8
+ before { Capybara.default_selector = :css }
3
9
  it "should print the text of the page" do
4
10
  @session.visit('/with_simple_html')
5
11
  @session.text.should == 'Bar'
6
12
  end
13
+ after { Capybara.default_selector = :xpath }
14
+ end
7
15
 
8
- context "with css as default selector" do
9
- before { Capybara.default_selector = :css }
10
- it "should print the text of the page" do
11
- @session.visit('/with_simple_html')
12
- @session.text.should == 'Bar'
13
- end
14
- after { Capybara.default_selector = :xpath }
15
- end
16
-
17
- it "should strip whitespace" do
18
- @session.visit('/with_html')
19
- n = @session.find(:css, '#second')
20
- @session.find(:css, '#second').text.should =~ \
21
- /\ADuis aute .* text with whitespace .* est laborum\.\z/
22
- 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/
23
21
  end
24
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