Use expect..to instead of the `running` alias

This commit is contained in:
Jonas Nicklas 2012-10-30 14:26:19 +01:00
parent 875081fe56
commit 7e4d3b85f5
20 changed files with 71 additions and 73 deletions

View File

@ -12,7 +12,7 @@ Capybara::SpecHelper.spec "#attach_file" do
@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')
@ -55,14 +55,14 @@ Capybara::SpecHelper.spec "#attach_file" do
@session.click_button 'Upload Single'
@session.should have_content('image/jpeg')
end
it "should not break when using HTML5 multiple file input" do
@session.attach_file "Multiple Documents", @test_file_path
@session.click_button('Upload Multiple')
@session.body.should include("1 | ")#number of files
@session.should have_content(File.read(@test_file_path))
end
it "should not break when using HTML5 multiple file input uploading multiple files" do
pending "Selenium is buggy on this, see http://code.google.com/p/selenium/issues/detail?id=2239" if @session.respond_to?(:mode) && @session.mode == :selenium
@session.attach_file "Multiple Documents", [@test_file_path, @another_test_file_path]
@ -76,15 +76,15 @@ Capybara::SpecHelper.spec "#attach_file" do
context "with a locator that doesn't exist" do
it "should raise an error" do
msg = "Unable to find file field \"does not exist\""
running do
expect do
@session.attach_file('does not exist', @test_file_path)
end.should raise_error(Capybara::ElementNotFound, msg)
end.to raise_error(Capybara::ElementNotFound, msg)
end
end
context "with a path that doesn't exist" do
it "should raise an error" do
running { @session.attach_file('Image', '/no_such_file.png') }.should raise_error(Capybara::FileNotFound)
expect { @session.attach_file('Image', '/no_such_file.png') }.to raise_error(Capybara::FileNotFound)
end
end
end

View File

@ -69,17 +69,17 @@ Capybara::SpecHelper.spec "#check" do
context "with a locator that doesn't exist" do
it "should raise an error" do
msg = "Unable to find checkbox \"does not exist\""
running do
expect do
@session.check('does not exist')
end.should raise_error(Capybara::ElementNotFound, msg)
end.to raise_error(Capybara::ElementNotFound, msg)
end
end
context "with a disabled checkbox" do
it "should raise an error" do
running do
expect do
@session.check('Disabled Checkbox')
end.should raise_error(Capybara::ElementNotFound)
end.to raise_error(Capybara::ElementNotFound)
end
end
end

View File

@ -24,17 +24,17 @@ Capybara::SpecHelper.spec "#choose" do
context "with a locator that doesn't exist" do
it "should raise an error" do
msg = "Unable to find radio button \"does not exist\""
running do
expect do
@session.choose('does not exist')
end.should raise_error(Capybara::ElementNotFound, msg)
end.to raise_error(Capybara::ElementNotFound, msg)
end
end
context "with a disabled radio button" do
it "should raise an error" do
running do
expect do
@session.choose('Disabled Radio')
end.should raise_error(Capybara::ElementNotFound)
end.to raise_error(Capybara::ElementNotFound)
end
end
end

View File

@ -258,9 +258,9 @@ Capybara::SpecHelper.spec '#click_button' do
context "with a locator that doesn't exist" do
it "should raise an error" do
msg = "Unable to find button \"does not exist\""
running do
expect do
@session.click_button('does not exist')
end.should raise_error(Capybara::ElementNotFound, msg)
end.to raise_error(Capybara::ElementNotFound, msg)
end
end

View File

@ -39,9 +39,9 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
it "should raise an error" do
@session.visit('/with_html')
msg = "Unable to find link or button \"does not exist\""
running do
expect do
@session.click_link_or_button('does not exist')
end.should raise_error(Capybara::ElementNotFound, msg)
end.to raise_error(Capybara::ElementNotFound, msg)
end
end
end

View File

@ -60,9 +60,9 @@ Capybara::SpecHelper.spec '#click_link' do
context "with a locator that doesn't exist" do
it "should raise an error" do
msg = "Unable to find link \"does not exist\""
running do
expect do
@session.click_link('does not exist')
end.should raise_error(Capybara::ElementNotFound, msg)
end.to raise_error(Capybara::ElementNotFound, msg)
end
end
@ -112,8 +112,8 @@ Capybara::SpecHelper.spec '#click_link' do
end
it "raise an error with links with no href" do
running do
expect do
@session.click_link('No Href')
end.should raise_error(Capybara::ElementNotFound)
end.to raise_error(Capybara::ElementNotFound)
end
end

