bjeanes-capybara 0.3.1

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 (88) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +87 -0
  3. data/README.rdoc +404 -0
  4. data/Rakefile +29 -0
  5. data/config.ru +6 -0
  6. data/lib/capybara.rb +53 -0
  7. data/lib/capybara/cucumber.rb +32 -0
  8. data/lib/capybara/driver/base.rb +37 -0
  9. data/lib/capybara/driver/celerity_driver.rb +135 -0
  10. data/lib/capybara/driver/culerity_driver.rb +25 -0
  11. data/lib/capybara/driver/rack_test_driver.rb +244 -0
  12. data/lib/capybara/driver/selenium_driver.rb +137 -0
  13. data/lib/capybara/dsl.rb +60 -0
  14. data/lib/capybara/node.rb +69 -0
  15. data/lib/capybara/rails.rb +11 -0
  16. data/lib/capybara/save_and_open_page.rb +33 -0
  17. data/lib/capybara/searchable.rb +53 -0
  18. data/lib/capybara/server.rb +111 -0
  19. data/lib/capybara/session.rb +274 -0
  20. data/lib/capybara/wait_until.rb +23 -0
  21. data/lib/capybara/xpath.rb +176 -0
  22. data/script/console +10 -0
  23. data/script/destroy +14 -0
  24. data/script/generate +14 -0
  25. data/spec/capybara_spec.rb +18 -0
  26. data/spec/driver/celerity_driver_spec.rb +17 -0
  27. data/spec/driver/culerity_driver_spec.rb +13 -0
  28. data/spec/driver/rack_test_driver_spec.rb +12 -0
  29. data/spec/driver/remote_culerity_driver_spec.rb +26 -0
  30. data/spec/driver/remote_selenium_driver_spec.rb +18 -0
  31. data/spec/driver/selenium_driver_spec.rb +12 -0
  32. data/spec/drivers_spec.rb +139 -0
  33. data/spec/dsl/all_spec.rb +69 -0
  34. data/spec/dsl/attach_file_spec.rb +64 -0
  35. data/spec/dsl/check_spec.rb +39 -0
  36. data/spec/dsl/choose_spec.rb +26 -0
  37. data/spec/dsl/click_button_spec.rb +218 -0
  38. data/spec/dsl/click_link_spec.rb +108 -0
  39. data/spec/dsl/click_spec.rb +24 -0
  40. data/spec/dsl/current_url_spec.rb +8 -0
  41. data/spec/dsl/fill_in_spec.rb +91 -0
  42. data/spec/dsl/find_button_spec.rb +16 -0
  43. data/spec/dsl/find_by_id_spec.rb +16 -0
  44. data/spec/dsl/find_field_spec.rb +22 -0
  45. data/spec/dsl/find_link_spec.rb +17 -0
  46. data/spec/dsl/find_spec.rb +57 -0
  47. data/spec/dsl/has_button_spec.rb +32 -0
  48. data/spec/dsl/has_content_spec.rb +101 -0
  49. data/spec/dsl/has_css_spec.rb +107 -0
  50. data/spec/dsl/has_field_spec.rb +96 -0
  51. data/spec/dsl/has_link_spec.rb +33 -0
  52. data/spec/dsl/has_xpath_spec.rb +123 -0
  53. data/spec/dsl/locate_spec.rb +59 -0
  54. data/spec/dsl/select_spec.rb +71 -0
  55. data/spec/dsl/uncheck_spec.rb +21 -0
  56. data/spec/dsl/within_spec.rb +153 -0
  57. data/spec/dsl_spec.rb +140 -0
  58. data/spec/fixtures/capybara.jpg +0 -0
  59. data/spec/fixtures/test_file.txt +1 -0
  60. data/spec/public/jquery-ui.js +35 -0
  61. data/spec/public/jquery.js +19 -0
  62. data/spec/public/test.js +30 -0
  63. data/spec/save_and_open_page_spec.rb +43 -0
  64. data/spec/searchable_spec.rb +61 -0
  65. data/spec/server_spec.rb +47 -0
  66. data/spec/session/celerity_session_spec.rb +27 -0
  67. data/spec/session/culerity_session_spec.rb +25 -0
  68. data/spec/session/rack_test_session_spec.rb +25 -0
  69. data/spec/session/selenium_session_spec.rb +25 -0
  70. data/spec/session_spec.rb +77 -0
  71. data/spec/session_with_headers_support_spec.rb +13 -0
  72. data/spec/session_with_javascript_support_spec.rb +182 -0
  73. data/spec/session_without_headers_support_spec.rb +15 -0
  74. data/spec/session_without_javascript_support_spec.rb +15 -0
  75. data/spec/spec_helper.rb +27 -0
  76. data/spec/test_app.rb +71 -0
  77. data/spec/views/buttons.erb +4 -0
  78. data/spec/views/fieldsets.erb +29 -0
  79. data/spec/views/form.erb +226 -0
  80. data/spec/views/postback.erb +13 -0
  81. data/spec/views/tables.erb +122 -0
  82. data/spec/views/with_html.erb +38 -0
  83. data/spec/views/with_js.erb +34 -0
  84. data/spec/views/with_scope.erb +36 -0
  85. data/spec/views/with_simple_html.erb +1 -0
  86. data/spec/wait_until_spec.rb +28 -0
  87. data/spec/xpath_spec.rb +271 -0
  88. metadata +239 -0
