yannp-capybara 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/History.txt +112 -0
  2. data/README.rdoc +442 -0
  3. data/lib/capybara/cucumber.rb +32 -0
  4. data/lib/capybara/driver/base.rb +56 -0
  5. data/lib/capybara/driver/celerity_driver.rb +154 -0
  6. data/lib/capybara/driver/culerity_driver.rb +26 -0
  7. data/lib/capybara/driver/node.rb +66 -0
  8. data/lib/capybara/driver/rack_test_driver.rb +279 -0
  9. data/lib/capybara/driver/selenium_driver.rb +157 -0
  10. data/lib/capybara/dsl.rb +98 -0
  11. data/lib/capybara/node/actions.rb +156 -0
  12. data/lib/capybara/node/finders.rb +155 -0
  13. data/lib/capybara/node/matchers.rb +97 -0
  14. data/lib/capybara/node.rb +209 -0
  15. data/lib/capybara/rails.rb +17 -0
  16. data/lib/capybara/server.rb +101 -0
  17. data/lib/capybara/session.rb +278 -0
  18. data/lib/capybara/spec/driver.rb +190 -0
  19. data/lib/capybara/spec/fixtures/capybara.jpg +0 -0
  20. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  21. data/lib/capybara/spec/public/jquery-ui.js +35 -0
  22. data/lib/capybara/spec/public/jquery.js +19 -0
  23. data/lib/capybara/spec/public/test.js +33 -0
  24. data/lib/capybara/spec/session/all_spec.rb +73 -0
  25. data/lib/capybara/spec/session/attach_file_spec.rb +64 -0
  26. data/lib/capybara/spec/session/check_spec.rb +67 -0
  27. data/lib/capybara/spec/session/choose_spec.rb +26 -0
  28. data/lib/capybara/spec/session/click_button_spec.rb +243 -0
  29. data/lib/capybara/spec/session/click_link_or_button_spec.rb +30 -0
  30. data/lib/capybara/spec/session/click_link_spec.rb +108 -0
  31. data/lib/capybara/spec/session/current_url_spec.rb +15 -0
  32. data/lib/capybara/spec/session/fill_in_spec.rb +119 -0
  33. data/lib/capybara/spec/session/find_button_spec.rb +18 -0
  34. data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
  35. data/lib/capybara/spec/session/find_field_spec.rb +26 -0
  36. data/lib/capybara/spec/session/find_link_spec.rb +19 -0
  37. data/lib/capybara/spec/session/find_spec.rb +91 -0
  38. data/lib/capybara/spec/session/has_button_spec.rb +32 -0
  39. data/lib/capybara/spec/session/has_content_spec.rb +106 -0
  40. data/lib/capybara/spec/session/has_css_spec.rb +107 -0
  41. data/lib/capybara/spec/session/has_field_spec.rb +96 -0
  42. data/lib/capybara/spec/session/has_link_spec.rb +33 -0
  43. data/lib/capybara/spec/session/has_select_spec.rb +89 -0
  44. data/lib/capybara/spec/session/has_table_spec.rb +96 -0
  45. data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
  46. data/lib/capybara/spec/session/headers.rb +19 -0
  47. data/lib/capybara/spec/session/javascript.rb +232 -0
  48. data/lib/capybara/spec/session/response_code.rb +19 -0
  49. data/lib/capybara/spec/session/select_spec.rb +91 -0
  50. data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
  51. data/lib/capybara/spec/session/unselect_spec.rb +54 -0
  52. data/lib/capybara/spec/session/within_spec.rb +153 -0
  53. data/lib/capybara/spec/session.rb +78 -0
  54. data/lib/capybara/spec/test_app.rb +94 -0
  55. data/lib/capybara/spec/views/buttons.erb +4 -0
  56. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  57. data/lib/capybara/spec/views/form.erb +245 -0
  58. data/lib/capybara/spec/views/frame_one.erb +8 -0
  59. data/lib/capybara/spec/views/frame_two.erb +8 -0
  60. data/lib/capybara/spec/views/postback.erb +13 -0
  61. data/lib/capybara/spec/views/tables.erb +122 -0
  62. data/lib/capybara/spec/views/with_html.erb +43 -0
  63. data/lib/capybara/spec/views/with_js.erb +39 -0
  64. data/lib/capybara/spec/views/with_scope.erb +36 -0
  65. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  66. data/lib/capybara/spec/views/within_frames.erb +10 -0
  67. data/lib/capybara/util/save_and_open_page.rb +36 -0
  68. data/lib/capybara/util/timeout.rb +27 -0
  69. data/lib/capybara/version.rb +3 -0
  70. data/lib/capybara/xpath.rb +182 -0
  71. data/lib/capybara.rb +73 -0
  72. data/spec/capybara_spec.rb +18 -0
  73. data/spec/driver/celerity_driver_spec.rb +17 -0
  74. data/spec/driver/culerity_driver_spec.rb +13 -0
  75. data/spec/driver/rack_test_driver_spec.rb +19 -0
  76. data/spec/driver/remote_culerity_driver_spec.rb +24 -0
  77. data/spec/driver/remote_selenium_driver_spec.rb +19 -0
  78. data/spec/driver/selenium_driver_spec.rb +13 -0
  79. data/spec/dsl_spec.rb +140 -0
  80. data/spec/save_and_open_page_spec.rb +83 -0
  81. data/spec/server_spec.rb +53 -0
  82. data/spec/session/celerity_session_spec.rb +28 -0
  83. data/spec/session/culerity_session_spec.rb +26 -0
  84. data/spec/session/rack_test_session_spec.rb +34 -0
  85. data/spec/session/selenium_session_spec.rb +26 -0
  86. data/spec/spec_helper.rb +23 -0
  87. data/spec/timeout_spec.rb +28 -0
  88. data/spec/xpath_spec.rb +173 -0
  89. metadata +314 -0
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Capybara::Driver::Selenium do
4
+ before(:all) do
5
+ Capybara.app_host = "http://capybara-testapp.heroku.com"
6
+ end
7
+
8
+ after(:all) do
9
+ Capybara.app_host = nil
10
+ end
11
+
12
+ before do
13
+ @driver = Capybara::Driver::Selenium.new(TestApp)
14
+ end
15
+
16
+ it_should_behave_like "driver"
17
+ it_should_behave_like "driver with javascript support"
18
+ it_should_behave_like "driver without status code support"
19
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Capybara::Driver::Selenium do
4
+ before do
5
+ @driver = Capybara::Driver::Selenium.new(TestApp)
6
+ end
7
+
8
+ it_should_behave_like "driver"
9
+ it_should_behave_like "driver with javascript support"
10
+ it_should_behave_like "driver with frame support"
11
+ it_should_behave_like "driver without status code support"
12
+ it_should_behave_like "driver with cookies support"
13
+ end
data/spec/dsl_spec.rb ADDED
@@ -0,0 +1,140 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ require 'capybara/dsl'
4
+
5
+ describe Capybara do
6
+
7
+ before do
8
+ Capybara.app = TestApp
9
+ end
10
+
11
+ after do
12
+ Capybara.default_driver = nil
13
+ Capybara.use_default_driver
14
+ end
15
+
16
+ describe '#default_driver' do
17
+ it "should default to rack_test" do
18
+ Capybara.default_driver.should == :rack_test
19
+ end
20
+
21
+ it "should be changeable" do
22
+ Capybara.default_driver = :culerity
23
+ Capybara.default_driver.should == :culerity
24
+ end
25
+ end
26
+
27
+ describe '#current_driver' do
28
+ it "should default to the default driver" do
29
+ Capybara.current_driver.should == :rack_test
30
+ Capybara.default_driver = :culerity
31
+ Capybara.current_driver.should == :culerity
32
+ end
33
+
34
+ it "should be changeable" do
35
+ Capybara.current_driver = :culerity
36
+ Capybara.current_driver.should == :culerity
37
+ end
38
+ end
39
+
40
+ describe '#javascript_driver' do
41
+ it "should default to selenium" do
42
+ Capybara.javascript_driver.should == :selenium
43
+ end
44
+
45
+ it "should be changeable" do
46
+ Capybara.javascript_driver = :culerity
47
+ Capybara.javascript_driver.should == :culerity
48
+ end
49
+ end
50
+
51
+ describe '#use_default_driver' do
52
+ it "should restore the default driver" do
53
+ Capybara.current_driver = :culerity
54
+ Capybara.use_default_driver
55
+ Capybara.current_driver.should == :rack_test
56
+ end
57
+ end
58
+
59
+ describe '#app' do
60
+ it "should be changeable" do
61
+ Capybara.app = "foobar"
62
+ Capybara.app.should == 'foobar'
63
+ end
64
+ end
65
+
66
+ describe '#current_session' do
67
+ it "should choose a session object of the current driver type" do
68
+ Capybara.current_session.should be_a(Capybara::Session)
69
+ end
70
+
71
+ it "should use #app as the application" do
72
+ Capybara.app = proc {}
73
+ Capybara.current_session.app.should == Capybara.app
74
+ end
75
+
76
+ it "should change with the current driver" do
77
+ Capybara.current_session.mode.should == :rack_test
78
+ Capybara.current_driver = :culerity
79
+ Capybara.current_session.mode.should == :culerity
80
+ end
81
+
82
+ it "should be persistent even across driver changes" do
83
+ object_id = Capybara.current_session.object_id
84
+ Capybara.current_session.object_id.should == object_id
85
+ Capybara.current_driver = :culerity
86
+ Capybara.current_session.mode.should == :culerity
87
+ Capybara.current_session.object_id.should_not == object_id
88
+
89
+ Capybara.current_driver = :rack_test
90
+ Capybara.current_session.object_id.should == object_id
91
+ end
92
+
93
+ it "should change when changing application" do
94
+ object_id = Capybara.current_session.object_id
95
+ Capybara.current_session.object_id.should == object_id
96
+ Capybara.app = proc {}
97
+ Capybara.current_session.object_id.should_not == object_id
98
+ Capybara.current_session.app.should == Capybara.app
99
+ end
100
+ end
101
+
102
+ describe '.reset_sessions!' do
103
+ it "should clear any persisted sessions" do
104
+ object_id = Capybara.current_session.object_id
105
+ Capybara.current_session.object_id.should == object_id
106
+ Capybara.reset_sessions!
107
+ Capybara.current_session.object_id.should_not == object_id
108
+ end
109
+ end
110
+
111
+ describe 'the DSL' do
112
+ before do
113
+ @session = Capybara
114
+ end
115
+
116
+ it_should_behave_like "session"
117
+ it_should_behave_like "session without javascript support"
118
+
119
+ it "should be possible to include it in another class" do
120
+ klass = Class.new do
121
+ include Capybara
122
+ end
123
+ foo = klass.new
124
+ foo.visit('/with_html')
125
+ foo.click_link('ullamco')
126
+ foo.body.should include('Another World')
127
+ end
128
+
129
+ it "should provide a 'page' shortcut for more expressive tests" do
130
+ klass = Class.new do
131
+ include Capybara
132
+ end
133
+ foo = klass.new
134
+ foo.page.visit('/with_html')
135
+ foo.page.click_link('ullamco')
136
+ foo.page.body.should include('Another World')
137
+ end
138
+ end
139
+
140
+ end
@@ -0,0 +1,83 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ require 'capybara/util/save_and_open_page'
4
+ require 'launchy'
5
+ describe Capybara do
6
+ describe ".save_save_and_open_page" do
7
+ before do
8
+ @time = Time.new.strftime("%Y%m%d%H%M%S")
9
+
10
+ @temp_file = mock("FILE")
11
+ @temp_file.stub!(:write)
12
+ @temp_file.stub!(:close)
13
+
14
+ @html = <<-HTML
15
+ <html>
16
+ <head>
17
+ </head>
18
+ <body>
19
+ <h1>test</h1>
20
+ </body>
21
+ <html>
22
+ HTML
23
+
24
+ Launchy::Browser.stub(:run)
25
+ end
26
+
27
+ describe "defaults" do
28
+ before do
29
+ @name = "capybara-#{@time}.html"
30
+
31
+ @temp_file.stub!(:path).and_return(@name)
32
+
33
+ File.should_receive(:exist?).and_return true
34
+ File.should_receive(:new).and_return @temp_file
35
+ end
36
+
37
+ it "should create a new temporary file" do
38
+ @temp_file.should_receive(:write).with @html
39
+ Capybara.save_and_open_page @html
40
+ end
41
+
42
+ it "should open the file in the browser" do
43
+ Capybara.should_receive(:open_in_browser).with(@name)
44
+ Capybara.save_and_open_page @html
45
+ end
46
+ end
47
+
48
+ describe "custom output path" do
49
+ before do
50
+ @custom_path = File.join('tmp', 'capybara')
51
+ @custom_name = File.join(@custom_path, "capybara-#{@time}.html")
52
+
53
+ @temp_file.stub!(:path).and_return(@custom_name)
54
+
55
+ Capybara.should_receive(:save_and_open_page_path).at_least(:once).and_return(@custom_path)
56
+ end
57
+
58
+ it "should create a new temporary file in the custom path" do
59
+ File.should_receive(:directory?).and_return true
60
+ File.should_receive(:exist?).and_return true
61
+ File.should_receive(:new).and_return @temp_file
62
+
63
+ @temp_file.should_receive(:write).with @html
64
+ Capybara.save_and_open_page @html
65
+ end
66
+
67
+ it "should open the file - in the custom path - in the browser" do
68
+ Capybara.should_receive(:open_in_browser).with(@custom_name)
69
+ Capybara.save_and_open_page @html
70
+ end
71
+
72
+ it "should be possible to configure output path" do
73
+ Capybara.should respond_to(:save_and_open_page_path)
74
+ default_setting = Capybara.save_and_open_page_path
75
+ lambda {
76
+ Capybara.save_and_open_page_path = File.join('tmp', 'capybara')
77
+ Capybara.save_and_open_page_path.should == File.join('tmp', 'capybara')
78
+ }.should_not raise_error
79
+ Capybara.save_and_open_page_path = default_setting
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,53 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Capybara::Server do
4
+
5
+ it "should spool up a rack server" do
6
+ @app = proc { |env| [200, {}, "Hello Server!"]}
7
+ @server = Capybara::Server.new(@app).boot
8
+
9
+ @res = Net::HTTP.start(@server.host, @server.port) { |http| http.get('/') }
10
+
11
+ @res.body.should include('Hello Server')
12
+ end
13
+
14
+ it "should do nothing when no server given" do
15
+ running do
16
+ @server = Capybara::Server.new(nil).boot
17
+ end.should_not raise_error
18
+ end
19
+
20
+ it "should find an available port" do
21
+ @app1 = proc { |env| [200, {}, "Hello Server!"]}
22
+ @app2 = proc { |env| [200, {}, "Hello Second Server!"]}
23
+
24
+ @server1 = Capybara::Server.new(@app1).boot
25
+ @server2 = Capybara::Server.new(@app2).boot
26
+
27
+ @res1 = Net::HTTP.start(@server1.host, @server1.port) { |http| http.get('/') }
28
+ @res1.body.should include('Hello Server')
29
+
30
+ @res2 = Net::HTTP.start(@server2.host, @server2.port) { |http| http.get('/') }
31
+ @res2.body.should include('Hello Second Server')
32
+ end
33
+
34
+ it "should use the server if it already running" do
35
+ @app1 = proc { |env| [200, {}, "Hello Server!"]}
36
+ @app2 = proc { |env| [200, {}, "Hello Second Server!"]}
37
+
38
+ @server1a = Capybara::Server.new(@app1).boot
39
+ @server1b = Capybara::Server.new(@app1).boot
40
+ @server2a = Capybara::Server.new(@app2).boot
41
+ @server2b = Capybara::Server.new(@app2).boot
42
+
43
+ @res1 = Net::HTTP.start(@server1b.host, @server1b.port) { |http| http.get('/') }
44
+ @res1.body.should include('Hello Server')
45
+
46
+ @res2 = Net::HTTP.start(@server2b.host, @server2b.port) { |http| http.get('/') }
47
+ @res2.body.should include('Hello Second Server')
48
+
49
+ @server1a.port.should == @server1b.port
50
+ @server2a.port.should == @server2b.port
51
+ end
52
+
53
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ if RUBY_PLATFORM =~ /java/
4
+ describe Capybara::Driver::Celerity do
5
+ before(:all) do
6
+ @session = Capybara::Session.new(:celerity, TestApp)
7
+ end
8
+
9
+ describe '#driver' do
10
+ it "should be a celerity driver" do
11
+ @session.driver.should be_an_instance_of(Capybara::Driver::Celerity)
12
+ end
13
+ end
14
+
15
+ describe '#mode' do
16
+ it "should remember the mode" do
17
+ @session.mode.should == :celerity
18
+ end
19
+ end
20
+
21
+ it_should_behave_like "session"
22
+ it_should_behave_like "session with javascript support"
23
+ it_should_behave_like "session with headers support"
24
+ it_should_behave_like "session with status code support"
25
+ end
26
+ else
27
+ puts "#{File.basename(__FILE__)} requires JRuby; skipping.."
28
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Capybara::Session do
4
+ context 'with culerity driver' do
5
+ before(:all) do
6
+ @session = Capybara::Session.new(:culerity, TestApp)
7
+ end
8
+
9
+ describe '#driver' do
10
+ it "should be a culerity driver" do
11
+ @session.driver.should be_an_instance_of(Capybara::Driver::Culerity)
12
+ end
13
+ end
14
+
15
+ describe '#mode' do
16
+ it "should remember the mode" do
17
+ @session.mode.should == :culerity
18
+ end
19
+ end
20
+
21
+ it_should_behave_like "session"
22
+ it_should_behave_like "session with javascript support"
23
+ it_should_behave_like "session with headers support"
24
+ it_should_behave_like "session with status code support"
25
+ end
26
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Capybara::Session do
4
+ context 'with rack test driver' do
5
+ before do
6
+ @session = Capybara::Session.new(:rack_test, TestApp)
7
+ end
8
+
9
+ describe '#driver' do
10
+ it "should be a rack test driver" do
11
+ @session.driver.should be_an_instance_of(Capybara::Driver::RackTest)
12
+ end
13
+ end
14
+
15
+ describe '#mode' do
16
+ it "should remember the mode" do
17
+ @session.mode.should == :rack_test
18
+ end
19
+ end
20
+
21
+ describe '#click_link' do
22
+ it "should use data-method if available" do
23
+ @session.visit "/with_html"
24
+ @session.click_link "A link with data-method"
25
+ @session.body.should == 'The requested object was deleted'
26
+ end
27
+ end
28
+
29
+ it_should_behave_like "session"
30
+ it_should_behave_like "session without javascript support"
31
+ it_should_behave_like "session with headers support"
32
+ it_should_behave_like "session with status code support"
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Capybara::Session do
4
+ context 'with selenium driver' do
5
+ before do
6
+ @session = Capybara::Session.new(:selenium, TestApp)
7
+ end
8
+
9
+ describe '#driver' do
10
+ it "should be a selenium driver" do
11
+ @session.driver.should be_an_instance_of(Capybara::Driver::Selenium)
12
+ end
13
+ end
14
+
15
+ describe '#mode' do
16
+ it "should remember the mode" do
17
+ @session.mode.should == :selenium
18
+ end
19
+ end
20
+
21
+ it_should_behave_like "session"
22
+ it_should_behave_like "session with javascript support"
23
+ it_should_behave_like "session without headers support"
24
+ it_should_behave_like "session without status code support"
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ $:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
2
+ $:.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rubygems'
5
+ require "bundler/setup"
6
+
7
+ require 'spec'
8
+ require 'spec/autorun'
9
+ require 'capybara'
10
+ require 'capybara/spec/driver'
11
+ require 'capybara/spec/session'
12
+
13
+ alias :running :lambda
14
+
15
+ Capybara.default_wait_time = 0 # less timeout so tests run faster
16
+
17
+ Spec::Runner.configure do |config|
18
+ config.before do
19
+ Capybara.configure do |config|
20
+ config.default_selector = :xpath
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ require 'capybara'
4
+ require 'capybara/util/timeout'
5
+
6
+ module Capybara
7
+
8
+ describe '.timeout' do
9
+
10
+ it "should return result of yield if it returns true value within timeout" do
11
+ Capybara.timeout { "hello" }.should == "hello"
12
+ end
13
+
14
+ it "should keep trying within timeout" do
15
+ count = 0
16
+ Capybara.timeout { count += 1; count == 5 ? count : nil }.should == 5
17
+ end
18
+
19
+ it "should raise Capybara::TimeoutError if block fails to return true within timeout" do
20
+ running do
21
+ Capybara.timeout(0.1) { false }
22
+ end.should raise_error(::Capybara::TimeoutError)
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
@@ -0,0 +1,173 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Capybara::XPath do
4
+
5
+ before do
6
+ @driver = Capybara::Driver::RackTest.new(TestApp)
7
+ @driver.visit('/form')
8
+ @xpath = Capybara::XPath.new
9
+ end
10
+
11
+ it "should proxy any class method calls to a new instance" do
12
+ @query = Capybara::XPath.fillable_field('First Name').to_s
13
+ @driver.find(@query).first.value.should == 'John'
14
+ end
15
+
16
+ it "should respond to instance methods at the class level" do
17
+ Capybara::XPath.should respond_to(:fillable_field)
18
+ end
19
+
20
+ describe '.wrap' do
21
+ it "should return an XPath unmodified" do
22
+ Capybara::XPath.wrap(@xpath).should == @xpath
23
+ end
24
+
25
+ it "should wrap a string in an xpath object" do
26
+ @xpath = Capybara::XPath.wrap('//foo/bar')
27
+ @xpath.should be_an_instance_of(Capybara::XPath)
28
+ @xpath.paths.should == ['//foo/bar']
29
+ end
30
+ end
31
+
32
+ describe '#append' do
33
+ it "should append an XPath's paths" do
34
+ @xpath = Capybara::XPath.wrap('//test')
35
+ @xpath = @xpath.append(Capybara::XPath.wrap('//foo/bar'))
36
+ @xpath.paths.should == ['//test', '//foo/bar']
37
+ end
38
+
39
+ it "should append an String as a new path" do
40
+ @xpath = Capybara::XPath.wrap('//test')
41
+ @xpath = @xpath.append('//foo/bar')
42
+ @xpath.paths.should == ['//test', '//foo/bar']
43
+ end
44
+ end
45
+
46
+ describe '#prepend' do
47
+ it "should prepend an XPath's paths" do
48
+ @xpath = Capybara::XPath.wrap('//test')
49
+ @xpath = @xpath.prepend(Capybara::XPath.wrap('//foo/bar'))
50
+ @xpath.paths.should == ['//foo/bar', '//test']
51
+ end
52
+
53
+ it "should prepend an String as a new path" do
54
+ @xpath = Capybara::XPath.wrap('//test')
55
+ @xpath = @xpath.prepend('//foo/bar')
56
+ @xpath.paths.should == ['//foo/bar', '//test']
57
+ end
58
+ end
59
+
60
+ describe '#field' do
61
+ it "should find any field by id or label" do
62
+ @query = @xpath.field('First Name').to_s
63
+ @driver.find(@query).first.value.should == 'John'
64
+ @query = @xpath.field('Password').to_s
65
+ @driver.find(@query).first.value.should == 'seeekrit'
66
+ @query = @xpath.field('Description').to_s
67
+ @driver.find(@query).first.text.should == 'Descriptive text goes here'
68
+ @query = @xpath.field('Document').to_s
69
+ @driver.find(@query).first[:name].should == 'form[document]'
70
+ @query = @xpath.field('Cat').to_s
71
+ @driver.find(@query).first.value.should == 'cat'
72
+ @query = @xpath.field('Male').to_s
73
+ @driver.find(@query).first.value.should == 'male'
74
+ @query = @xpath.field('Region').to_s
75
+ @driver.find(@query).first[:name].should == 'form[region]'
76
+ end
77
+
78
+ it "should be chainable" do
79
+ @query = @xpath.field('First Name').button('Click me!').to_s
80
+ @driver.find(@query).first.value.should == 'John'
81
+ end
82
+ end
83
+
84
+ describe '#fillable_field' do
85
+ it "should find a text field, password field, or text area by id or label" do
86
+ @query = @xpath.fillable_field('First Name').to_s
87
+ @driver.find(@query).first.value.should == 'John'
88
+ @query = @xpath.fillable_field('Password').to_s
89
+ @driver.find(@query).first.value.should == 'seeekrit'
90
+ @query = @xpath.fillable_field('Description').to_s
91
+ @driver.find(@query).first.text.should == 'Descriptive text goes here'
92
+ end
93
+
94
+ it "should be chainable" do
95
+ @query = @xpath.fillable_field('First Name').button('Click me!').to_s
96
+ @driver.find(@query).first.value.should == 'John'
97
+ end
98
+ end
99
+
100
+ describe '#text_area' do
101
+ it "should find a text area by id or label" do
102
+ @query = @xpath.text_area('form_description').to_s
103
+ @driver.find(@query).first.text.should == 'Descriptive text goes here'
104
+ @query = @xpath.text_area('Description').to_s
105
+ @driver.find(@query).first.text.should == 'Descriptive text goes here'
106
+ end
107
+
108
+ it "should be chainable" do
109
+ @query = @xpath.text_area('Description').button('Click me!').to_s
110
+ @driver.find(@query).first.text.should == 'Descriptive text goes here'
111
+ end
112
+ end
113
+
114
+ describe '#button' do
115
+ it "should find a button by id or content" do
116
+ @query = @xpath.button('awe123').to_s
117
+ @driver.find(@query).first.value.should == 'awesome'
118
+ @query = @xpath.button('okay556').to_s
119
+ @driver.find(@query).first.value.should == 'okay'
120
+ @query = @xpath.button('click_me_123').to_s
121
+ @driver.find(@query).first.value.should == 'click_me'
122
+ @query = @xpath.button('Click me!').to_s
123
+ @driver.find(@query).first.value.should == 'click_me'
124
+ @query = @xpath.button('fresh_btn').to_s
125
+ @driver.find(@query).first.value.should == 'i am fresh'
126
+ @query = @xpath.button('i am fresh').to_s
127
+ @driver.find(@query).first[:name].should == 'form[fresh]'
128
+ end
129
+ end
130
+
131
+ describe '#radio_button' do
132
+ it "should find a radio button by id or label" do
133
+ @query = @xpath.radio_button('Male').to_s
134
+ @driver.find(@query).first.value.should == 'male'
135
+ @query = @xpath.radio_button('gender_male').to_s
136
+ @driver.find(@query).first.value.should == 'male'
137
+ end
138
+
139
+ it "should be chainable" do
140
+ @query = @xpath.radio_button('Male').button('Click me!').to_s
141
+ @driver.find(@query).first.value.should == 'male'
142
+ end
143
+ end
144
+
145
+ describe '#checkbox' do
146
+ it "should find a checkbox by id or label" do
147
+ @query = @xpath.checkbox('Cat').to_s
148
+ @driver.find(@query).first.value.should == 'cat'
149
+ @query = @xpath.checkbox('form_pets_cat').to_s
150
+ @driver.find(@query).first.value.should == 'cat'
151
+ end
152
+
153
+ it "should be chainable" do
154
+ @query = @xpath.checkbox('Cat').button('Click me!').to_s
155
+ @driver.find(@query).first.value.should == 'cat'
156
+ end
157
+ end
158
+
159
+ describe '#select' do
160
+ it "should find a select by id or label" do
161
+ @query = @xpath.select('Region').to_s
162
+ @driver.find(@query).first[:name].should == 'form[region]'
163
+ @query = @xpath.select('form_region').to_s
164
+ @driver.find(@query).first[:name].should == 'form[region]'
165
+ end
166
+
167
+ it "should be chainable" do
168
+ @query = @xpath.select('Region').button('Click me!').to_s
169
+ @driver.find(@query).first[:name].should == 'form[region]'
170
+ end
171
+ end
172
+
173
+ end