pr0d1r2-capybara 0.3.7

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 (87) hide show
  1. data/History.txt +71 -0
  2. data/README.rdoc +388 -0
  3. data/lib/capybara.rb +57 -0
  4. data/lib/capybara/cucumber.rb +32 -0
  5. data/lib/capybara/driver/base.rb +48 -0
  6. data/lib/capybara/driver/celerity_driver.rb +143 -0
  7. data/lib/capybara/driver/culerity_driver.rb +25 -0
  8. data/lib/capybara/driver/rack_test_driver.rb +271 -0
  9. data/lib/capybara/driver/selenium_driver.rb +161 -0
  10. data/lib/capybara/dsl.rb +60 -0
  11. data/lib/capybara/node.rb +60 -0
  12. data/lib/capybara/rails.rb +17 -0
  13. data/lib/capybara/save_and_open_page.rb +33 -0
  14. data/lib/capybara/searchable.rb +54 -0
  15. data/lib/capybara/server.rb +114 -0
  16. data/lib/capybara/session.rb +262 -0
  17. data/lib/capybara/spec/driver.rb +162 -0
  18. data/lib/capybara/spec/fixtures/capybara.jpg +0 -0
  19. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  20. data/lib/capybara/spec/public/jquery-ui.js +35 -0
  21. data/lib/capybara/spec/public/jquery.js +19 -0
  22. data/lib/capybara/spec/public/test.js +33 -0
  23. data/lib/capybara/spec/session.rb +81 -0
  24. data/lib/capybara/spec/session/all_spec.rb +69 -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 +236 -0
  29. data/lib/capybara/spec/session/click_link_spec.rb +108 -0
  30. data/lib/capybara/spec/session/click_spec.rb +24 -0
  31. data/lib/capybara/spec/session/current_url_spec.rb +8 -0
  32. data/lib/capybara/spec/session/fill_in_spec.rb +108 -0
  33. data/lib/capybara/spec/session/find_button_spec.rb +16 -0
  34. data/lib/capybara/spec/session/find_by_id_spec.rb +16 -0
  35. data/lib/capybara/spec/session/find_field_spec.rb +22 -0
  36. data/lib/capybara/spec/session/find_link_spec.rb +17 -0
  37. data/lib/capybara/spec/session/find_spec.rb +57 -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 +204 -0
  48. data/lib/capybara/spec/session/locate_spec.rb +59 -0
  49. data/lib/capybara/spec/session/select_spec.rb +77 -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/test_app.rb +75 -0
  54. data/lib/capybara/spec/views/buttons.erb +4 -0
  55. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  56. data/lib/capybara/spec/views/form.erb +234 -0
  57. data/lib/capybara/spec/views/frame_one.erb +8 -0
  58. data/lib/capybara/spec/views/frame_two.erb +8 -0
  59. data/lib/capybara/spec/views/postback.erb +13 -0
  60. data/lib/capybara/spec/views/tables.erb +122 -0
  61. data/lib/capybara/spec/views/with_html.erb +42 -0
  62. data/lib/capybara/spec/views/with_js.erb +39 -0
  63. data/lib/capybara/spec/views/with_scope.erb +36 -0
  64. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  65. data/lib/capybara/spec/views/within_frames.erb +10 -0
  66. data/lib/capybara/version.rb +3 -0
  67. data/lib/capybara/wait_until.rb +28 -0
  68. data/lib/capybara/xpath.rb +179 -0
  69. data/spec/capybara_spec.rb +18 -0
  70. data/spec/driver/celerity_driver_spec.rb +16 -0
  71. data/spec/driver/culerity_driver_spec.rb +12 -0
  72. data/spec/driver/rack_test_driver_spec.rb +11 -0
  73. data/spec/driver/remote_culerity_driver_spec.rb +23 -0
  74. data/spec/driver/remote_selenium_driver_spec.rb +18 -0
  75. data/spec/driver/selenium_driver_spec.rb +11 -0
  76. data/spec/dsl_spec.rb +140 -0
  77. data/spec/save_and_open_page_spec.rb +43 -0
  78. data/spec/searchable_spec.rb +66 -0
  79. data/spec/server_spec.rb +53 -0
  80. data/spec/session/celerity_session_spec.rb +27 -0
  81. data/spec/session/culerity_session_spec.rb +25 -0
  82. data/spec/session/rack_test_session_spec.rb +33 -0
  83. data/spec/session/selenium_session_spec.rb +25 -0
  84. data/spec/spec_helper.rb +19 -0
  85. data/spec/wait_until_spec.rb +28 -0
  86. data/spec/xpath_spec.rb +180 -0
  87. metadata +259 -0