View File

@ -116,26 +116,26 @@ Capybara::SpecHelper.spec "#fill_in" do
after { Capybara.ignore_hidden_elements = false }
it "should not find a hidden field" do
msg = "Unable to find field \"Super Secret\""
running do
expect do
@session.fill_in('Super Secret', :with => '777')
end.should raise_error(Capybara::ElementNotFound, msg)
end.to raise_error(Capybara::ElementNotFound, msg)
end
end
context "with a locator that doesn't exist" do
it "should raise an error" do
msg = "Unable to find field \"does not exist\""
running do
expect do
@session.fill_in('does not exist', :with => 'Blah blah')
end.should raise_error(Capybara::ElementNotFound, msg)
end.to raise_error(Capybara::ElementNotFound, msg)
end
end
context "on a disabled field" do
it "should raise an error" do
running do
expect do
@session.fill_in('Disabled Text Field', :with => 'Blah blah')
end.should raise_error(Capybara::ElementNotFound)
end.to raise_error(Capybara::ElementNotFound)
end
end
end

View File

@ -13,8 +13,8 @@ Capybara::SpecHelper.spec '#find_button' do
end
it "should raise error if the button doesn't exist" do
running do
expect do
@session.find_button('Does not exist')
end.should raise_error(Capybara::ElementNotFound)
end.to raise_error(Capybara::ElementNotFound)
end
end

View File

@ -13,8 +13,8 @@ Capybara::SpecHelper.spec '#find_by_id' do
end
it "should raise error if no element with id is found" do
running do
expect do
@session.find_by_id('nothing_with_this_id')
end.should raise_error(Capybara::ElementNotFound)
end.to raise_error(Capybara::ElementNotFound)
end
end

View File

@ -14,15 +14,15 @@ Capybara::SpecHelper.spec '#find_field' do
end
it "should raise error if the field doesn't exist" do
running do
expect do
@session.find_field('Does not exist')
end.should raise_error(Capybara::ElementNotFound)
end.to raise_error(Capybara::ElementNotFound)
end
it "should be aliased as 'field_labeled' for webrat compatibility" do
@session.field_labeled('Dog').value.should == 'dog'
running do
expect do
@session.field_labeled('Does not exist')
end.should raise_error(Capybara::ElementNotFound)
end.to raise_error(Capybara::ElementNotFound)
end
end

View File

@ -13,8 +13,8 @@ Capybara::SpecHelper.spec '#find_link' do
end
it "should raise error if the field doesn't exist" do
running do
expect do
@session.find_link('Does not exist')
end.should raise_error(Capybara::ElementNotFound)
end.to raise_error(Capybara::ElementNotFound)
end
end

View File

@ -102,9 +102,9 @@ Capybara::SpecHelper.spec '#find' do
end
it "should raise ElementNotFound with a useful default message if nothing was found" do
running do
@session.find(:xpath, '//div[@id="nosuchthing"]').should be_nil
end.should raise_error(Capybara::ElementNotFound, "Unable to find xpath \"//div[@id=\\\"nosuchthing\\\"]\"")
expect do
@session.find(:xpath, '//div[@id="nosuchthing"]').to be_nil
end.to raise_error(Capybara::ElementNotFound, "Unable to find xpath \"//div[@id=\\\"nosuchthing\\\"]\"")
end
it "should accept an XPath instance" do

View File

@ -154,7 +154,7 @@ Capybara::SpecHelper.spec "node" do
node = @session.find(:css, '#reload-me')
@session.click_link('Reload!')
sleep(0.3)
running { node.text.should == 'has been reloaded' }.should raise_error
expect { node.text.to == 'has been reloaded' }.to raise_error
end
after { Capybara.automatic_reload = true }
end
@ -189,8 +189,8 @@ Capybara::SpecHelper.spec "node" do
node = @session.all(:css, '#the-list li')[1]
@session.click_link('Fetch new list!')
sleep(0.3)
running { node.text.should == 'Foo' }.should raise_error
running { node.text.should == 'Bar' }.should raise_error
expect { node.text.to == 'Foo' }.to raise_error
expect { node.text.to == 'Bar' }.to raise_error
end
it "should reload nodes with options" do

View File

