Don't put DSL specs into modules

I don't understand how this is useful?
This commit is contained in:
Jonas Nicklas 2010-01-18 20:33:22 +01:00
parent 05fd0d3f06
commit 2e432b82e7
21 changed files with 1092 additions and 1133 deletions

View File

@ -1,61 +1,59 @@
module AllSpec
shared_examples_for "all" do
describe '#all' do
shared_examples_for "all" do
describe '#all' do
before do
@session.visit('/with_html')
end
it "should find all elements using the given locator" do
@session.all('//p').should have(3).elements
@session.all('//h1').first.text.should == 'This is a test'
@session.all("//input[@id='test_field']").first[:value].should == 'monkey'
end
context "with css selectors" do
it "should find the first element using the given locator" do
@session.all(:css, 'h1').first.text.should == 'This is a test'
@session.all(:css, "input[id='test_field']").first[:value].should == 'monkey'
end
end
context "with xpath selectors" do
it "should find the first element using the given locator" do
@session.all(:xpath, '//h1').first.text.should == 'This is a test'
@session.all(:xpath, "//input[@id='test_field']").first[:value].should == 'monkey'
end
end
context "with css as default selector" do
before { Capybara.default_selector = :css }
it "should find the first element using the given locator" do
@session.all('h1').first.text.should == 'This is a test'
@session.all("input[id='test_field']").first[:value].should == 'monkey'
end
after { Capybara.default_selector = :xpath }
end
it "should return an empty array when nothing was found" do
@session.all('//div[@id="nosuchthing"]').should be_empty
end
it "should accept an XPath instance" do
@session.visit('/form')
@xpath = Capybara::XPath.text_field('Name')
@result = @session.all(@xpath).map { |r| r.value }
@result.should include('Smith', 'John', 'John Smith')
end
context "within a scope" do
before do
@session.visit('/with_html')
@session.visit('/with_scope')
end
it "should find all elements using the given locator" do
@session.all('//p').should have(3).elements
@session.all('//h1').first.text.should == 'This is a test'
@session.all("//input[@id='test_field']").first[:value].should == 'monkey'
end
context "with css selectors" do
it "should find the first element using the given locator" do
@session.all(:css, 'h1').first.text.should == 'This is a test'
@session.all(:css, "input[id='test_field']").first[:value].should == 'monkey'
end
end
context "with xpath selectors" do
it "should find the first element using the given locator" do
@session.all(:xpath, '//h1').first.text.should == 'This is a test'
@session.all(:xpath, "//input[@id='test_field']").first[:value].should == 'monkey'
end
end
context "with css as default selector" do
before { Capybara.default_selector = :css }
it "should find the first element using the given locator" do
@session.all('h1').first.text.should == 'This is a test'
@session.all("input[id='test_field']").first[:value].should == 'monkey'
end
after { Capybara.default_selector = :xpath }
end
it "should return an empty array when nothing was found" do
@session.all('//div[@id="nosuchthing"]').should be_empty
end
it "should accept an XPath instance" do
@session.visit('/form')
@xpath = Capybara::XPath.text_field('Name')
@result = @session.all(@xpath).map { |r| r.value }
@result.should include('Smith', 'John', 'John Smith')
end
context "within a scope" do
before do
@session.visit('/with_scope')
end
it "should find any element using the given locator" do
@session.within(:xpath, "//div[@id='for_bar']") do
@session.all('//li').should have(2).elements
end
it "should find any element using the given locator" do
@session.within(:xpath, "//div[@id='for_bar']") do
@session.all('//li').should have(2).elements
end
end
end
end
end
end

View File

@ -1,66 +1,64 @@
module AttachFileSpec
shared_examples_for "attach_file" do
shared_examples_for "attach_file" do
describe "#attach_file" do
describe "#attach_file" do
before do
@session.visit('/form')
end
context "with normal form" do
it "should set a file path by id" do
@session.attach_file "form_image", __FILE__
@session.click_button('awesome')
extract_results(@session)['image'].should == File.basename(__FILE__)
end
it "should set a file path by label" do
@session.attach_file "Image", __FILE__
@session.click_button('awesome')
extract_results(@session)['image'].should == File.basename(__FILE__)
end
end
context "with multipart form" do
before do
@session.visit('/form')
@test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
@test_jpg_file_path = File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))
end
context "with normal form" do
it "should set a file path by id" do
@session.attach_file "form_image", __FILE__
@session.click_button('awesome')
extract_results(@session)['image'].should == File.basename(__FILE__)
end
it "should set a file path by label" do
@session.attach_file "Image", __FILE__
@session.click_button('awesome')
extract_results(@session)['image'].should == File.basename(__FILE__)
end
it "should set a file path by id" do
@session.attach_file "form_document", @test_file_path
@session.click_button('Upload')
@session.body.should include(File.read(@test_file_path))
end
context "with multipart form" do
before do
@test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
@test_jpg_file_path = File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))
end
it "should set a file path by id" do
@session.attach_file "form_document", @test_file_path
@session.click_button('Upload')
@session.body.should include(File.read(@test_file_path))
end
it "should set a file path by label" do
@session.attach_file "Document", @test_file_path
@session.click_button('Upload')
@session.body.should include(File.read(@test_file_path))
end
it "should not break if no file is submitted" do
@session.click_button('Upload')
@session.body.should include('No file uploaded')
end
it "should send content type text/plain when uploading a text file" do
@session.attach_file "Document", @test_file_path
@session.click_button 'Upload'
@session.body.should include('text/plain')
end
it "should send content type image/jpeg when uploading an image" do
@session.attach_file "Document", @test_jpg_file_path
@session.click_button 'Upload'
@session.body.should include('image/jpeg')
end
it "should set a file path by label" do
@session.attach_file "Document", @test_file_path
@session.click_button('Upload')
@session.body.should include(File.read(@test_file_path))
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running { @session.attach_file('does not exist', 'foo.txt') }.should raise_error(Capybara::ElementNotFound)
end
it "should not break if no file is submitted" do
@session.click_button('Upload')
@session.body.should include('No file uploaded')
end
it "should send content type text/plain when uploading a text file" do
@session.attach_file "Document", @test_file_path
@session.click_button 'Upload'
@session.body.should include('text/plain')
end
it "should send content type image/jpeg when uploading an image" do
@session.attach_file "Document", @test_jpg_file_path
@session.click_button 'Upload'
@session.body.should include('image/jpeg')
end
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running { @session.attach_file('does not exist', 'foo.txt') }.should raise_error(Capybara::ElementNotFound)
end
end
end
end
end

View File

@ -1,28 +1,26 @@
module ChooseSpec
shared_examples_for "choose" do
shared_examples_for "choose" do
describe "#choose" do
before do
@session.visit('/form')
end
describe "#choose" do
before do
@session.visit('/form')
end
it "should choose a radio button by id" do
@session.choose("gender_male")
@session.click_button('awesome')
extract_results(@session)['gender'].should == 'male'
end
it "should choose a radio button by id" do
@session.choose("gender_male")
@session.click_button('awesome')
extract_results(@session)['gender'].should == 'male'
end
it "should choose a radio button by label" do
@session.choose("Both")
@session.click_button('awesome')
extract_results(@session)['gender'].should == 'both'
end
it "should choose a radio button by label" do
@session.choose("Both")
@session.click_button('awesome')
extract_results(@session)['gender'].should == 'both'
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running { @session.choose('does not exist') }.should raise_error(Capybara::ElementNotFound)
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running { @session.choose('does not exist') }.should raise_error(Capybara::ElementNotFound)
end
end
end
end
end

View File