@@ -0,0 +1,11 @@
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
+ end
@@ -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,43 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ require 'capybara/save_and_open_page'
4
+ require 'launchy'
5
+ describe Capybara::SaveAndOpenPage do
6
+ describe "#save_save_and_open_page" do
7
+ before do
8
+
9
+ @time = Time.new.strftime("%Y%m%d%H%M%S")
10
+ @name = "capybara-#{@time}.html"
11
+
12
+ @temp_file = mock("FILE")
13
+ @temp_file.stub!(:write)
14
+ @temp_file.stub!(:close)
15
+ @temp_file.stub!(:path).and_return(@name)
16
+
17
+ File.should_receive(:exist?).and_return true
18
+ File.should_receive(:new).and_return @temp_file
19
+
20
+ @html = <<-HTML
21
+ <html>
22
+ <head>
23
+ </head>
24
+ <body>
25
+ <h1>test</h1>
26
+ </body>
27
+ <html>
28
+ HTML
29
+
30
+ Launchy::Browser.stub(:run)
31
+ end
32
+
33
+ it "should create a new temporary file" do
34
+ @temp_file.should_receive(:write).with @html
35
+ Capybara::SaveAndOpenPage.save_and_open_page @html
36
+ end
37
+
38
+ it "should open the file in the browser" do
39
+ Capybara::SaveAndOpenPage.should_receive(:open_in_browser).with(@name)
40
+ Capybara::SaveAndOpenPage.save_and_open_page @html
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,66 @@
1
+ require File.expand_path('spec_helper', File.dirname(__FILE__))
2
+
3
+ module Capybara
4
+
5
+ describe Searchable do
6
+ class Klass
7
+ include Searchable
8
+
9
+ def all_unfiltered(locator, options = {})
10
+ []
11
+ end
12
+
13
+ end
14
+
15
+ describe "#all" do
16
+ before do
17
+ @searchable = Klass.new
18
+ end
19
+
20
+ it "should return unfiltered list without options" do
21
+ node1 = stub(Node)
22
+ node2 = stub(Node)
23
+ @searchable.should_receive(:all_unfiltered).with('//x').and_return([node1, node2])
24
+ @searchable.all('//x').should == [node1, node2]
25
+ end
26
+
27
+ context "with :text filter" do
28
+ before do
29
+ @node1 = stub(Node, :text => 'node one text (with parens)')
30
+ @node2 = stub(Node, :text => 'node two text [-]')
31
+ @searchable.stub(:all_unfiltered).and_return([@node1, @node2])
32
+ end
33
+
34
+ it "should accept regular expression" do
35
+ @searchable.all('//x', :text => /node one/).should == [@node1]
36
+ @searchable.all('//x', :text => /node two/).should == [@node2]
37
+ end
38
+
39
+ it "should accept text" do
40
+ @searchable.all('//x', :text => "node one").should == [@node1]
41
+ @searchable.all('//x', :text => "node two").should == [@node2]
42
+ end
43
+
44
+ it "should allow Regexp reserved words in text" do
45
+ @searchable.all('//x', :text => "node one text (with parens)").should == [@node1]
46
+ @searchable.all('//x', :text => "node two text [-]").should == [@node2]
47
+ end
48
+ end
49
+
50
+ context "with :visible filter" do
51
+ before do
52
+ @visible_node = stub(Node, :visible? => true)
53
+ @hidden_node = stub(Node, :visible? => false)
54
+ @searchable.stub(:all_unfiltered).and_return([@visible_node, @hidden_node])
55
+ end
56
+
57
+ it "should filter out hidden nodes" do
58
+ @searchable.all('//x', :visible => true).should == [@visible_node]
59
+ end
60
+
61
+ end
62
+
63
+ end #all
64
+ end
65
+
66
+ 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,27 @@
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 rack test 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
+ end
25
+ else
26
+ puts "#{File.basename(__FILE__)} requires JRuby; skipping.."
27
+ end
@@ -0,0 +1,25 @@
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 rack test 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
+ end
25
+ end
@@ -0,0 +1,33 @@
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
+ end
33
+ end
@@ -0,0 +1,25 @@
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
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ $:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
2
+ $:.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rubygems'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+ require 'capybara'
8
+ require 'capybara/spec/driver'
9
+ require 'capybara/spec/session'
10
+
11
+ alias :running :lambda
12
+
13
+ Capybara.default_wait_time = 0 # less timeout so tests run faster
14
+
15
+ Spec::Runner.configure do |config|
16
+ config.after do
17
+ Capybara.default_selector = :xpath
18
+ end
19
+ end