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.
- data/History.txt +4 -0
- data/Manifest.txt +87 -0
- data/README.rdoc +404 -0
- data/Rakefile +29 -0
- data/config.ru +6 -0
- data/lib/capybara.rb +53 -0
- data/lib/capybara/cucumber.rb +32 -0
- data/lib/capybara/driver/base.rb +37 -0
- data/lib/capybara/driver/celerity_driver.rb +135 -0
- data/lib/capybara/driver/culerity_driver.rb +25 -0
- data/lib/capybara/driver/rack_test_driver.rb +244 -0
- data/lib/capybara/driver/selenium_driver.rb +137 -0
- data/lib/capybara/dsl.rb +60 -0
- data/lib/capybara/node.rb +69 -0
- data/lib/capybara/rails.rb +11 -0
- data/lib/capybara/save_and_open_page.rb +33 -0
- data/lib/capybara/searchable.rb +53 -0
- data/lib/capybara/server.rb +111 -0
- data/lib/capybara/session.rb +274 -0
- data/lib/capybara/wait_until.rb +23 -0
- data/lib/capybara/xpath.rb +176 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/capybara_spec.rb +18 -0
- data/spec/driver/celerity_driver_spec.rb +17 -0
- data/spec/driver/culerity_driver_spec.rb +13 -0
- data/spec/driver/rack_test_driver_spec.rb +12 -0
- data/spec/driver/remote_culerity_driver_spec.rb +26 -0
- data/spec/driver/remote_selenium_driver_spec.rb +18 -0
- data/spec/driver/selenium_driver_spec.rb +12 -0
- data/spec/drivers_spec.rb +139 -0
- data/spec/dsl/all_spec.rb +69 -0
- data/spec/dsl/attach_file_spec.rb +64 -0
- data/spec/dsl/check_spec.rb +39 -0
- data/spec/dsl/choose_spec.rb +26 -0
- data/spec/dsl/click_button_spec.rb +218 -0
- data/spec/dsl/click_link_spec.rb +108 -0
- data/spec/dsl/click_spec.rb +24 -0
- data/spec/dsl/current_url_spec.rb +8 -0
- data/spec/dsl/fill_in_spec.rb +91 -0
- data/spec/dsl/find_button_spec.rb +16 -0
- data/spec/dsl/find_by_id_spec.rb +16 -0
- data/spec/dsl/find_field_spec.rb +22 -0
- data/spec/dsl/find_link_spec.rb +17 -0
- data/spec/dsl/find_spec.rb +57 -0
- data/spec/dsl/has_button_spec.rb +32 -0
- data/spec/dsl/has_content_spec.rb +101 -0
- data/spec/dsl/has_css_spec.rb +107 -0
- data/spec/dsl/has_field_spec.rb +96 -0
- data/spec/dsl/has_link_spec.rb +33 -0
- data/spec/dsl/has_xpath_spec.rb +123 -0
- data/spec/dsl/locate_spec.rb +59 -0
- data/spec/dsl/select_spec.rb +71 -0
- data/spec/dsl/uncheck_spec.rb +21 -0
- data/spec/dsl/within_spec.rb +153 -0
- data/spec/dsl_spec.rb +140 -0
- data/spec/fixtures/capybara.jpg +0 -0
- data/spec/fixtures/test_file.txt +1 -0
- data/spec/public/jquery-ui.js +35 -0
- data/spec/public/jquery.js +19 -0
- data/spec/public/test.js +30 -0
- data/spec/save_and_open_page_spec.rb +43 -0
- data/spec/searchable_spec.rb +61 -0
- data/spec/server_spec.rb +47 -0
- data/spec/session/celerity_session_spec.rb +27 -0
- data/spec/session/culerity_session_spec.rb +25 -0
- data/spec/session/rack_test_session_spec.rb +25 -0
- data/spec/session/selenium_session_spec.rb +25 -0
- data/spec/session_spec.rb +77 -0
- data/spec/session_with_headers_support_spec.rb +13 -0
- data/spec/session_with_javascript_support_spec.rb +182 -0
- data/spec/session_without_headers_support_spec.rb +15 -0
- data/spec/session_without_javascript_support_spec.rb +15 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/test_app.rb +71 -0
- data/spec/views/buttons.erb +4 -0
- data/spec/views/fieldsets.erb +29 -0
- data/spec/views/form.erb +226 -0
- data/spec/views/postback.erb +13 -0
- data/spec/views/tables.erb +122 -0
- data/spec/views/with_html.erb +38 -0
- data/spec/views/with_js.erb +34 -0
- data/spec/views/with_scope.erb +36 -0
- data/spec/views/with_simple_html.erb +1 -0
- data/spec/wait_until_spec.rb +28 -0
- data/spec/xpath_spec.rb +271 -0
- metadata +239 -0
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/capybara.rb'}"
|
9
|
+
puts "Loading capybara gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'capybara'
|
4
|
+
|
5
|
+
describe Capybara do
|
6
|
+
|
7
|
+
describe 'default_wait_time' do
|
8
|
+
after do
|
9
|
+
Capybara.default_wait_time = 2
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be changeable" do
|
13
|
+
Capybara.default_wait_time = 5
|
14
|
+
Capybara.default_wait_time.should == 5
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
if RUBY_PLATFORM =~ /java/
|
4
|
+
describe Capybara::Driver::Celerity do
|
5
|
+
before do
|
6
|
+
@driver = Capybara::Driver::Celerity.new(TestApp)
|
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 header support"
|
12
|
+
it_should_behave_like "driver with node path support"
|
13
|
+
|
14
|
+
end
|
15
|
+
else
|
16
|
+
puts "#{File.basename(__FILE__)} requires JRuby; skipping.."
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Capybara::Driver::Culerity do
|
4
|
+
before do
|
5
|
+
@driver = Capybara::Driver::Culerity.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 header support"
|
11
|
+
it_should_behave_like "driver with node path support"
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Capybara::Driver::RackTest do
|
4
|
+
before do
|
5
|
+
@driver = Capybara::Driver::RackTest.new(TestApp)
|
6
|
+
end
|
7
|
+
|
8
|
+
it_should_behave_like "driver"
|
9
|
+
it_should_behave_like "driver with header support"
|
10
|
+
it_should_behave_like "driver with node path support"
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Capybara::Driver::Culerity do
|
4
|
+
before do
|
5
|
+
@driver = Capybara::Driver::Culerity.new(TestApp)
|
6
|
+
end
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
Capybara.app_host = "http://capybara-testapp.heroku.com"
|
10
|
+
Capybara.run_server = false
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:all) do
|
14
|
+
Capybara.app_host = nil
|
15
|
+
Capybara.run_server = true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should navigate to a fully qualified remote page" do
|
19
|
+
@driver.visit('http://elabs.se/contact')
|
20
|
+
@driver.body.should include('Edithouse eLabs AB')
|
21
|
+
end
|
22
|
+
|
23
|
+
it_should_behave_like "driver"
|
24
|
+
it_should_behave_like "driver with javascript support"
|
25
|
+
it_should_behave_like "driver with header support"
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
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
|
+
end
|
@@ -0,0 +1,12 @@
|
|
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 without node path support"
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
shared_examples_for 'driver' do
|
4
|
+
|
5
|
+
describe '#visit' do
|
6
|
+
it "should move to another page" do
|
7
|
+
@driver.visit('/')
|
8
|
+
@driver.body.should include('Hello world!')
|
9
|
+
@driver.visit('/foo')
|
10
|
+
@driver.body.should include('Another World')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should show the correct URL" do
|
14
|
+
@driver.visit('/foo')
|
15
|
+
@driver.current_url.should include('/foo')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#body' do
|
20
|
+
it "should return text reponses" do
|
21
|
+
@driver.visit('/')
|
22
|
+
@driver.body.should include('Hello world!')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return the full response html" do
|
26
|
+
@driver.visit('/with_simple_html')
|
27
|
+
@driver.body.should include('Bar')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#find' do
|
32
|
+
context "with xpath selector" do
|
33
|
+
before do
|
34
|
+
@driver.visit('/with_html')
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should extract node texts" do
|
38
|
+
@driver.find('//a')[0].text.should == 'labore'
|
39
|
+
@driver.find('//a')[1].text.should == 'ullamco'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should extract node attributes" do
|
43
|
+
@driver.find('//a')[0][:href].should == '/with_simple_html'
|
44
|
+
@driver.find('//a')[0][:class].should == 'simple'
|
45
|
+
@driver.find('//a')[1][:href].should == '/foo'
|
46
|
+
@driver.find('//a')[1][:id].should == 'foo'
|
47
|
+
@driver.find('//a')[1][:rel].should be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should extract boolean node attributes" do
|
51
|
+
@driver.find('//input[@id="checked_field"]')[0][:checked].should be_true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should allow assignment of field value" do
|
55
|
+
@driver.find('//input').first.value.should == 'monkey'
|
56
|
+
@driver.find('//input').first.set('gorilla')
|
57
|
+
@driver.find('//input').first.value.should == 'gorilla'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should extract node tag name" do
|
61
|
+
@driver.find('//a')[0].tag_name.should == 'a'
|
62
|
+
@driver.find('//a')[1].tag_name.should == 'a'
|
63
|
+
@driver.find('//p')[1].tag_name.should == 'p'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should extract node visibility" do
|
67
|
+
@driver.find('//a')[0].should be_visible
|
68
|
+
|
69
|
+
@driver.find('//div[@id="hidden"]')[0].should_not be_visible
|
70
|
+
@driver.find('//div[@id="hidden_via_ancestor"]')[0].should_not be_visible
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
shared_examples_for "driver with javascript support" do
|
78
|
+
before { @driver.visit('/with_js') }
|
79
|
+
|
80
|
+
describe '#find' do
|
81
|
+
it "should find dynamically changed nodes" do
|
82
|
+
@driver.find('//p').first.text.should == 'I changed it'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#drag_to' do
|
87
|
+
it "should drag and drop an object" do
|
88
|
+
draggable = @driver.find('//div[@id="drag"]').first
|
89
|
+
droppable = @driver.find('//div[@id="drop"]').first
|
90
|
+
draggable.drag_to(droppable)
|
91
|
+
@driver.find('//div[contains(., "Dropped!")]').should_not be_nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#evaluate_script" do
|
96
|
+
it "should return the value of the executed script" do
|
97
|
+
@driver.evaluate_script('1+1').should == 2
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
shared_examples_for "driver with header support" do
|
104
|
+
it "should make headers available through response_headers" do
|
105
|
+
@driver.visit('/with_simple_html')
|
106
|
+
@driver.response_headers['Content-Type'].should == 'text/html'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
shared_examples_for "driver with node path support" do
|
111
|
+
describe "node relative searching" do
|
112
|
+
before do
|
113
|
+
@driver.visit('/tables')
|
114
|
+
@node = @driver.find('//body').first
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should be able to navigate/search child nodes" do
|
118
|
+
@node.all('//table').size.should == 3
|
119
|
+
@node.find('//form').all('//table').size.should == 1
|
120
|
+
@node.find('//form').find('//table//caption').text.should == 'Agent'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
shared_examples_for "driver without node path support" do
|
126
|
+
describe "node relative searching" do
|
127
|
+
before do
|
128
|
+
@driver.visit('/tables')
|
129
|
+
@node = @driver.find('//body').first
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should get NotSupportedByDriverError" do
|
133
|
+
running do
|
134
|
+
@node.all('//form')
|
135
|
+
end.should raise_error(Capybara::NotSupportedByDriverError)
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
shared_examples_for "all" do
|
2
|
+
describe '#all' do
|
3
|
+
before do
|
4
|
+
@session.visit('/with_html')
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should find all elements using the given locator" do
|
8
|
+
@session.all('//p').should have(3).elements
|
9
|
+
@session.all('//h1').first.text.should == 'This is a test'
|
10
|
+
@session.all("//input[@id='test_field']").first[:value].should == 'monkey'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return an empty array when nothing was found" do
|
14
|
+
@session.all('//div[@id="nosuchthing"]').should be_empty
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should accept an XPath instance" do
|
18
|
+
@session.visit('/form')
|
19
|
+
@xpath = Capybara::XPath.text_field('Name')
|
20
|
+
@result = @session.all(@xpath).map { |r| r.value }
|
21
|
+
@result.should include('Smith', 'John', 'John Smith')
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with css selectors" do
|
25
|
+
it "should find the first element using the given locator" do
|
26
|
+
@session.all(:css, 'h1').first.text.should == 'This is a test'
|
27
|
+
@session.all(:css, "input[id='test_field']").first[:value].should == 'monkey'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with xpath selectors" do
|
32
|
+
it "should find the first element using the given locator" do
|
33
|
+
@session.all(:xpath, '//h1').first.text.should == 'This is a test'
|
34
|
+
@session.all(:xpath, "//input[@id='test_field']").first[:value].should == 'monkey'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with css as default selector" do
|
39
|
+
before { Capybara.default_selector = :css }
|
40
|
+
it "should find the first element using the given locator" do
|
41
|
+
@session.all('h1').first.text.should == 'This is a test'
|
42
|
+
@session.all("input[id='test_field']").first[:value].should == 'monkey'
|
43
|
+
end
|
44
|
+
after { Capybara.default_selector = :xpath }
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with visible filter" do
|
48
|
+
after { Capybara.ignore_hidden_elements = false }
|
49
|
+
it "should only find visible nodes" do
|
50
|
+
@session.all("//a[@title='awesome title']").should have(2).elements
|
51
|
+
@session.all("//a[@title='awesome title']", :visible => true).should have(1).elements
|
52
|
+
Capybara.ignore_hidden_elements = true
|
53
|
+
@session.all("//a[@title='awesome title']").should have(1).elements
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "within a scope" do
|
58
|
+
before do
|
59
|
+
@session.visit('/with_scope')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should find any element using the given locator" do
|
63
|
+
@session.within(:xpath, "//div[@id='for_bar']") do
|
64
|
+
@session.all('//li').should have(2).elements
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
shared_examples_for "attach_file" do
|
2
|
+
|
3
|
+
describe "#attach_file" do
|
4
|
+
before do
|
5
|
+
@session.visit('/form')
|
6
|
+
end
|
7
|
+
|
8
|
+
context "with normal form" do
|
9
|
+
it "should set a file path by id" do
|
10
|
+
@session.attach_file "form_image", __FILE__
|
11
|
+
@session.click_button('awesome')
|
12
|
+
extract_results(@session)['image'].should == File.basename(__FILE__)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should set a file path by label" do
|
16
|
+
@session.attach_file "Image", __FILE__
|
17
|
+
@session.click_button('awesome')
|
18
|
+
extract_results(@session)['image'].should == File.basename(__FILE__)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with multipart form" do
|
23
|
+
before do
|
24
|
+
@test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
|
25
|
+
@test_jpg_file_path = File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should set a file path by id" do
|
29
|
+
@session.attach_file "form_document", @test_file_path
|
30
|
+
@session.click_button('Upload')
|
31
|
+
@session.body.should include(File.read(@test_file_path))
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should set a file path by label" do
|
35
|
+
@session.attach_file "Document", @test_file_path
|
36
|
+
@session.click_button('Upload')
|
37
|
+
@session.body.should include(File.read(@test_file_path))
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not break if no file is submitted" do
|
41
|
+
@session.click_button('Upload')
|
42
|
+
@session.body.should include('No file uploaded')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should send content type text/plain when uploading a text file" do
|
46
|
+
@session.attach_file "Document", @test_file_path
|
47
|
+
@session.click_button 'Upload'
|
48
|
+
@session.body.should include('text/plain')
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should send content type image/jpeg when uploading an image" do
|
52
|
+
@session.attach_file "Document", @test_jpg_file_path
|
53
|
+
@session.click_button 'Upload'
|
54
|
+
@session.body.should include('image/jpeg')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "with a locator that doesn't exist" do
|
59
|
+
it "should raise an error" do
|
60
|
+
running { @session.attach_file('does not exist', 'foo.txt') }.should raise_error(Capybara::ElementNotFound)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module CheckSpec
|
2
|
+
shared_examples_for "check" do
|
3
|
+
|
4
|
+
describe "#check" do
|
5
|
+
before do
|
6
|
+
@session.visit('/form')
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "'checked' attribute" do
|
10
|
+
it "should be true if checked" do
|
11
|
+
@session.check("Terms of Use")
|
12
|
+
@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_true
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be false if unchecked" do
|
16
|
+
@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should check a checkbox by id" do
|
21
|
+
@session.check("form_pets_cat")
|
22
|
+
@session.click_button('awesome')
|
23
|
+
extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should check a checkbox by label" do
|
27
|
+
@session.check("Cat")
|
28
|
+
@session.click_button('awesome')
|
29
|
+
extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with a locator that doesn't exist" do
|
33
|
+
it "should raise an error" do
|
34
|
+
running { @session.check('does not exist') }.should raise_error(Capybara::ElementNotFound)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|