@ -1,183 +1,181 @@
module ClickButtonSpec
shared_examples_for "click_button" do
describe '#click_button' do
shared_examples_for "click_button" do
describe '#click_button' do
before do
@session.visit('/form')
end
context "with multiple values with the same name" do
it "should use the latest given value" do
@session.check('Terms of Use')
@session.click_button('awesome')
extract_results(@session)['terms_of_use'].should == '1'
end
end
context "with value given on a submit button" do
before do
@session.visit('/form')
end
context "with multiple values with the same name" do
it "should use the latest given value" do
@session.check('Terms of Use')
@session.click_button('awesome')
extract_results(@session)['terms_of_use'].should == '1'
end
end
context "with value given on a submit button" do
before do
@session.click_button('awesome')
@results = extract_results(@session)
end
it "should serialize and submit text fields" do
@results['first_name'].should == 'John'
end
it "should escape fields when submitting" do
@results['phone'].should == '+1 555 7021'
end
it "should serialize and submit password fields" do
@results['password'].should == 'seeekrit'
end
it "should serialize and submit hidden fields" do
@results['token'].should == '12345'
end
it "should not serialize fields from other forms" do
@results['middle_name'].should be_nil
end
it "should submit the button that was clicked, but not other buttons" do
@results['awesome'].should == 'awesome'
@results['crappy'].should be_nil
end
it "should serialize radio buttons" do
@results['gender'].should == 'female'
end
it "should serialize check boxes" do
@results['pets'].should include('dog', 'hamster')
@results['pets'].should_not include('cat')
end
it "should serialize text areas" do
@results['description'].should == 'Descriptive text goes here'
end
it "should serialize select tag with values" do
@results['locale'].should == 'en'
end
it "should serialize select tag without values" do
@results['region'].should == 'Norway'
end
it "should serialize first option for select tag with no selection" do
@results['city'].should == 'London'
end
it "should not serialize a select tag without options" do
@results['tendency'].should be_nil
end
end
context "with id given on a submit button" do
it "should submit the associated form" do
@session.click_button('awe123')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('Go')
@session.body.should include('You landed')
end
end
context "with value given on an image button" do
it "should submit the associated form" do
@session.click_button('okay')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('kay')
extract_results(@session)['first_name'].should == 'John'
end
end
context "with id given on an image button" do
it "should submit the associated form" do
@session.click_button('okay556')
extract_results(@session)['first_name'].should == 'John'
end
end
context "with text given on a button defined by <button> tag" do
it "should submit the associated form" do
@session.click_button('Click me')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('Click')
extract_results(@session)['first_name'].should == 'John'
end
it "should prefer exact matches over partial matches" do
@session.click_button('Just an input')
extract_results(@session)['button'].should == 'button_second'
end
end
context "with id given on a button defined by <button> tag" do
it "should submit the associated form" do
@session.click_button('click_me_123')
extract_results(@session)['first_name'].should == 'John'
end
end
context "with value given on a button defined by <button> tag" do
it "should submit the associated form" do
@session.click_button('click_me')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('ck_me')
extract_results(@session)['first_name'].should == 'John'
end
it "should prefer exact matches over partial matches" do
@session.click_button('Just a button')
extract_results(@session)['button'].should == 'Just a button'
end
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running do
@session.click_button('does not exist')
end.should raise_error(Capybara::ElementNotFound)
end
end
it "should serialize and send GET forms" do
@session.visit('/form')
@session.click_button('med')
@session.click_button('awesome')
@results = extract_results(@session)
@results['middle_name'].should == 'Darren'
@results['foo'].should be_nil
end
it "should follow redirects" do
@session.click_button('Go FAR')
it "should serialize and submit text fields" do
@results['first_name'].should == 'John'
end
it "should escape fields when submitting" do
@results['phone'].should == '+1 555 7021'
end
it "should serialize and submit password fields" do
@results['password'].should == 'seeekrit'
end
it "should serialize and submit hidden fields" do
@results['token'].should == '12345'
end
it "should not serialize fields from other forms" do
@results['middle_name'].should be_nil
end
it "should submit the button that was clicked, but not other buttons" do
@results['awesome'].should == 'awesome'
@results['crappy'].should be_nil
end
it "should serialize radio buttons" do
@results['gender'].should == 'female'
end
it "should serialize check boxes" do
@results['pets'].should include('dog', 'hamster')
@results['pets'].should_not include('cat')
end
it "should serialize text areas" do
@results['description'].should == 'Descriptive text goes here'
end
it "should serialize select tag with values" do
@results['locale'].should == 'en'
end
it "should serialize select tag without values" do
@results['region'].should == 'Norway'
end
it "should serialize first option for select tag with no selection" do
@results['city'].should == 'London'
end
it "should not serialize a select tag without options" do
@results['tendency'].should be_nil
end
end
context "with id given on a submit button" do
it "should submit the associated form" do
@session.click_button('awe123')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('Go')
@session.body.should include('You landed')
end
it "should post pack to the same URL when no action given" do
@session.visit('/postback')
@session.click_button('With no action')
@session.body.should include('Postback')
end
context "with value given on an image button" do
it "should submit the associated form" do
@session.click_button('okay')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('kay')
extract_results(@session)['first_name'].should == 'John'
end
end
context "with id given on an image button" do
it "should submit the associated form" do
@session.click_button('okay556')
extract_results(@session)['first_name'].should == 'John'
end
end
context "with text given on a button defined by <button> tag" do
it "should submit the associated form" do
@session.click_button('Click me')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('Click')
extract_results(@session)['first_name'].should == 'John'
end
it "should prefer exact matches over partial matches" do
@session.click_button('Just an input')
extract_results(@session)['button'].should == 'button_second'
end
end
context "with id given on a button defined by <button> tag" do
it "should submit the associated form" do
@session.click_button('click_me_123')
extract_results(@session)['first_name'].should == 'John'
end
end
context "with value given on a button defined by <button> tag" do
it "should submit the associated form" do
@session.click_button('click_me')
extract_results(@session)['first_name'].should == 'John'
end
it "should work with partial matches" do
@session.click_button('ck_me')
extract_results(@session)['first_name'].should == 'John'
end
it "should post pack to the same URL when blank action given" do
@session.visit('/postback')
@session.click_button('With blank action')
@session.body.should include('Postback')
it "should prefer exact matches over partial matches" do
@session.click_button('Just a button')
extract_results(@session)['button'].should == 'Just a button'
end
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running do
@session.click_button('does not exist')
end.should raise_error(Capybara::ElementNotFound)
end
end
it "should serialize and send GET forms" do
@session.visit('/form')
@session.click_button('med')
@results = extract_results(@session)
@results['middle_name'].should == 'Darren'
@results['foo'].should be_nil
end
it "should follow redirects" do
@session.click_button('Go FAR')
@session.body.should include('You landed')
end
it "should post pack to the same URL when no action given" do
@session.visit('/postback')
@session.click_button('With no action')
@session.body.should include('Postback')
end
it "should post pack to the same URL when blank action given" do
@session.visit('/postback')
@session.click_button('With blank action')
@session.body.should include('Postback')
end
end
end

View File

