capybara 1.1.4 → 2.0.0.beta2
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.
- data/History.txt +100 -0
- data/License.txt +22 -0
- data/README.md +829 -0
- data/lib/capybara.rb +124 -6
- data/lib/capybara/cucumber.rb +2 -5
- data/lib/capybara/driver/base.rb +5 -5
- data/lib/capybara/driver/node.rb +2 -2
- data/lib/capybara/dsl.rb +3 -121
- data/lib/capybara/node/actions.rb +12 -28
- data/lib/capybara/node/base.rb +5 -13
- data/lib/capybara/node/element.rb +21 -21
- data/lib/capybara/node/finders.rb +27 -89
- data/lib/capybara/node/matchers.rb +107 -69
- data/lib/capybara/node/simple.rb +11 -13
- data/lib/capybara/query.rb +78 -0
- data/lib/capybara/rack_test/browser.rb +16 -27
- data/lib/capybara/rack_test/driver.rb +11 -1
- data/lib/capybara/rack_test/node.rb +17 -1
- data/lib/capybara/result.rb +84 -0
- data/lib/capybara/rspec/matchers.rb +28 -63
- data/lib/capybara/selector.rb +97 -33
- data/lib/capybara/selenium/driver.rb +14 -61
- data/lib/capybara/selenium/node.rb +6 -15
- data/lib/capybara/server.rb +32 -27
- data/lib/capybara/session.rb +54 -30
- data/lib/capybara/spec/public/jquery-ui.js +791 -0
- data/lib/capybara/spec/public/jquery.js +9046 -0
- data/lib/capybara/spec/public/test.js +4 -1
- data/lib/capybara/spec/session.rb +56 -27
- data/lib/capybara/spec/session/all_spec.rb +8 -4
- data/lib/capybara/spec/session/attach_file_spec.rb +12 -9
- data/lib/capybara/spec/session/check_spec.rb +6 -3
- data/lib/capybara/spec/session/choose_spec.rb +4 -1
- data/lib/capybara/spec/session/click_button_spec.rb +5 -14
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +2 -1
- data/lib/capybara/spec/session/click_link_spec.rb +3 -17
- data/lib/capybara/spec/session/current_url_spec.rb +77 -9
- data/lib/capybara/spec/session/fill_in_spec.rb +8 -18
- data/lib/capybara/spec/session/find_spec.rb +19 -46
- data/lib/capybara/spec/session/first_spec.rb +2 -34
- data/lib/capybara/spec/session/has_css_spec.rb +1 -1
- data/lib/capybara/spec/session/has_field_spec.rb +28 -0
- data/lib/capybara/spec/session/has_select_spec.rb +84 -31
- data/lib/capybara/spec/session/has_table_spec.rb +7 -69
- data/lib/capybara/spec/session/has_text_spec.rb +168 -0
- data/lib/capybara/spec/session/javascript.rb +65 -81
- data/lib/capybara/spec/session/node_spec.rb +115 -0
- data/lib/capybara/spec/session/screenshot.rb +29 -0
- data/lib/capybara/spec/session/select_spec.rb +12 -12
- data/lib/capybara/spec/session/text_spec.rb +9 -4
- data/lib/capybara/spec/session/unselect_spec.rb +12 -6
- data/lib/capybara/spec/session/visit_spec.rb +76 -0
- data/lib/capybara/spec/session/within_frame_spec.rb +33 -0
- data/lib/capybara/spec/session/within_spec.rb +47 -58
- data/lib/capybara/spec/session/within_window_spec.rb +40 -0
- data/lib/capybara/spec/test_app.rb +27 -3
- data/lib/capybara/spec/views/form.erb +11 -10
- data/lib/capybara/spec/views/host_links.erb +2 -2
- data/lib/capybara/spec/views/tables.erb +6 -66
- data/lib/capybara/spec/views/with_html.erb +3 -3
- data/lib/capybara/spec/views/with_js.erb +11 -8
- data/lib/capybara/util/save_and_open_page.rb +4 -3
- data/lib/capybara/version.rb +1 -1
- data/spec/basic_node_spec.rb +15 -3
- data/spec/dsl_spec.rb +12 -10
- data/spec/rack_test_spec.rb +152 -0
- data/spec/rspec/features_spec.rb +0 -2
- data/spec/rspec/matchers_spec.rb +164 -89
- data/spec/rspec_spec.rb +0 -2
- data/spec/selenium_spec.rb +67 -0
- data/spec/server_spec.rb +35 -23
- data/spec/spec_helper.rb +18 -2
- metadata +30 -30
- data/README.rdoc +0 -722
- data/lib/capybara/spec/driver.rb +0 -301
- data/lib/capybara/spec/session/current_host_spec.rb +0 -68
- data/lib/capybara/spec/session/has_content_spec.rb +0 -106
- data/lib/capybara/util/timeout.rb +0 -27
- data/spec/driver/rack_test_driver_spec.rb +0 -89
- data/spec/driver/selenium_driver_spec.rb +0 -37
- data/spec/session/rack_test_session_spec.rb +0 -55
- data/spec/session/selenium_session_spec.rb +0 -26
- data/spec/string_spec.rb +0 -77
- data/spec/timeout_spec.rb +0 -28
@@ -1,27 +0,0 @@
|
|
1
|
-
module Capybara
|
2
|
-
class << self
|
3
|
-
|
4
|
-
##
|
5
|
-
# Provides timeout similar to standard library Timeout, but avoids threads
|
6
|
-
#
|
7
|
-
def timeout(seconds = 1, driver = nil, error_message = nil, &block)
|
8
|
-
start_time = Time.now
|
9
|
-
|
10
|
-
result = nil
|
11
|
-
|
12
|
-
until result
|
13
|
-
return result if result = yield
|
14
|
-
|
15
|
-
delay = seconds - (Time.now - start_time)
|
16
|
-
if delay <= 0
|
17
|
-
raise TimeoutError, error_message || "timed out"
|
18
|
-
end
|
19
|
-
|
20
|
-
driver && driver.wait_until(delay)
|
21
|
-
|
22
|
-
sleep(0.05)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'stringio'
|
4
|
-
|
5
|
-
def capture(*streams)
|
6
|
-
streams.map! { |stream| stream.to_s }
|
7
|
-
begin
|
8
|
-
result = StringIO.new
|
9
|
-
streams.each { |stream| eval "$#{stream} = result" }
|
10
|
-
yield
|
11
|
-
ensure
|
12
|
-
streams.each { |stream| eval("$#{stream} = #{stream.upcase}") }
|
13
|
-
end
|
14
|
-
result.string
|
15
|
-
end
|
16
|
-
|
17
|
-
describe Capybara::RackTest::Driver do
|
18
|
-
before do
|
19
|
-
@driver = TestSessions::RackTest.driver
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should throw an error when no rack app is given" do
|
23
|
-
running do
|
24
|
-
Capybara::RackTest::Driver.new(nil)
|
25
|
-
end.should raise_error(ArgumentError)
|
26
|
-
end
|
27
|
-
|
28
|
-
it_should_behave_like "driver"
|
29
|
-
it_should_behave_like "driver with header support"
|
30
|
-
it_should_behave_like "driver with status code support"
|
31
|
-
it_should_behave_like "driver with cookies support"
|
32
|
-
it_should_behave_like "driver with infinite redirect detection"
|
33
|
-
|
34
|
-
describe '#reset!' do
|
35
|
-
it { @driver.visit('/foo'); lambda { @driver.reset! }.should change(@driver, :current_url).to('') }
|
36
|
-
|
37
|
-
it 'should reset headers' do
|
38
|
-
@driver.header('FOO', 'BAR')
|
39
|
-
@driver.visit('/get_header')
|
40
|
-
@driver.body.should include('BAR')
|
41
|
-
|
42
|
-
@driver.reset!
|
43
|
-
@driver.visit('/get_header')
|
44
|
-
@driver.body.should_not include('BAR')
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'should reset response' do
|
48
|
-
@driver.visit('/foo')
|
49
|
-
lambda { @driver.response }.should_not raise_error
|
50
|
-
@driver.reset!
|
51
|
-
lambda { @driver.response }.should raise_error
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'should request response' do
|
55
|
-
@driver.visit('/foo')
|
56
|
-
lambda { @driver.request }.should_not raise_error
|
57
|
-
@driver.reset!
|
58
|
-
lambda { @driver.request }.should raise_error
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe ':headers option' do
|
63
|
-
it 'should always set headers' do
|
64
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
65
|
-
@driver.visit('/get_header')
|
66
|
-
@driver.body.should include('foobar')
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'should keep headers on link clicks' do
|
70
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
71
|
-
@driver.visit('/header_links')
|
72
|
-
@driver.find('.//a').first.click
|
73
|
-
@driver.body.should include('foobar')
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'should keep headers on form submit' do
|
77
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
78
|
-
@driver.visit('/header_links')
|
79
|
-
@driver.find('.//input').first.click
|
80
|
-
@driver.body.should include('foobar')
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should keep headers on redirects' do
|
84
|
-
@driver = Capybara::RackTest::Driver.new(TestApp, :headers => {'HTTP_FOO' => 'foobar'})
|
85
|
-
@driver.visit('/get_header_via_redirect')
|
86
|
-
@driver.body.should include('foobar')
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'rbconfig'
|
3
|
-
|
4
|
-
describe Capybara::Selenium::Driver do
|
5
|
-
before do
|
6
|
-
@driver = TestSessions::Selenium.driver
|
7
|
-
end
|
8
|
-
|
9
|
-
it_should_behave_like "driver"
|
10
|
-
it_should_behave_like "driver with javascript support"
|
11
|
-
it_should_behave_like "driver with resynchronization support"
|
12
|
-
it_should_behave_like "driver with frame support"
|
13
|
-
it_should_behave_like "driver with support for window switching"
|
14
|
-
it_should_behave_like "driver without status code support"
|
15
|
-
it_should_behave_like "driver with cookies support"
|
16
|
-
|
17
|
-
describe "exit codes" do
|
18
|
-
before do
|
19
|
-
@current_dir = Dir.getwd
|
20
|
-
Dir.chdir(File.join(File.dirname(__FILE__), '..', '..'))
|
21
|
-
end
|
22
|
-
|
23
|
-
after do
|
24
|
-
Dir.chdir(@current_dir)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should have return code 1 when running selenium_driver_rspec_failure.rb" do
|
28
|
-
`rspec spec/fixtures/selenium_driver_rspec_failure.rb`
|
29
|
-
$?.exitstatus.should be 1
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should have return code 0 when running selenium_driver_rspec_success.rb" do
|
33
|
-
`rspec spec/fixtures/selenium_driver_rspec_success.rb`
|
34
|
-
$?.exitstatus.should be 0
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Capybara::Session do
|
4
|
-
context 'with rack test driver' do
|
5
|
-
before do
|
6
|
-
@session = TestSessions::RackTest
|
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::RackTest::Driver)
|
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 include('The requested object was deleted')
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should not use data-method if option is false" do
|
29
|
-
@session.driver.options[:respect_data_method] = false
|
30
|
-
@session.visit "/with_html"
|
31
|
-
@session.click_link "A link with data-method"
|
32
|
-
@session.body.should include('Not deleted')
|
33
|
-
end
|
34
|
-
|
35
|
-
after do
|
36
|
-
@session.driver.options[:respect_data_method] = true
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "#attach_file" do
|
41
|
-
context "with multipart form" do
|
42
|
-
it "should submit an empty form-data section if no file is submitted" do
|
43
|
-
@session.visit("/form")
|
44
|
-
@session.click_button("Upload Empty")
|
45
|
-
@session.body.should include('Successfully ignored empty file field.')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
it_should_behave_like "session"
|
51
|
-
it_should_behave_like "session without javascript support"
|
52
|
-
it_should_behave_like "session with headers support"
|
53
|
-
it_should_behave_like "session with status code support"
|
54
|
-
end
|
55
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Capybara::Session do
|
4
|
-
context 'with selenium driver' do
|
5
|
-
before do
|
6
|
-
@session = TestSessions::Selenium
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#driver' do
|
10
|
-
it "should be a selenium driver" do
|
11
|
-
@session.driver.should be_an_instance_of(Capybara::Selenium::Driver)
|
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
|
data/spec/string_spec.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Capybara do
|
4
|
-
describe '.string' do
|
5
|
-
let :string do
|
6
|
-
Capybara.string <<-STRING
|
7
|
-
<div id="page">
|
8
|
-
<div id="content">
|
9
|
-
<h1 data="fantastic">Awesome</h1>
|
10
|
-
<p>Yes it is</p>
|
11
|
-
</div>
|
12
|
-
|
13
|
-
<div id="footer" style="display: none">
|
14
|
-
<p>c2010</p>
|
15
|
-
<p>Jonas Nicklas</p>
|
16
|
-
<input type="text" name="foo" value="bar"/>
|
17
|
-
<select name="animal">
|
18
|
-
<option>Monkey</option>
|
19
|
-
<option selected="selected">Capybara</option>
|
20
|
-
</select>
|
21
|
-
</div>
|
22
|
-
</div>
|
23
|
-
STRING
|
24
|
-
end
|
25
|
-
|
26
|
-
it "allows using matchers" do
|
27
|
-
string.should have_css('#page')
|
28
|
-
string.should_not have_css('#does-not-exist')
|
29
|
-
end
|
30
|
-
|
31
|
-
it "allows using custom matchers" do
|
32
|
-
Capybara.add_selector :lifeform do
|
33
|
-
xpath { |name| "//option[contains(.,'#{name}')]" }
|
34
|
-
end
|
35
|
-
string.should have_selector(:page)
|
36
|
-
string.should_not have_selector(:'does-not-exist')
|
37
|
-
string.should have_selector(:lifeform, "Monkey")
|
38
|
-
string.should_not have_selector(:lifeform, "Gorilla")
|
39
|
-
end
|
40
|
-
|
41
|
-
it "allows using matchers with text option" do
|
42
|
-
string.should have_css('h1', :text => 'Awesome')
|
43
|
-
string.should_not have_css('h1', :text => 'Not so awesome')
|
44
|
-
end
|
45
|
-
|
46
|
-
it "allows finding only visible nodes" do
|
47
|
-
string.all('//p', :text => 'c2010', :visible => true).should be_empty
|
48
|
-
string.all('//p', :text => 'c2010', :visible => false).should have(1).element
|
49
|
-
end
|
50
|
-
|
51
|
-
it "allows finding elements and extracting text from them" do
|
52
|
-
string.find('//h1').text.should == 'Awesome'
|
53
|
-
end
|
54
|
-
|
55
|
-
it "allows finding elements and extracting attributes from them" do
|
56
|
-
string.find('//h1')[:data].should == 'fantastic'
|
57
|
-
end
|
58
|
-
|
59
|
-
it "allows finding elements and extracting the tag name from them" do
|
60
|
-
string.find('//h1').tag_name.should == 'h1'
|
61
|
-
end
|
62
|
-
|
63
|
-
it "allows finding elements and extracting the path" do
|
64
|
-
string.find('//h1').path.should == '/html/body/div/div[1]/h1'
|
65
|
-
end
|
66
|
-
|
67
|
-
it "allows finding elements and extracting the value" do
|
68
|
-
string.find('//input').value.should == 'bar'
|
69
|
-
string.find('//select').value.should == 'Capybara'
|
70
|
-
end
|
71
|
-
|
72
|
-
it "allows finding elements and checking if they are visible" do
|
73
|
-
string.find('//h1').should be_visible
|
74
|
-
string.find('//input').should_not be_visible
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
data/spec/timeout_spec.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
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
|
-
|