@@ -0,0 +1,16 @@
1
+ shared_examples_for "find_button" do
2
+ describe '#find_button' do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ it "should find any field" do
8
+ @session.find_button('med')[:id].should == "mediocre"
9
+ @session.find_button('crap321').value.should == "crappy"
10
+ end
11
+
12
+ it "should return nil if the field doesn't exist" do
13
+ @session.find_button('Does not exist').should be_nil
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ shared_examples_for "find_by_id" do
2
+ describe '#find_by_id' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ it "should find any element by id" do
8
+ @session.find_by_id('red').tag_name.should == 'a'
9
+ @session.find_by_id('hidden_via_ancestor').tag_name.should == 'div'
10
+ end
11
+
12
+ it "should return nil if no element with id is found" do
13
+ @session.find_by_id('nothing_with_this_id').should be_nil
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ shared_examples_for "find_field" do
2
+ describe '#find_field' do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ it "should find any field" do
8
+ @session.find_field('Dog').value.should == 'dog'
9
+ @session.find_field('form_description').text.should == 'Descriptive text goes here'
10
+ @session.find_field('Region')[:name].should == 'form[region]'
11
+ end
12
+
13
+ it "should be nil if the field doesn't exist" do
14
+ @session.find_field('Does not exist').should be_nil
15
+ end
16
+
17
+ it "should be aliased as 'field_labeled' for webrat compatibility" do
18
+ @session.field_labeled('Dog').value.should == 'dog'
19
+ @session.field_labeled('Does not exist').should be_nil
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ shared_examples_for "find_link" do
2
+
3
+ describe '#find_link' do
4
+ before do
5
+ @session.visit('/with_html')
6
+ end
7
+
8
+ it "should find any field" do
9
+ @session.find_link('foo').text.should == "ullamco"
10
+ @session.find_link('labore')[:href].should == "/with_simple_html"
11
+ end
12
+
13
+ it "should return nil if the field doesn't exist" do
14
+ @session.find_link('Does not exist').should be_nil
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,57 @@
1
+ shared_examples_for "find" do
2
+ describe '#find' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ it "should find the first element using the given locator" do
8
+ @session.find('//h1').text.should == 'This is a test'
9
+ @session.find("//input[@id='test_field']")[:value].should == 'monkey'
10
+ end
11
+
12
+ context "with css selectors" do
13
+ it "should find the first element using the given locator" do
14
+ @session.find(:css, 'h1').text.should == 'This is a test'
15
+ @session.find(:css, "input[id='test_field']")[:value].should == 'monkey'
16
+ end
17
+ end
18
+
19
+ context "with xpath selectors" do
20
+ it "should find the first element using the given locator" do
21
+ @session.find(:xpath, '//h1').text.should == 'This is a test'
22
+ @session.find(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
23
+ end
24
+ end
25
+
26
+ context "with css as default selector" do
27
+ before { Capybara.default_selector = :css }
28
+ it "should find the first element using the given locator" do
29
+ @session.find('h1').text.should == 'This is a test'
30
+ @session.find("input[id='test_field']")[:value].should == 'monkey'
31
+ end
32
+ after { Capybara.default_selector = :xpath }
33
+ end
34
+
35
+ it "should return nil when nothing was found" do
36
+ @session.find('//div[@id="nosuchthing"]').should be_nil
37
+ end
38
+
39
+ it "should accept an XPath instance and respect the order of paths" do
40
+ @session.visit('/form')
41
+ @xpath = Capybara::XPath.text_field('Name')
42
+ @session.find(@xpath).value.should == 'John Smith'
43
+ end
44
+
45
+ context "within a scope" do
46
+ before do
47
+ @session.visit('/with_scope')
48
+ end
49
+
50
+ it "should find the first element using the given locator" do
51
+ @session.within(:xpath, "//div[@id='for_bar']") do
52
+ @session.find('//li').text.should =~ /With Simple HTML/
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,32 @@
1
+ shared_examples_for "has_button" do
2
+ describe '#has_button?' do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ it "should be true if the given button is on the page" do
8
+ @session.should have_button('med')
9
+ @session.should have_button('crap321')
10
+ end
11
+
12
+ it "should be false if the given button is not on the page" do
13
+ @session.should_not have_button('monkey')
14
+ end
15
+ end
16
+
17
+ describe '#has_no_button?' do
18
+ before do
19
+ @session.visit('/form')
20
+ end
21
+
22
+ it "should be true if the given button is on the page" do
23
+ @session.should_not have_no_button('med')
24
+ @session.should_not have_no_button('crap321')
25
+ end
26
+
27
+ it "should be false if the given button is not on the page" do
28
+ @session.should have_no_button('monkey')
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,101 @@
1
+ shared_examples_for "has_content" do
2
+ describe '#has_content?' do
3
+ it "should be true if the given content is on the page at least once" do
4
+ @session.visit('/with_html')
5
+ @session.should have_content('est')
6
+ @session.should have_content('Lorem')
7
+ @session.should have_content('Redirect')
8
+ end
9
+
10
+ it "should be true if scoped to an element which has the content" do
11
+ @session.visit('/with_html')
12
+ @session.within("//a[@title='awesome title']") do
13
+ @session.should have_content('labore')
14
+ end
15
+ end
16
+
17
+ it "should be false if scoped to an element which does not have the content" do
18
+ @session.visit('/with_html')
19
+ @session.within("//a[@title='awesome title']") do
20
+ @session.should_not have_content('monkey')
21
+ end
22
+ end
23
+
24
+ it "should ignore tags" do
25
+ @session.visit('/with_html')
26
+ @session.should_not have_content('exercitation <a href="/foo" id="foo">ullamco</a> laboris')
27
+ @session.should have_content('exercitation ullamco laboris')
28
+ end
29
+
30
+ it "should be false if the given content is not on the page" do
31
+ @session.visit('/with_html')
32
+ @session.should_not have_content('xxxxyzzz')
33
+ @session.should_not have_content('monkey')
34
+ end
35
+
36
+ it 'should handle single quotes in the content' do
37
+ @session.visit('/with-quotes')
38
+ @session.should have_content("can't")
39
+ end
40
+
41
+ it 'should handle double quotes in the content' do
42
+ @session.visit('/with-quotes')
43
+ @session.should have_content(%q{"No," he said})
44
+ end
45
+
46
+ it 'should handle mixed single and double quotes in the content' do
47
+ @session.visit('/with-quotes')
48
+ @session.should have_content(%q{"you can't do that."})
49
+ end
50
+ end
51
+
52
+ describe '#has_no_content?' do
53
+ it "should be false if the given content is on the page at least once" do
54
+ @session.visit('/with_html')
55
+ @session.should_not have_no_content('est')
56
+ @session.should_not have_no_content('Lorem')
57
+ @session.should_not have_no_content('Redirect')
58
+ end
59
+
60
+ it "should be false if scoped to an element which has the content" do
61
+ @session.visit('/with_html')
62
+ @session.within("//a[@title='awesome title']") do
63
+ @session.should_not have_no_content('labore')
64
+ end
65
+ end
66
+
67
+ it "should be true if scoped to an element which does not have the content" do
68
+ @session.visit('/with_html')
69
+ @session.within("//a[@title='awesome title']") do
70
+ @session.should have_no_content('monkey')
71
+ end
72
+ end
73
+
74
+ it "should ignore tags" do
75
+ @session.visit('/with_html')
76
+ @session.should have_no_content('exercitation <a href="/foo" id="foo">ullamco</a> laboris')
77
+ @session.should_not have_no_content('exercitation ullamco laboris')
78
+ end
79
+
80
+ it "should be true if the given content is not on the page" do
81
+ @session.visit('/with_html')
82
+ @session.should have_no_content('xxxxyzzz')
83
+ @session.should have_no_content('monkey')
84
+ end
85
+
86
+ it 'should handle single quotes in the content' do
87
+ @session.visit('/with-quotes')
88
+ @session.should_not have_no_content("can't")
89
+ end
90
+
91
+ it 'should handle double quotes in the content' do
92
+ @session.visit('/with-quotes')
93
+ @session.should_not have_no_content(%q{"No," he said})
94
+ end
95
+
96
+ it 'should handle mixed single and double quotes in the content' do
97
+ @session.visit('/with-quotes')
98
+ @session.should_not have_no_content(%q{"you can't do that."})
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,107 @@
1
+ shared_examples_for "has_css" do
2
+ describe '#has_css?' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ it "should be true if the given selector is on the page" do
8
+ @session.should have_css("p")
9
+ @session.should have_css("p a#foo")
10
+ end
11
+
12
+ it "should be false if the given selector is not on the page" do
13
+ @session.should_not have_css("abbr")
14
+ @session.should_not have_css("p a#doesnotexist")
15
+ @session.should_not have_css("p.nosuchclass")
16
+ end
17
+
18
+ it "should respect scopes" do
19
+ @session.within "//p[@id='first']" do
20
+ @session.should have_css("a#foo")
21
+ @session.should_not have_css("a#red")
22
+ end
23
+ end
24
+
25
+ context "with count" do
26
+ it "should be true if the content is on the page the given number of times" do
27
+ @session.should have_css("p", :count => 3)
28
+ @session.should have_css("p a#foo", :count => 1)
29
+ end
30
+
31
+ it "should be false if the content is on the page the given number of times" do
32
+ @session.should_not have_css("p", :count => 6)
33
+ @session.should_not have_css("p a#foo", :count => 2)
34
+ end
35
+
36
+ it "should be false if the content isn't on the page at all" do
37
+ @session.should_not have_css("abbr", :count => 2)
38
+ @session.should_not have_css("p a.doesnotexist", :count => 1)
39
+ end
40
+ end
41
+
42
+ context "with text" do
43
+ it "should discard all matches where the given string is not contained" do
44
+ @session.should have_css("p a", :text => "Redirect", :count => 1)
45
+ @session.should_not have_css("p a", :text => "Doesnotexist")
46
+ end
47
+
48
+ it "should discard all matches where the given regexp is not matched" do
49
+ @session.should have_css("p a", :text => /re[dab]i/i, :count => 1)
50
+ @session.should_not have_css("p a", :text => /Red$/)
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#has_no_css?' do
56
+ before do
57
+ @session.visit('/with_html')
58
+ end
59
+
60
+ it "should be false if the given selector is on the page" do
61
+ @session.should_not have_no_css("p")
62
+ @session.should_not have_no_css("p a#foo")
63
+ end
64
+
65
+ it "should be true if the given selector is not on the page" do
66
+ @session.should have_no_css("abbr")
67
+ @session.should have_no_css("p a#doesnotexist")
68
+ @session.should have_no_css("p.nosuchclass")
69
+ end
70
+
71
+ it "should respect scopes" do
72
+ @session.within "//p[@id='first']" do
73
+ @session.should_not have_no_css("a#foo")
74
+ @session.should have_no_css("a#red")
75
+ end
76
+ end
77
+
78
+ context "with count" do
79
+ it "should be false if the content is on the page the given number of times" do
80
+ @session.should_not have_no_css("p", :count => 3)
81
+ @session.should_not have_no_css("p a#foo", :count => 1)
82
+ end
83
+
84
+ it "should be true if the content is on the page the given number of times" do
85
+ @session.should have_no_css("p", :count => 6)
86
+ @session.should have_no_css("p a#foo", :count => 2)
87
+ end
88
+
89
+ it "should be true if the content isn't on the page at all" do
90
+ @session.should have_no_css("abbr", :count => 2)
91
+ @session.should have_no_css("p a.doesnotexist", :count => 1)
92
+ end
93
+ end
94
+
95
+ context "with text" do
96
+ it "should discard all matches where the given string is not contained" do
97
+ @session.should_not have_no_css("p a", :text => "Redirect", :count => 1)
98
+ @session.should have_no_css("p a", :text => "Doesnotexist")
99
+ end
100
+
101
+ it "should discard all matches where the given regexp is not matched" do
102
+ @session.should_not have_no_css("p a", :text => /re[dab]i/i, :count => 1)
103
+ @session.should have_no_css("p a", :text => /Red$/)
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,96 @@
1
+ shared_examples_for "has_field" do
2
+ describe '#has_field' do
3
+ before { @session.visit('/form') }
4
+
5
+ it "should be true if the field is on the page" do
6
+ @session.should have_field('Dog')
7
+ @session.should have_field('form_description')
8
+ @session.should have_field('Region')
9
+ end
10
+
11
+ it "should be false if the field is not on the page" do
12
+ @session.should_not have_field('Monkey')
13
+ end
14
+
15
+ context 'with value' do
16
+ it "should be true if a field with the given value is on the page" do
17
+ @session.should have_field('First Name', :with => 'John')
18
+ @session.should have_field('Phone', :with => '+1 555 7021')
19
+ @session.should have_field('Street', :with => 'Sesame street 66')
20
+ @session.should have_field('Description', :with => 'Descriptive text goes here')
21
+ end
22
+
23
+ it "should be false if the given field is not on the page" do
24
+ @session.should_not have_field('First Name', :with => 'Peter')
25
+ @session.should_not have_field('Wrong Name', :with => 'John')
26
+ @session.should_not have_field('Description', :with => 'Monkey')
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '#has_no_field' do
32
+ before { @session.visit('/form') }
33
+
34
+ it "should be false if the field is on the page" do
35
+ @session.should_not have_no_field('Dog')
36
+ @session.should_not have_no_field('form_description')
37
+ @session.should_not have_no_field('Region')
38
+ end
39
+
40
+ it "should be true if the field is not on the page" do
41
+ @session.should have_no_field('Monkey')
42
+ end
43
+
44
+ context 'with value' do
45
+ it "should be flase if a field with the given value is on the page" do
46
+ @session.should_not have_no_field('First Name', :with => 'John')
47
+ @session.should_not have_no_field('Phone', :with => '+1 555 7021')
48
+ @session.should_not have_no_field('Street', :with => 'Sesame street 66')
49
+ @session.should_not have_no_field('Description', :with => 'Descriptive text goes here')
50
+ end
51
+
52
+ it "should be true if the given field is not on the page" do
53
+ @session.should have_no_field('First Name', :with => 'Peter')
54
+ @session.should have_no_field('Wrong Name', :with => 'John')
55
+ @session.should have_no_field('Description', :with => 'Monkey')
56
+ end
57
+ end
58
+ end
59
+
60
+ describe '#has_checked_field?' do
61
+ before { @session.visit('/form') }
62
+
63
+ it "should be true if a checked field is on the page" do
64
+ @session.should have_checked_field('gender_female')
65
+ @session.should have_checked_field('Hamster')
66
+ end
67
+
68
+ it "should be false if an unchecked field is on the page" do
69
+ @session.should_not have_checked_field('form_pets_cat')
70
+ @session.should_not have_checked_field('Male')
71
+ end
72
+
73
+ it "should be false if no field is on the page" do
74
+ @session.should_not have_checked_field('Does Not Exist')
75
+ end
76
+ end
77
+
78
+ describe '#has_unchecked_field?' do
79
+ before { @session.visit('/form') }
80
+
81
+ it "should be false if a checked field is on the page" do
82
+ @session.should_not have_unchecked_field('gender_female')
83
+ @session.should_not have_unchecked_field('Hamster')
84
+ end
85
+
86
+ it "should be true if an unchecked field is on the page" do
87
+ @session.should have_unchecked_field('form_pets_cat')
88
+ @session.should have_unchecked_field('Male')
89
+ end
90
+
91
+ it "should be false if no field is on the page" do
92
+ @session.should_not have_unchecked_field('Does Not Exist')
93
+ end
94
+ end
95
+ end
96
+