@ -1,105 +1,103 @@
module ClickLinkSpec
shared_examples_for "click_link" do
describe '#click_link' do
before do
@session.visit('/with_html')
shared_examples_for "click_link" do
describe '#click_link' do
before do
@session.visit('/with_html')
end
context "with id given" do
it "should take user to the linked page" do
@session.click_link('foo')
@session.body.should include('Another World')
end
end
context "with id given" do
it "should take user to the linked page" do
@session.click_link('foo')
@session.body.should include('Another World')
end
end
context "with text given" do
it "should take user to the linked page" do
@session.click_link('labore')
@session.body.should include('Bar')
end
it "should accept partial matches" do
@session.click_link('abo')
@session.body.should include('Bar')
end
it "should prefer exact matches over partial matches" do
@session.click_link('A link')
@session.body.should include('Bar')
end
end
context "with title given" do
it "should take user to the linked page" do
@session.click_link('awesome title')
@session.body.should include('Bar')
end
it "should accept partial matches" do
@session.click_link('some tit')
@session.body.should include('Bar')
end
it "should prefer exact matches over partial matches" do
@session.click_link('a fine link')
@session.body.should include('Bar')
end
end
context "with alternative text given to a contained image" do
it "should take user to the linked page" do
@session.click_link('awesome image')
@session.body.should include('Bar')
end
it "should take user to the linked page" do
@session.click_link('some imag')
@session.body.should include('Bar')
end
it "should prefer exact matches over partial matches" do
@session.click_link('fine image')
@session.body.should include('Bar')
end
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running do
@session.click_link('does not exist')
end.should raise_error(Capybara::ElementNotFound)
end
end
it "should follow redirects" do
@session.click_link('Redirect')
@session.body.should include('You landed')
end
it "should do nothing on anchor links" do
@session.fill_in("test_field", :with => 'blah')
@session.click_link('Anchor')
@session.find_field("test_field").value.should == 'blah'
@session.click_link('Blank Anchor')
@session.find_field("test_field").value.should == 'blah'
end
it "should do nothing on URL+anchor links for the same page" do
@session.fill_in("test_field", :with => 'blah')
@session.click_link('Anchor on same page')
@session.find_field("test_field").value.should == 'blah'
end
it "should follow link on URL+anchor links for a different page" do
@session.click_link('Anchor on different page')
context "with text given" do
it "should take user to the linked page" do
@session.click_link('labore')
@session.body.should include('Bar')
end
it "raise an error with links with no href" do
it "should accept partial matches" do
@session.click_link('abo')
@session.body.should include('Bar')
end
it "should prefer exact matches over partial matches" do
@session.click_link('A link')
@session.body.should include('Bar')
end
end
context "with title given" do
it "should take user to the linked page" do
@session.click_link('awesome title')
@session.body.should include('Bar')
end
it "should accept partial matches" do
@session.click_link('some tit')
@session.body.should include('Bar')
end
it "should prefer exact matches over partial matches" do
@session.click_link('a fine link')
@session.body.should include('Bar')
end
end
context "with alternative text given to a contained image" do
it "should take user to the linked page" do
@session.click_link('awesome image')
@session.body.should include('Bar')
end
it "should take user to the linked page" do
@session.click_link('some imag')
@session.body.should include('Bar')
end
it "should prefer exact matches over partial matches" do
@session.click_link('fine image')
@session.body.should include('Bar')
end
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running do
@session.click_link('No Href')
@session.click_link('does not exist')
end.should raise_error(Capybara::ElementNotFound)
end
end
it "should follow redirects" do
@session.click_link('Redirect')
@session.body.should include('You landed')
end
it "should do nothing on anchor links" do
@session.fill_in("test_field", :with => 'blah')
@session.click_link('Anchor')
@session.find_field("test_field").value.should == 'blah'
@session.click_link('Blank Anchor')
@session.find_field("test_field").value.should == 'blah'
end
it "should do nothing on URL+anchor links for the same page" do
@session.fill_in("test_field", :with => 'blah')
@session.click_link('Anchor on same page')
@session.find_field("test_field").value.should == 'blah'
end
it "should follow link on URL+anchor links for a different page" do
@session.click_link('Anchor on different page')
@session.body.should include('Bar')
end
it "raise an error with links with no href" do
running do
@session.click_link('No Href')
end.should raise_error(Capybara::ElementNotFound)
end
end
end
end

View File

@ -1,26 +1,24 @@
module ClickSpec
shared_examples_for "click" do
describe '#click' do
it "should click on a link" do
shared_examples_for "click" do
describe '#click' do
it "should click on a link" do
@session.visit('/with_html')
@session.click('labore')
@session.body.should include('Bar')
end
it "should click on a button" do
@session.visit('/form')
@session.click('awe123')
extract_results(@session)['first_name'].should == 'John'
end
context "with a locator that doesn't exist" do
it "should raise an error" do
@session.visit('/with_html')
@session.click('labore')
@session.body.should include('Bar')
end
it "should click on a button" do
@session.visit('/form')
@session.click('awe123')
extract_results(@session)['first_name'].should == 'John'
end
context "with a locator that doesn't exist" do
it "should raise an error" do
@session.visit('/with_html')
running do
@session.click('does not exist')
end.should raise_error(Capybara::ElementNotFound)
end
running do
@session.click('does not exist')
end.should raise_error(Capybara::ElementNotFound)
end
end
end
end
end

View File