@ -62,26 +62,26 @@ Capybara::SpecHelper.spec "#select" do
context "with a locator that doesn't exist" do
it "should raise an error" do
msg = "Unable to find select box \"does not exist\""
running do
expect do
@session.select('foo', :from => 'does not exist')
end.should raise_error(Capybara::ElementNotFound, msg)
end.to raise_error(Capybara::ElementNotFound, msg)
end
end
context "with an option that doesn't exist" do
it "should raise an error" do
msg = "Unable to find option \"Does not Exist\""
running do
expect do
@session.select('Does not Exist', :from => 'form_locale')
end.should raise_error(Capybara::ElementNotFound, msg)
end.to raise_error(Capybara::ElementNotFound, msg)
end
end
context "on a disabled select" do
it "should raise an error" do
running do
expect do
@session.select('Should not see me', :from => 'Disabled Select')
end.should raise_error(Capybara::ElementNotFound)
end.to raise_error(Capybara::ElementNotFound)
end
end

View File

@ -48,25 +48,25 @@ Capybara::SpecHelper.spec "#unselect" do
context "with single select" do
it "should raise an error" do
running { @session.unselect("English", :from => 'form_locale') }.should raise_error(Capybara::UnselectNotAllowed)
expect { @session.unselect("English", :from => 'form_locale') }.to raise_error(Capybara::UnselectNotAllowed)
end
end
context "with a locator that doesn't exist" do
it "should raise an error" do
msg = "Unable to find select box \"does not exist\""
running do
expect do
@session.unselect('foo', :from => 'does not exist')
end.should raise_error(Capybara::ElementNotFound, msg)
end.to raise_error(Capybara::ElementNotFound, msg)
end
end
context "with an option that doesn't exist" do
it "should raise an error" do
msg = "Unable to find option \"Does not Exist\""
running do
expect do
@session.unselect('Does not Exist', :from => 'form_underwear')
end.should raise_error(Capybara::ElementNotFound, msg)
end.to raise_error(Capybara::ElementNotFound, msg)
end
end
end

View File

@ -87,23 +87,23 @@ Capybara::SpecHelper.spec '#within' do
end
it "should raise an error if the scope is not found on the page" do
running do
expect do
@session.within("//div[@id='doesnotexist']") do
end
end.should raise_error(Capybara::ElementNotFound)
end.to raise_error(Capybara::ElementNotFound)
end
it "should restore the scope when an error is raised" do
running do
expect do
@session.within("//div[@id='for_bar']") do
running do
running do
expect do
expect do
@session.within(".//div[@id='doesnotexist']") do
end
end.should raise_error(Capybara::ElementNotFound)
end.should_not change { @session.has_xpath?(".//div[@id='another_foo']") }.from(false)
end.to raise_error(Capybara::ElementNotFound)
end.to_not change { @session.has_xpath?(".//div[@id='another_foo']") }.from(false)
end
end.should_not change { @session.has_xpath?(".//div[@id='another_foo']") }.from(true)
end.to_not change { @session.has_xpath?(".//div[@id='another_foo']") }.from(true)
end
it "should fill in a field and click a button" do

View File

@ -47,9 +47,9 @@ end
describe Capybara::Session do
context 'with non-existant driver' do
it "should raise an error" do
running {
expect {
Capybara::Session.new(:quox, TestApp).driver
}.should raise_error(Capybara::DriverNotFoundError)
}.to raise_error(Capybara::DriverNotFoundError)
end
end
end

View File

@ -127,9 +127,9 @@ describe Capybara::RackTest::Driver do
end
it "should not follow more than 6 redirects" do
running do
expect do
@driver.visit("/redirect/6/times")
end.should raise_error(Capybara::InfiniteRedirectError)
end.to raise_error(Capybara::InfiniteRedirectError)
end
end
@ -144,9 +144,9 @@ describe Capybara::RackTest::Driver do
end
it "should not follow more than 21 redirects" do
running do
expect do
@driver.visit("/redirect/22/times")
end.should raise_error(Capybara::InfiniteRedirectError)
end.to raise_error(Capybara::InfiniteRedirectError)
end
end
end

View File

@ -12,9 +12,9 @@ describe Capybara::Server do
end
it "should do nothing when no server given" do
running do
expect do
@server = Capybara::Server.new(nil).boot
end.should_not raise_error
end.not_to raise_error
end
it "should bind to the specified host" do

View File

@ -26,8 +26,6 @@ end
require 'capybara/spec/spec_helper'
alias :running :lambda
module TestSessions
RackTest = Capybara::Session.new(:rack_test, TestApp)
Selenium = Capybara::Session.new(:selenium, TestApp)