@ -1,10 +1,8 @@
module CurrentUrlSpec
shared_examples_for "current_url" do
describe '#current_url' do
it "should return the current url" do
@session.visit('/form')
@session.current_url.should =~ %r(http://[^/]+/form)
end
shared_examples_for "current_url" do
describe '#current_url' do
it "should return the current url" do
@session.visit('/form')
@session.current_url.should =~ %r(http://[^/]+/form)
end
end
end
end

View File

@ -1,89 +1,87 @@
module FillInSpec
shared_examples_for "fill_in" do
describe "#fill_in" do
before do
@session.visit('/form')
end
shared_examples_for "fill_in" do
describe "#fill_in" do
before do
@session.visit('/form')
end
it "should fill in a text field by id" do
@session.fill_in('form_first_name', :with => 'Harry')
@session.click_button('awesome')
extract_results(@session)['first_name'].should == 'Harry'
end
it "should fill in a text field by id" do
@session.fill_in('form_first_name', :with => 'Harry')
@session.click_button('awesome')
extract_results(@session)['first_name'].should == 'Harry'
end
it "should fill in a text field by label" do
@session.fill_in('First Name', :with => 'Harry')
@session.click_button('awesome')
extract_results(@session)['first_name'].should == 'Harry'
end
it "should fill in a text field by label" do
@session.fill_in('First Name', :with => 'Harry')
@session.click_button('awesome')
extract_results(@session)['first_name'].should == 'Harry'
end
it "should fill in a text field by name" do
@session.fill_in('form[first_name]', :with => 'Harry')
@session.click_button('awesome')
extract_results(@session)['first_name'].should == 'Harry'
end
it "should fill in a text field by name" do
@session.fill_in('form[first_name]', :with => 'Harry')
@session.click_button('awesome')
extract_results(@session)['first_name'].should == 'Harry'
end
it "should fill in a text field by label without for" do
@session.fill_in('Street', :with => 'Avenue Q')
@session.click_button('awesome')
extract_results(@session)['street'].should == 'Avenue Q'
end
it "should fill in a text field by label without for" do
@session.fill_in('Street', :with => 'Avenue Q')
@session.click_button('awesome')
extract_results(@session)['street'].should == 'Avenue Q'
end
it "should favour exact label matches over partial matches" do
@session.fill_in('Name', :with => 'Harry Jones')
@session.click_button('awesome')
extract_results(@session)['name'].should == 'Harry Jones'
end
it "should favour exact label matches over partial matches" do
@session.fill_in('Name', :with => 'Harry Jones')
@session.click_button('awesome')
extract_results(@session)['name'].should == 'Harry Jones'
end
it "should fill in a textarea by id" do
@session.fill_in('form_description', :with => 'Texty text')
@session.click_button('awesome')
extract_results(@session)['description'].should == 'Texty text'
end
it "should fill in a textarea by id" do
@session.fill_in('form_description', :with => 'Texty text')
@session.click_button('awesome')
extract_results(@session)['description'].should == 'Texty text'
end
it "should fill in a textarea by label" do
@session.fill_in('Description', :with => 'Texty text')
@session.click_button('awesome')
extract_results(@session)['description'].should == 'Texty text'
end
it "should fill in a textarea by label" do
@session.fill_in('Description', :with => 'Texty text')
@session.click_button('awesome')
extract_results(@session)['description'].should == 'Texty text'
end
it "should fill in a textarea by name" do
@session.fill_in('form[description]', :with => 'Texty text')
@session.click_button('awesome')
extract_results(@session)['description'].should == 'Texty text'
end
it "should fill in a textarea by name" do
@session.fill_in('form[description]', :with => 'Texty text')
@session.click_button('awesome')
extract_results(@session)['description'].should == 'Texty text'
end
it "should fill in a password field by id" do
@session.fill_in('form_password', :with => 'supasikrit')
@session.click_button('awesome')
extract_results(@session)['password'].should == 'supasikrit'
end
it "should fill in a password field by id" do
@session.fill_in('form_password', :with => 'supasikrit')
@session.click_button('awesome')
extract_results(@session)['password'].should == 'supasikrit'
end
it "should fill in a password field by label" do
@session.fill_in('Password', :with => 'supasikrit')
@session.click_button('awesome')
extract_results(@session)['password'].should == 'supasikrit'
end
it "should fill in a password field by label" do
@session.fill_in('Password', :with => 'supasikrit')
@session.click_button('awesome')
extract_results(@session)['password'].should == 'supasikrit'
end
it "should fill in a password field by name" do
@session.fill_in('form[password]', :with => 'supasikrit')
@session.click_button('awesome')
extract_results(@session)['password'].should == 'supasikrit'
end
it "should prefer exact matches over partial matches" do
@session.fill_in('Name', :with => 'Ford Prefect')
@session.click_button('awesome')
extract_results(@session)['name'].should == 'Ford Prefect'
end
it "should fill in a password field by name" do
@session.fill_in('form[password]', :with => 'supasikrit')
@session.click_button('awesome')
extract_results(@session)['password'].should == 'supasikrit'
end
it "should prefer exact matches over partial matches" do
@session.fill_in('Name', :with => 'Ford Prefect')
@session.click_button('awesome')
extract_results(@session)['name'].should == 'Ford Prefect'
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running do
@session.fill_in('does not exist', :with => 'Blah blah')
end.should raise_error(Capybara::ElementNotFound)
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running do
@session.fill_in('does not exist', :with => 'Blah blah')
end.should raise_error(Capybara::ElementNotFound)
end
end
end
end
end

View File

@ -1,18 +1,16 @@
module FindButtonSpec
shared_examples_for "find_button" do
describe '#find_button' do
before do
@session.visit('/form')
end
shared_examples_for "find_button" do
describe '#find_button' do
before do
@session.visit('/form')
end
it "should find any field" do
@session.find_button('med')[:id].should == "mediocre"
@session.find_button('crap321').value.should == "crappy"
end
it "should find any field" do
@session.find_button('med')[:id].should == "mediocre"
@session.find_button('crap321').value.should == "crappy"
end
it "should return nil if the field doesn't exist" do
@session.find_button('Does not exist').should be_nil
end
it "should return nil if the field doesn't exist" do
@session.find_button('Does not exist').should be_nil
end
end
end
end

View File

@ -1,18 +1,16 @@
module FindByIdSpec
shared_examples_for "find_by_id" do
describe '#find_by_id' do
before do
@session.visit('/with_html')
end
shared_examples_for "find_by_id" do
describe '#find_by_id' do
before do
@session.visit('/with_html')
end
it "should find any element by id" do
@session.find_by_id('red').tag_name.should == 'a'
@session.find_by_id('hidden_via_ancestor').tag_name.should == 'div'
end
it "should find any element by id" do
@session.find_by_id('red').tag_name.should == 'a'
@session.find_by_id('hidden_via_ancestor').tag_name.should == 'div'
end
it "should return nil if no element with id is found" do
@session.find_by_id('nothing_with_this_id').should be_nil
end
it "should return nil if no element with id is found" do
@session.find_by_id('nothing_with_this_id').should be_nil
end
end
end
end

View File

@ -1,24 +1,22 @@
module FindFieldSpec
shared_examples_for "find_field" do
describe '#find_field' do
before do
@session.visit('/form')
end
shared_examples_for "find_field" do
describe '#find_field' do
before do
@session.visit('/form')
end
it "should find any field" do
@session.find_field('Dog').value.should == 'dog'
@session.find_field('form_description').text.should == 'Descriptive text goes here'
@session.find_field('Region')[:name].should == 'form[region]'
end
it "should find any field" do
@session.find_field('Dog').value.should == 'dog'
@session.find_field('form_description').text.should == 'Descriptive text goes here'
@session.find_field('Region')[:name].should == 'form[region]'
end
it "should be nil if the field doesn't exist" do
@session.find_field('Does not exist').should be_nil
end
it "should be nil if the field doesn't exist" do
@session.find_field('Does not exist').should be_nil
end
it "should be aliased as 'field_labeled' for webrat compatibility" do
@session.field_labeled('Dog').value.should == 'dog'
@session.field_labeled('Does not exist').should be_nil
end
it "should be aliased as 'field_labeled' for webrat compatibility" do
@session.field_labeled('Dog').value.should == 'dog'
@session.field_labeled('Does not exist').should be_nil
end
end
end
end

View File

@ -1,19 +1,17 @@
module FindLinkSpec
shared_examples_for "find_link" do
describe '#find_link' do
before do
@session.visit('/with_html')
end
shared_examples_for "find_link" do
it "should find any field" do
@session.find_link('foo').text.should == "ullamco"
@session.find_link('labore')[:href].should == "/with_simple_html"
end
describe '#find_link' do
before do
@session.visit('/with_html')
end
it "should return nil if the field doesn't exist" do
@session.find_link('Does not exist').should be_nil
end
it "should find any field" do
@session.find_link('foo').text.should == "ullamco"
@session.find_link('labore')[:href].should == "/with_simple_html"
end
it "should return nil if the field doesn't exist" do
@session.find_link('Does not exist').should be_nil
end
end
end
end

View File

@ -1,59 +1,57 @@
module FindSpec
shared_examples_for "find" do
describe '#find' do
shared_examples_for "find" do
describe '#find' do
before do
@session.visit('/with_html')
end
it "should find the first element using the given locator" do
@session.find('//h1').text.should == 'This is a test'
@session.find("//input[@id='test_field']")[:value].should == 'monkey'
end
context "with css selectors" do
it "should find the first element using the given locator" do
@session.find(:css, 'h1').text.should == 'This is a test'
@session.find(:css, "input[id='test_field']")[:value].should == 'monkey'
end
end
context "with xpath selectors" do
it "should find the first element using the given locator" do
@session.find(:xpath, '//h1').text.should == 'This is a test'
@session.find(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
end
end
context "with css as default selector" do
before { Capybara.default_selector = :css }
it "should find the first element using the given locator" do
@session.find('h1').text.should == 'This is a test'
@session.find("input[id='test_field']")[:value].should == 'monkey'
end
after { Capybara.default_selector = :xpath }
end
it "should return nil when nothing was found" do
@session.find('//div[@id="nosuchthing"]').should be_nil
end
it "should accept an XPath instance and respect the order of paths" do
@session.visit('/form')
@xpath = Capybara::XPath.text_field('Name')
@session.find(@xpath).value.should == 'John Smith'
end
context "within a scope" do
before do
@session.visit('/with_html')
@session.visit('/with_scope')
end
it "should find the first element using the given locator" do
@session.find('//h1').text.should == 'This is a test'
@session.find("//input[@id='test_field']")[:value].should == 'monkey'
end
context "with css selectors" do
it "should find the first element using the given locator" do
@session.find(:css, 'h1').text.should == 'This is a test'
@session.find(:css, "input[id='test_field']")[:value].should == 'monkey'
end
end
context "with xpath selectors" do
it "should find the first element using the given locator" do
@session.find(:xpath, '//h1').text.should == 'This is a test'
@session.find(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
end
end
context "with css as default selector" do
before { Capybara.default_selector = :css }
it "should find the first element using the given locator" do
@session.find('h1').text.should == 'This is a test'
@session.find("input[id='test_field']")[:value].should == 'monkey'
end
after { Capybara.default_selector = :xpath }
end
it "should return nil when nothing was found" do
@session.find('//div[@id="nosuchthing"]').should be_nil
end
it "should accept an XPath instance and respect the order of paths" do
@session.visit('/form')
@xpath = Capybara::XPath.text_field('Name')
@session.find(@xpath).value.should == 'John Smith'
end
context "within a scope" do
before do
@session.visit('/with_scope')
end
it "should find the first element using the given locator" do
@session.within(:xpath, "//div[@id='for_bar']") do
@session.find('//li').text.should =~ /With Simple HTML/
end
@session.within(:xpath, "//div[@id='for_bar']") do
@session.find('//li').text.should =~ /With Simple HTML/
end
end
end
end
end
end

View File

@ -1,103 +1,101 @@
module HasContentSpec
shared_examples_for "has_content" do
describe '#has_content?' do
it "should be true if the given content is on the page at least once" do
@session.visit('/with_html')
@session.should have_content('est')
@session.should have_content('Lorem')
@session.should have_content('Redirect')
end
shared_examples_for "has_content" do
describe '#has_content?' do
it "should be true if the given content is on the page at least once" do
@session.visit('/with_html')
@session.should have_content('est')
@session.should have_content('Lorem')
@session.should have_content('Redirect')
end
it "should be true if scoped to an element which has the content" do
@session.visit('/with_html')
@session.within("//a[@title='awesome title']") do
@session.should have_content('labore')
end
it "should be true if scoped to an element which has the content" do
@session.visit('/with_html')
@session.within("//a[@title='awesome title']") do
@session.should have_content('labore')
end
end
it "should be false if scoped to an element which does not have the content" do
@session.visit('/with_html')
@session.within("//a[@title='awesome title']") do
@session.should_not have_content('monkey')
end
end
it "should ignore tags" do
@session.visit('/with_html')
@session.should_not have_content('exercitation <a href="/foo" id="foo">ullamco</a> laboris')
@session.should have_content('exercitation ullamco laboris')
end
it "should be false if the given content is not on the page" do
@session.visit('/with_html')
@session.should_not have_content('xxxxyzzz')
it "should be false if scoped to an element which does not have the content" do
@session.visit('/with_html')
@session.within("//a[@title='awesome title']") do
@session.should_not have_content('monkey')
end
it 'should handle single quotes in the content' do
@session.visit('/with-quotes')
@session.should have_content("can't")
end
it 'should handle double quotes in the content' do
@session.visit('/with-quotes')
@session.should have_content(%q{"No," he said})
end
it 'should handle mixed single and double quotes in the content' do
@session.visit('/with-quotes')
@session.should have_content(%q{"you can't do that."})
end
end
describe '#has_no_content?' do
it "should be false if the given content is on the page at least once" do
@session.visit('/with_html')
@session.should_not have_no_content('est')
@session.should_not have_no_content('Lorem')
@session.should_not have_no_content('Redirect')
end
it "should ignore tags" do
@session.visit('/with_html')
@session.should_not have_content('exercitation <a href="/foo" id="foo">ullamco</a> laboris')
@session.should have_content('exercitation ullamco laboris')
end
it "should be false if scoped to an element which has the content" do
@session.visit('/with_html')
@session.within("//a[@title='awesome title']") do
@session.should_not have_no_content('labore')
end
end
it "should be false if the given content is not on the page" do
@session.visit('/with_html')
@session.should_not have_content('xxxxyzzz')
@session.should_not have_content('monkey')
end
it "should be true if scoped to an element which does not have the content" do
@session.visit('/with_html')
@session.within("//a[@title='awesome title']") do
@session.should have_no_content('monkey')
end
end
it 'should handle single quotes in the content' do
@session.visit('/with-quotes')
@session.should have_content("can't")
end
it "should ignore tags" do
@session.visit('/with_html')
@session.should have_no_content('exercitation <a href="/foo" id="foo">ullamco</a> laboris')
@session.should_not have_no_content('exercitation ullamco laboris')
end
it 'should handle double quotes in the content' do
@session.visit('/with-quotes')
@session.should have_content(%q{"No," he said})
end
it "should be true if the given content is not on the page" do
@session.visit('/with_html')
@session.should have_no_content('xxxxyzzz')
@session.should have_no_content('monkey')
end
it 'should handle single quotes in the content' do
@session.visit('/with-quotes')
@session.should_not have_no_content("can't")
end
it 'should handle double quotes in the content' do
@session.visit('/with-quotes')
@session.should_not have_no_content(%q{"No," he said})
end
it 'should handle mixed single and double quotes in the content' do
@session.visit('/with-quotes')
@session.should_not have_no_content(%q{"you can't do that."})
end
it 'should handle mixed single and double quotes in the content' do
@session.visit('/with-quotes')
@session.should have_content(%q{"you can't do that."})
end
end
end
describe '#has_no_content?' do
it "should be false if the given content is on the page at least once" do
@session.visit('/with_html')
@session.should_not have_no_content('est')
@session.should_not have_no_content('Lorem')
@session.should_not have_no_content('Redirect')
end
it "should be false if scoped to an element which has the content" do
@session.visit('/with_html')
@session.within("//a[@title='awesome title']") do
@session.should_not have_no_content('labore')
end
end
it "should be true if scoped to an element which does not have the content" do
@session.visit('/with_html')
@session.within("//a[@title='awesome title']") do
@session.should have_no_content('monkey')
end
end
it "should ignore tags" do
@session.visit('/with_html')
@session.should have_no_content('exercitation <a href="/foo" id="foo">ullamco</a> laboris')
@session.should_not have_no_content('exercitation ullamco laboris')
end
it "should be true if the given content is not on the page" do
@session.visit('/with_html')
@session.should have_no_content('xxxxyzzz')
@session.should have_no_content('monkey')
end
it 'should handle single quotes in the content' do
@session.visit('/with-quotes')
@session.should_not have_no_content("can't")
end
it 'should handle double quotes in the content' do
@session.visit('/with-quotes')
@session.should_not have_no_content(%q{"No," he said})
end
it 'should handle mixed single and double quotes in the content' do
@session.visit('/with-quotes')
@session.should_not have_no_content(%q{"you can't do that."})
end
end
end

View File

@ -1,109 +1,107 @@
module HasCssSpec
shared_examples_for "has_css" do
describe '#has_css?' do
before do
@session.visit('/with_html')
end
shared_examples_for "has_css" do
describe '#has_css?' do
before do
@session.visit('/with_html')
end
it "should be true if the given selector is on the page" do
@session.should have_css("p")
@session.should have_css("p a#foo")
end
it "should be true if the given selector is on the page" do
@session.should have_css("p")
@session.should have_css("p a#foo")
end
it "should be false if the given selector is not on the page" do
@session.should_not have_css("abbr")
@session.should_not have_css("p a#doesnotexist")
@session.should_not have_css("p.nosuchclass")
end
it "should be false if the given selector is not on the page" do
@session.should_not have_css("abbr")
@session.should_not have_css("p a#doesnotexist")
@session.should_not have_css("p.nosuchclass")
end
it "should respect scopes" do
@session.within "//p[@id='first']" do
@session.should have_css("a#foo")
@session.should_not have_css("a#red")
end
end
context "with count" do
it "should be true if the content is on the page the given number of times" do
@session.should have_css("p", :count => 3)
@session.should have_css("p a#foo", :count => 1)
end
it "should be false if the content is on the page the given number of times" do
@session.should_not have_css("p", :count => 6)
@session.should_not have_css("p a#foo", :count => 2)
end
it "should be false if the content isn't on the page at all" do
@session.should_not have_css("abbr", :count => 2)
@session.should_not have_css("p a.doesnotexist", :count => 1)
end
end
context "with text" do
it "should discard all matches where the given string is not contained" do
@session.should have_css("p a", :text => "Redirect", :count => 1)
@session.should_not have_css("p a", :text => "Doesnotexist")
end
it "should discard all matches where the given regexp is not matched" do
@session.should have_css("p a", :text => /re[dab]i/i, :count => 1)
@session.should_not have_css("p a", :text => /Red$/)
end
it "should respect scopes" do
@session.within "//p[@id='first']" do
@session.should have_css("a#foo")
@session.should_not have_css("a#red")
end
end
describe '#has_no_css?' do
before do
@session.visit('/with_html')
context "with count" do
it "should be true if the content is on the page the given number of times" do
@session.should have_css("p", :count => 3)
@session.should have_css("p a#foo", :count => 1)
end
it "should be false if the given selector is on the page" do
@session.should_not have_no_css("p")
@session.should_not have_no_css("p a#foo")
it "should be false if the content is on the page the given number of times" do
@session.should_not have_css("p", :count => 6)
@session.should_not have_css("p a#foo", :count => 2)
end
it "should be true if the given selector is not on the page" do
@session.should have_no_css("abbr")
@session.should have_no_css("p a#doesnotexist")
@session.should have_no_css("p.nosuchclass")
it "should be false if the content isn't on the page at all" do
@session.should_not have_css("abbr", :count => 2)
@session.should_not have_css("p a.doesnotexist", :count => 1)
end
end
context "with text" do
it "should discard all matches where the given string is not contained" do
@session.should have_css("p a", :text => "Redirect", :count => 1)
@session.should_not have_css("p a", :text => "Doesnotexist")
end
it "should respect scopes" do
@session.within "//p[@id='first']" do
@session.should_not have_no_css("a#foo")
@session.should have_no_css("a#red")
end
end
context "with count" do
it "should be false if the content is on the page the given number of times" do
@session.should_not have_no_css("p", :count => 3)
@session.should_not have_no_css("p a#foo", :count => 1)
end
it "should be true if the content is on the page the given number of times" do
@session.should have_no_css("p", :count => 6)
@session.should have_no_css("p a#foo", :count => 2)
end
it "should be true if the content isn't on the page at all" do
@session.should have_no_css("abbr", :count => 2)
@session.should have_no_css("p a.doesnotexist", :count => 1)
end
end
context "with text" do
it "should discard all matches where the given string is not contained" do
@session.should_not have_no_css("p a", :text => "Redirect", :count => 1)
@session.should have_no_css("p a", :text => "Doesnotexist")
end
it "should discard all matches where the given regexp is not matched" do
@session.should_not have_no_css("p a", :text => /re[dab]i/i, :count => 1)
@session.should have_no_css("p a", :text => /Red$/)
end
it "should discard all matches where the given regexp is not matched" do
@session.should have_css("p a", :text => /re[dab]i/i, :count => 1)
@session.should_not have_css("p a", :text => /Red$/)
end
end
end
end
describe '#has_no_css?' do
before do
@session.visit('/with_html')
end
it "should be false if the given selector is on the page" do
@session.should_not have_no_css("p")
@session.should_not have_no_css("p a#foo")
end
it "should be true if the given selector is not on the page" do
@session.should have_no_css("abbr")
@session.should have_no_css("p a#doesnotexist")
@session.should have_no_css("p.nosuchclass")
end
it "should respect scopes" do
@session.within "//p[@id='first']" do
@session.should_not have_no_css("a#foo")
@session.should have_no_css("a#red")
end
end
context "with count" do
it "should be false if the content is on the page the given number of times" do
@session.should_not have_no_css("p", :count => 3)
@session.should_not have_no_css("p a#foo", :count => 1)
end
it "should be true if the content is on the page the given number of times" do
@session.should have_no_css("p", :count => 6)
@session.should have_no_css("p a#foo", :count => 2)
end
it "should be true if the content isn't on the page at all" do
@session.should have_no_css("abbr", :count => 2)
@session.should have_no_css("p a.doesnotexist", :count => 1)
end
end
context "with text" do
it "should discard all matches where the given string is not contained" do
@session.should_not have_no_css("p a", :text => "Redirect", :count => 1)
@session.should have_no_css("p a", :text => "Doesnotexist")
end
it "should discard all matches where the given regexp is not matched" do
@session.should_not have_no_css("p a", :text => /re[dab]i/i, :count => 1)
@session.should have_no_css("p a", :text => /Red$/)
end
end
end
end

View File

@ -1,115 +1,113 @@
module HasXpathSpec
shared_examples_for "has_xpath" do
describe '#has_xpath?' do
before do
@session.visit('/with_html')
end
shared_examples_for "has_xpath" do
describe '#has_xpath?' do
before do
@session.visit('/with_html')
end
it "should be true if the given selector is on the page" do
@session.should have_xpath("//p")
@session.should have_xpath("//p//a[@id='foo']")
@session.should have_xpath("//p[contains(.,'est')]")
end
it "should be true if the given selector is on the page" do
@session.should have_xpath("//p")
@session.should have_xpath("//p//a[@id='foo']")
@session.should have_xpath("//p[contains(.,'est')]")
end
it "should be false if the given selector is not on the page" do
@session.should_not have_xpath("//abbr")
@session.should_not have_xpath("//p//a[@id='doesnotexist']")
@session.should_not have_xpath("//p[contains(.,'thisstringisnotonpage')]")
end
it "should be false if the given selector is not on the page" do
@session.should_not have_xpath("//abbr")
@session.should_not have_xpath("//p//a[@id='doesnotexist']")
@session.should_not have_xpath("//p[contains(.,'thisstringisnotonpage')]")
end
it "should respect scopes" do
@session.within "//p[@id='first']" do
@session.should have_xpath("//a[@id='foo']")
@session.should_not have_xpath("//a[@id='red']")
end
end
context "with count" do
it "should be true if the content is on the page the given number of times" do
@session.should have_xpath("//p", :count => 3)
@session.should have_xpath("//p//a[@id='foo']", :count => 1)
@session.should have_xpath("//p[contains(.,'est')]", :count => 1)
end
it "should be false if the content is on the page the given number of times" do
@session.should_not have_xpath("//p", :count => 6)
@session.should_not have_xpath("//p//a[@id='foo']", :count => 2)
@session.should_not have_xpath("//p[contains(.,'est')]", :count => 5)
end
it "should be false if the content isn't on the page at all" do
@session.should_not have_xpath("//abbr", :count => 2)
@session.should_not have_xpath("//p//a[@id='doesnotexist']", :count => 1)
end
end
context "with text" do
it "should discard all matches where the given string is not contained" do
@session.should have_xpath("//p//a", :text => "Redirect", :count => 1)
@session.should_not have_xpath("//p", :text => "Doesnotexist")
end
it "should discard all matches where the given regexp is not matched" do
@session.should have_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
@session.should_not have_xpath("//p//a", :text => /Red$/)
end
it "should respect scopes" do
@session.within "//p[@id='first']" do
@session.should have_xpath("//a[@id='foo']")
@session.should_not have_xpath("//a[@id='red']")
end
end
describe '#has_no_xpath?' do
before do
@session.visit('/with_html')
context "with count" do
it "should be true if the content is on the page the given number of times" do
@session.should have_xpath("//p", :count => 3)
@session.should have_xpath("//p//a[@id='foo']", :count => 1)
@session.should have_xpath("//p[contains(.,'est')]", :count => 1)
end
it "should be false if the given selector is on the page" do
@session.should_not have_no_xpath("//p")
@session.should_not have_no_xpath("//p//a[@id='foo']")
@session.should_not have_no_xpath("//p[contains(.,'est')]")
it "should be false if the content is on the page the given number of times" do
@session.should_not have_xpath("//p", :count => 6)
@session.should_not have_xpath("//p//a[@id='foo']", :count => 2)
@session.should_not have_xpath("//p[contains(.,'est')]", :count => 5)
end
it "should be true if the given selector is not on the page" do
@session.should have_no_xpath("//abbr")
@session.should have_no_xpath("//p//a[@id='doesnotexist']")
@session.should have_no_xpath("//p[contains(.,'thisstringisnotonpage')]")
it "should be false if the content isn't on the page at all" do
@session.should_not have_xpath("//abbr", :count => 2)
@session.should_not have_xpath("//p//a[@id='doesnotexist']", :count => 1)
end
end
context "with text" do
it "should discard all matches where the given string is not contained" do
@session.should have_xpath("//p//a", :text => "Redirect", :count => 1)
@session.should_not have_xpath("//p", :text => "Doesnotexist")
end
it "should respect scopes" do
@session.within "//p[@id='first']" do
@session.should_not have_no_xpath("//a[@id='foo']")
@session.should have_no_xpath("//a[@id='red']")
end
end
context "with count" do
it "should be false if the content is on the page the given number of times" do
@session.should_not have_no_xpath("//p", :count => 3)
@session.should_not have_no_xpath("//p//a[@id='foo']", :count => 1)
@session.should_not have_no_xpath("//p[contains(.,'est')]", :count => 1)
end
it "should be true if the content is on the page the wrong number of times" do
@session.should have_no_xpath("//p", :count => 6)
@session.should have_no_xpath("//p//a[@id='foo']", :count => 2)
@session.should have_no_xpath("//p[contains(.,'est')]", :count => 5)
end
it "should be true if the content isn't on the page at all" do
@session.should have_no_xpath("//abbr", :count => 2)
@session.should have_no_xpath("//p//a[@id='doesnotexist']", :count => 1)
end
end
context "with text" do
it "should discard all matches where the given string is contained" do
@session.should_not have_no_xpath("//p//a", :text => "Redirect", :count => 1)
@session.should have_no_xpath("//p", :text => "Doesnotexist")
end
it "should discard all matches where the given regexp is matched" do
@session.should_not have_no_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
@session.should have_no_xpath("//p//a", :text => /Red$/)
end
it "should discard all matches where the given regexp is not matched" do
@session.should have_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
@session.should_not have_xpath("//p//a", :text => /Red$/)
end
end
end
end
describe '#has_no_xpath?' do
before do
@session.visit('/with_html')
end
it "should be false if the given selector is on the page" do
@session.should_not have_no_xpath("//p")
@session.should_not have_no_xpath("//p//a[@id='foo']")
@session.should_not have_no_xpath("//p[contains(.,'est')]")
end
it "should be true if the given selector is not on the page" do
@session.should have_no_xpath("//abbr")
@session.should have_no_xpath("//p//a[@id='doesnotexist']")
@session.should have_no_xpath("//p[contains(.,'thisstringisnotonpage')]")
end
it "should respect scopes" do
@session.within "//p[@id='first']" do
@session.should_not have_no_xpath("//a[@id='foo']")
@session.should have_no_xpath("//a[@id='red']")
end
end
context "with count" do
it "should be false if the content is on the page the given number of times" do
@session.should_not have_no_xpath("//p", :count => 3)
@session.should_not have_no_xpath("//p//a[@id='foo']", :count => 1)
@session.should_not have_no_xpath("//p[contains(.,'est')]", :count => 1)
end
it "should be true if the content is on the page the wrong number of times" do
@session.should have_no_xpath("//p", :count => 6)
@session.should have_no_xpath("//p//a[@id='foo']", :count => 2)
@session.should have_no_xpath("//p[contains(.,'est')]", :count => 5)
end
it "should be true if the content isn't on the page at all" do
@session.should have_no_xpath("//abbr", :count => 2)
@session.should have_no_xpath("//p//a[@id='doesnotexist']", :count => 1)
end
end
context "with text" do
it "should discard all matches where the given string is contained" do
@session.should_not have_no_xpath("//p//a", :text => "Redirect", :count => 1)
@session.should have_no_xpath("//p", :text => "Doesnotexist")
end
it "should discard all matches where the given regexp is matched" do
@session.should_not have_no_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
@session.should have_no_xpath("//p//a", :text => /Red$/)
end
end
end
end

View File

@ -1,61 +1,59 @@
module LocateSpec
shared_examples_for "locate" do
describe '#locate' do
shared_examples_for "locate" do
describe '#locate' do
before do
@session.visit('/with_html')
end
it "should find the first element using the given locator" do
@session.locate('//h1').text.should == 'This is a test'
@session.locate("//input[@id='test_field']")[:value].should == 'monkey'
end
context "with css selectors" do
it "should find the first element using the given locator" do
@session.locate(:css, 'h1').text.should == 'This is a test'
@session.locate(:css, "input[id='test_field']")[:value].should == 'monkey'
end
end
context "with xpath selectors" do
it "should find the first element using the given locator" do
@session.locate(:xpath, '//h1').text.should == 'This is a test'
@session.locate(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
end
end
context "with css as default selector" do
before { Capybara.default_selector = :css }
it "should find the first element using the given locator" do
@session.locate('h1').text.should == 'This is a test'
@session.locate("input[id='test_field']")[:value].should == 'monkey'
end
after { Capybara.default_selector = :xpath }
end
it "should raise ElementNotFound with specified fail message if nothing was found" do
running do
@session.locate(:xpath, '//div[@id="nosuchthing"]', 'arghh').should be_nil
end.should raise_error(Capybara::ElementNotFound, "arghh")
end
it "should accept an XPath instance and respect the order of paths" do
@session.visit('/form')
@xpath = Capybara::XPath.text_field('Name')
@session.locate(@xpath).value.should == 'John Smith'
end
context "within a scope" do
before do
@session.visit('/with_html')
@session.visit('/with_scope')
end
it "should find the first element using the given locator" do
@session.locate('//h1').text.should == 'This is a test'
@session.locate("//input[@id='test_field']")[:value].should == 'monkey'
end
context "with css selectors" do
it "should find the first element using the given locator" do
@session.locate(:css, 'h1').text.should == 'This is a test'
@session.locate(:css, "input[id='test_field']")[:value].should == 'monkey'
end
end
context "with xpath selectors" do
it "should find the first element using the given locator" do
@session.locate(:xpath, '//h1').text.should == 'This is a test'
@session.locate(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
end
end
context "with css as default selector" do
before { Capybara.default_selector = :css }
it "should find the first element using the given locator" do
@session.locate('h1').text.should == 'This is a test'
@session.locate("input[id='test_field']")[:value].should == 'monkey'
end
after { Capybara.default_selector = :xpath }
end
it "should raise ElementNotFound with specified fail message if nothing was found" do
running do
@session.locate(:xpath, '//div[@id="nosuchthing"]', 'arghh').should be_nil
end.should raise_error(Capybara::ElementNotFound, "arghh")
end
it "should accept an XPath instance and respect the order of paths" do
@session.visit('/form')
@xpath = Capybara::XPath.text_field('Name')
@session.locate(@xpath).value.should == 'John Smith'
end
context "within a scope" do
before do
@session.visit('/with_scope')
end
it "should find the first element using the given locator" do
@session.within(:xpath, "//div[@id='for_bar']") do
@session.locate('//li').text.should =~ /With Simple HTML/
end
end
@session.within(:xpath, "//div[@id='for_bar']") do
@session.locate('//li').text.should =~ /With Simple HTML/
end
end
end
end
end
end

View File

@ -1,27 +1,25 @@
module SelectSpec
shared_examples_for "select" do
describe "#select" do
before do
@session.visit('/form')
end
shared_examples_for "select" do
describe "#select" do
before do
@session.visit('/form')
end
it "should select an option from a select box by id" do
@session.select("Finish", :from => 'form_locale')
@session.click_button('awesome')
extract_results(@session)['locale'].should == 'fi'
end
it "should select an option from a select box by id" do
@session.select("Finish", :from => 'form_locale')
@session.click_button('awesome')
extract_results(@session)['locale'].should == 'fi'
end
it "should select an option from a select box by label" do
@session.select("Finish", :from => 'Locale')
@session.click_button('awesome')
extract_results(@session)['locale'].should == 'fi'
end
it "should select an option from a select box by label" do
@session.select("Finish", :from => 'Locale')
@session.click_button('awesome')
extract_results(@session)['locale'].should == 'fi'
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running { @session.select('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running { @session.select('foo', :from => 'does not exist') }.should raise_error(Capybara::ElementNotFound)
end
end
end
end
end

View File

@ -1,29 +1,27 @@
module UncheckSpec
shared_examples_for "uncheck" do
describe "#uncheck" do
before do
@session.visit('/form')
end
shared_examples_for "uncheck" do
describe "#uncheck" do
before do
@session.visit('/form')
end
it "should uncheck a checkbox by id" do
@session.uncheck("form_pets_hamster")
@session.click_button('awesome')
extract_results(@session)['pets'].should include('dog')
extract_results(@session)['pets'].should_not include('hamster')
end
it "should uncheck a checkbox by id" do
@session.uncheck("form_pets_hamster")
@session.click_button('awesome')
extract_results(@session)['pets'].should include('dog')
extract_results(@session)['pets'].should_not include('hamster')
end
it "should uncheck a checkbox by label" do
@session.uncheck("Hamster")
@session.click_button('awesome')
extract_results(@session)['pets'].should include('dog')
extract_results(@session)['pets'].should_not include('hamster')
end
it "should uncheck a checkbox by label" do
@session.uncheck("Hamster")
@session.click_button('awesome')
extract_results(@session)['pets'].should include('dog')
extract_results(@session)['pets'].should_not include('hamster')
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running { @session.uncheck('does not exist') }.should raise_error(Capybara::ElementNotFound)
end
context "with a locator that doesn't exist" do
it "should raise an error" do
running { @session.uncheck('does not exist') }.should raise_error(Capybara::ElementNotFound)
end
end
end
end
end

View File

@ -1,142 +1,140 @@
module WithinSpec
shared_examples_for "within" do
describe '#within' do
before do
shared_examples_for "within" do
describe '#within' do
before do
@session.visit('/with_scope')
end
context "with CSS selector" do
it "should click links in the given scope" do
@session.within(:css, "ul li[contains('With Simple HTML')]") do
@session.click_link('Go')
end
@session.body.should include('Bar')
end
end
context "with XPath selector" do
it "should click links in the given scope" do
@session.within(:xpath, "//li[contains(.,'With Simple HTML')]") do
@session.click_link('Go')
end
@session.body.should include('Bar')
end
end
context "with the default selector" do
it "should use XPath" do
@session.within("//li[contains(., 'With Simple HTML')]") do
@session.click_link('Go')
end
@session.body.should include('Bar')
end
end
context "with the default selector set to CSS" do
before { Capybara.default_selector = :css }
it "should use CSS" do
@session.within("ul li[contains('With Simple HTML')]") do
@session.click_link('Go')
end
@session.body.should include('Bar')
end
after { Capybara.default_selector = :xpath }
end
context "with click_link" do
it "should click links in the given scope" do
@session.within("//li[contains(.,'With Simple HTML')]") do
@session.click_link('Go')
end
@session.body.should include('Bar')
end
context "with nested scopes" do
it "should respect the inner scope" do
@session.within("//div[@id='for_bar']") do
@session.within("//li[contains(.,'Bar')]") do
@session.click_link('Go')
end
end
@session.body.should include('Another World')
end
it "should respect the outer scope" do
@session.within("//div[@id='another_foo']") do
@session.within("//li[contains(.,'With Simple HTML')]") do
@session.click_link('Go')
end
end
@session.body.should include('Hello world')
end
end
it "should raise an error if the scope is not found on the page" do
running {
@session.within("//div[@id='doesnotexist']") do
end
}.should raise_error(Capybara::ElementNotFound)
end
end
context "with forms" do
it "should fill in a field and click a button" do
@session.within("//li[contains(.,'Bar')]") do
@session.click_button('Go')
end
extract_results(@session)['first_name'].should == 'Peter'
@session.visit('/with_scope')
end
context "with CSS selector" do
it "should click links in the given scope" do
@session.within(:css, "ul li[contains('With Simple HTML')]") do
@session.click_link('Go')
end
@session.body.should include('Bar')
@session.within("//li[contains(.,'Bar')]") do
@session.fill_in('First Name', :with => 'Dagobert')
@session.click_button('Go')
end
end
context "with XPath selector" do
it "should click links in the given scope" do
@session.within(:xpath, "//li[contains(.,'With Simple HTML')]") do
@session.click_link('Go')
end
@session.body.should include('Bar')
end
end
context "with the default selector" do
it "should use XPath" do
@session.within("//li[contains(., 'With Simple HTML')]") do
@session.click_link('Go')
end
@session.body.should include('Bar')
end
end
context "with the default selector set to CSS" do
before { Capybara.default_selector = :css }
it "should use CSS" do
@session.within("ul li[contains('With Simple HTML')]") do
@session.click_link('Go')
end
@session.body.should include('Bar')
end
after { Capybara.default_selector = :xpath }
end
context "with click_link" do
it "should click links in the given scope" do
@session.within("//li[contains(.,'With Simple HTML')]") do
@session.click_link('Go')
end
@session.body.should include('Bar')
end
context "with nested scopes" do
it "should respect the inner scope" do
@session.within("//div[@id='for_bar']") do
@session.within("//li[contains(.,'Bar')]") do
@session.click_link('Go')
end
end
@session.body.should include('Another World')
end
it "should respect the outer scope" do
@session.within("//div[@id='another_foo']") do
@session.within("//li[contains(.,'With Simple HTML')]") do
@session.click_link('Go')
end
end
@session.body.should include('Hello world')
end
end
it "should raise an error if the scope is not found on the page" do
running {
@session.within("//div[@id='doesnotexist']") do
end
}.should raise_error(Capybara::ElementNotFound)
end
end
context "with forms" do
it "should fill in a field and click a button" do
@session.within("//li[contains(.,'Bar')]") do
@session.click_button('Go')
end
extract_results(@session)['first_name'].should == 'Peter'
@session.visit('/with_scope')
@session.within("//li[contains(.,'Bar')]") do
@session.fill_in('First Name', :with => 'Dagobert')
@session.click_button('Go')
end
extract_results(@session)['first_name'].should == 'Dagobert'
end
end
end
describe '#within_fieldset' do
before do
@session.visit('/fieldsets')
end
it "should restrict scope to a fieldset given by id" do
@session.within_fieldset("villain_fieldset") do
@session.fill_in("Name", :with => 'Goldfinger')
@session.click_button("Create")
end
extract_results(@session)['villain_name'].should == 'Goldfinger'
end
it "should restrict scope to a fieldset given by legend" do
@session.within_fieldset("Villain") do
@session.fill_in("Name", :with => 'Goldfinger')
@session.click_button("Create")
end
extract_results(@session)['villain_name'].should == 'Goldfinger'
end
end
describe '#within_table' do
before do
@session.visit('/tables')
end
it "should restrict scope to a fieldset given by id" do
@session.within_table("girl_table") do
@session.fill_in("Name", :with => 'Christmas')
@session.click_button("Create")
end
extract_results(@session)['girl_name'].should == 'Christmas'
end
it "should restrict scope to a fieldset given by legend" do
@session.within_table("Villain") do
@session.fill_in("Name", :with => 'Quantum')
@session.click_button("Create")
end
extract_results(@session)['villain_name'].should == 'Quantum'
extract_results(@session)['first_name'].should == 'Dagobert'
end
end
end
end
describe '#within_fieldset' do
before do
@session.visit('/fieldsets')
end
it "should restrict scope to a fieldset given by id" do
@session.within_fieldset("villain_fieldset") do
@session.fill_in("Name", :with => 'Goldfinger')
@session.click_button("Create")
end
extract_results(@session)['villain_name'].should == 'Goldfinger'
end
it "should restrict scope to a fieldset given by legend" do
@session.within_fieldset("Villain") do
@session.fill_in("Name", :with => 'Goldfinger')
@session.click_button("Create")
end
extract_results(@session)['villain_name'].should == 'Goldfinger'
end
end
describe '#within_table' do
before do
@session.visit('/tables')
end
it "should restrict scope to a fieldset given by id" do
@session.within_table("girl_table") do
@session.fill_in("Name", :with => 'Christmas')
@session.click_button("Create")
end
extract_results(@session)['girl_name'].should == 'Christmas'
end
it "should restrict scope to a fieldset given by legend" do
@session.within_table("Villain") do
@session.fill_in("Name", :with => 'Quantum')
@session.click_button("Create")
end
extract_results(@session)['villain_name'].should == 'Quantum'
end
end
end

View File

@ -10,7 +10,6 @@ require 'drivers_spec'
require 'session_spec'
Dir[File.dirname(__FILE__)+'/dsl/*'].each { |group|
require group
include Object.const_get(group.match(/.*[\/]{1}([\w]*)[.rb]./).captures.first.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase })
}
require 'session_with_javascript_support_spec'
require 'session_without_javascript_support_spec'