diff --git a/.travis.yml b/.travis.yml index f86c6f711..9034d7228 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,12 +9,18 @@ gemfile: - Gemfile - gemfiles/Gemfile.base-versions matrix: + include: + - gemfile: gemfiles/Gemfile.beta-versions + rvm: 2.1.1 exclude: # Nokogiri 1.3.3 is not compatible with Rubinius or JRuby - gemfile: gemfiles/Gemfile.base-versions rvm: rbx - gemfile: gemfiles/Gemfile.base-versions rvm: jruby-19mode + allow_failures: + - gemfile: gemfiles/Gemfile.beta-versions + rvm: 2.1.1 before_install: - CHROMEDRIVER_VERSION=$(wget -q -O - http://chromedriver.storage.googleapis.com/LATEST_RELEASE) - CHROMEDRIVER_URL="http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip" diff --git a/README.md b/README.md index fd21b4166..46ff417fb 100644 --- a/README.md +++ b/README.md @@ -343,7 +343,7 @@ You can get the [current path](http://rubydoc.info/github/jnicklas/capybara/mast of the browsing session for test assertions: ```ruby -current_path.should == post_comments_path(post) +expect(current_path).to eq(post_comments_path(post)) ``` ### Clicking links and buttons @@ -400,12 +400,12 @@ has_selector?`. Read the section on asynchronous JavaScript for an explanation. You can use these with RSpec's magic matchers: ```ruby -page.should have_selector('table tr') -page.should have_selector(:xpath, '//table/tr') +expect(page).to have_selector('table tr') +expect(page).to have_selector(:xpath, '//table/tr') -page.should have_xpath('//table/tr') -page.should have_css('table tr.foo') -page.should have_content('foo') +expect(page).to have_xpath('//table/tr') +expect(page).to have_css('table tr.foo') +expect(page).to have_content('foo') ``` ### Finding @@ -432,7 +432,7 @@ to specific parts of the page: ```ruby find('#navigation').click_link('Home') -find('#navigation').should have_button('Sign out') +expect(find('#navigation')).to have_button('Sign out') ``` ### Scoping @@ -595,7 +595,7 @@ When issuing instructions to the DSL such as: ```ruby click_link('foo') click_link('bar') -page.should have_content('baz') +expect(page).to have_content('baz') ``` If clicking on the *foo* link triggers an asynchronous process, such as @@ -627,15 +627,15 @@ Capybara's Rspec matchers, however, are smart enough to handle either form. The two following statements are functionally equivalent: ```ruby -page.should_not have_xpath('a') -page.should have_no_xpath('a') +expect(page).not_to have_xpath('a') +expect(page).to have_no_xpath('a') ``` Capybara's waiting behaviour is quite advanced, and can deal with situations such as the following line of code: ```ruby -find('#sidebar').find('h1').should have_content('Something') +expect(find('#sidebar').find('h1')).to have_content('Something') ``` Even if JavaScript causes `#sidebar` to disappear off the page, Capybara diff --git a/features/step_definitions/capybara_steps.rb b/features/step_definitions/capybara_steps.rb index a25a5700f..994dd7cbe 100644 --- a/features/step_definitions/capybara_steps.rb +++ b/features/step_definitions/capybara_steps.rb @@ -3,22 +3,22 @@ end Then /^I should see "([^"]*)"$/ do |text| - page.should have_content(text) + expect(page).to have_content(text) end Then /^Capybara should use the "([^"]*)" driver$/ do |driver| - Capybara.current_driver.should == driver.to_sym + expect(Capybara.current_driver).to eq(driver.to_sym) end When /^I use a matcher that fails$/ do begin - page.should have_css('h1#doesnotexist') + expect(page).to have_css('h1#doesnotexist') rescue StandardError => e @error_message = e.message end end Then /^the failing exception should be nice$/ do - @error_message.should =~ %r(expected to find css \"h1#doesnotexist\") + expect(@error_message).to match %r(expected to find css \"h1#doesnotexist\") end diff --git a/gemfiles/Gemfile.base-versions b/gemfiles/Gemfile.base-versions index 036e04eda..ed84e8527 100644 --- a/gemfiles/Gemfile.base-versions +++ b/gemfiles/Gemfile.base-versions @@ -9,6 +9,7 @@ gem 'rack', '= 1.3.0' # cannot go lower because referer tests need aa7ce77cd0 gem 'rack-test', '= 0.5.4' gem 'nokogiri', '= 1.3.3' gem 'rspec', '= 2.2.0' +gem 'fuubar', '>= 0.0.1' gem 'cucumber', '= 0.10.5' # We cannot test against older versions of selenium-webdriver without # installing older compatible Firefox versions. diff --git a/gemfiles/Gemfile.beta-versions b/gemfiles/Gemfile.beta-versions new file mode 100644 index 000000000..f018fc863 --- /dev/null +++ b/gemfiles/Gemfile.beta-versions @@ -0,0 +1,9 @@ +source "https://rubygems.org" + +gem 'bundler', '~> 1.0' +gemspec :path => '..' + +gem 'xpath', :git => 'git://github.com/jnicklas/xpath.git' + +gem 'rspec', '>= 3.0.0.beta2' +gem 'fuubar', '>= 2.0.0.beta1' diff --git a/lib/capybara.rb b/lib/capybara.rb index 3f23a9b20..63581138a 100644 --- a/lib/capybara.rb +++ b/lib/capybara.rb @@ -86,7 +86,7 @@ def register_driver(name, &block) # find(:row, 3) # page.find('table#myTable').find(:row, 3).text # page.find('table#myTable').has_selector?(:row, 3) - # within(:row, 3) { page.should have_content('$100.000') } + # within(:row, 3) { expect(page).to have_content('$100.000') } # # Here is another example: # diff --git a/lib/capybara/rspec.rb b/lib/capybara/rspec.rb index f3bc2cad9..cba5009d7 100644 --- a/lib/capybara/rspec.rb +++ b/lib/capybara/rspec.rb @@ -29,3 +29,4 @@ end end end + diff --git a/lib/capybara/session.rb b/lib/capybara/session.rb index 01f3b2eaf..495935f34 100644 --- a/lib/capybara/session.rb +++ b/lib/capybara/session.rb @@ -19,7 +19,7 @@ module Capybara # # session.fill_in('q', :with => 'Capybara') # session.click_button('Search') - # session.should have_content('Capybara') + # expect(session).to have_content('Capybara') # # When using capybara/dsl, the Session is initialized automatically for you. # diff --git a/lib/capybara/spec/session/all_spec.rb b/lib/capybara/spec/session/all_spec.rb index 50d6b35a8..7c9ceb7df 100644 --- a/lib/capybara/spec/session/all_spec.rb +++ b/lib/capybara/spec/session/all_spec.rb @@ -4,20 +4,20 @@ 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' + expect(@session.all('//p').size).to eq(3) + expect(@session.all('//h1').first.text).to eq('This is a test') + expect(@session.all("//input[@id='test_field']").first[:value]).to eq('monkey') end it "should return an empty array when nothing was found" do - @session.all('//div[@id="nosuchthing"]').should be_empty + expect(@session.all('//div[@id="nosuchthing"]')).to be_empty end it "should accept an XPath instance" do @session.visit('/form') @xpath = XPath::HTML.fillable_field('Name') @result = @session.all(@xpath).map { |r| r.value } - @result.should include('Smith', 'John', 'John Smith') + expect(@result).to include('Smith', 'John', 'John Smith') end it "should raise an error when given invalid options" do @@ -26,44 +26,44 @@ context "with css selectors" do it "should find all elements using the given selector" do - @session.all(:css, 'h1').first.text.should == 'This is a test' - @session.all(:css, "input[id='test_field']").first[:value].should == 'monkey' + expect(@session.all(:css, 'h1').first.text).to eq('This is a test') + expect(@session.all(:css, "input[id='test_field']").first[:value]).to eq('monkey') end it "should find all elements when given a list of selectors" do - @session.all(:css, 'h1, p').should have(4).elements + expect(@session.all(:css, 'h1, p').size).to eq(4) 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' + expect(@session.all(:xpath, '//h1').first.text).to eq('This is a test') + expect(@session.all(:xpath, "//input[@id='test_field']").first[:value]).to eq('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' + expect(@session.all('h1').first.text).to eq('This is a test') + expect(@session.all("input[id='test_field']").first[:value]).to eq('monkey') end end context "with visible filter" do it "should only find visible nodes when true" do - @session.all(:css, "a.simple", :visible => true).should have(1).elements + expect(@session.all(:css, "a.simple", :visible => true).size).to eq(1) end it "should find nodes regardless of whether they are invisible when false" do - @session.all(:css, "a.simple", :visible => false).should have(2).elements + expect(@session.all(:css, "a.simple", :visible => false).size).to eq(2) end it "should default to Capybara.ignore_hidden_elements" do Capybara.ignore_hidden_elements = true - @session.all(:css, "a.simple").should have(1).elements + expect(@session.all(:css, "a.simple").size).to eq(1) Capybara.ignore_hidden_elements = false - @session.all(:css, "a.simple").should have(2).elements + expect(@session.all(:css, "a.simple").size).to eq(2) end end @@ -145,7 +145,7 @@ 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 + expect(@session.all('.//li').size).to eq(2) end end end diff --git a/lib/capybara/spec/session/assert_selector.rb b/lib/capybara/spec/session/assert_selector.rb index 6590bbb94..7b6cdc8d0 100644 --- a/lib/capybara/spec/session/assert_selector.rb +++ b/lib/capybara/spec/session/assert_selector.rb @@ -72,7 +72,7 @@ Capybara::SpecHelper.spec '#refute_selector' do it "should be an alias of #assert_no_selector" do - Capybara::Node::Matchers.instance_method(:refute_selector).should == Capybara::Node::Matchers.instance_method(:assert_no_selector) + expect(Capybara::Node::Matchers.instance_method(:refute_selector)).to eq Capybara::Node::Matchers.instance_method(:assert_no_selector) end end diff --git a/lib/capybara/spec/session/attach_file_spec.rb b/lib/capybara/spec/session/attach_file_spec.rb index ab8bb3484..13bc7e512 100644 --- a/lib/capybara/spec/session/attach_file_spec.rb +++ b/lib/capybara/spec/session/attach_file_spec.rb @@ -10,19 +10,19 @@ 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__) + expect(extract_results(@session)['image']).to eq(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__) + expect(extract_results(@session)['image']).to eq(File.basename(__FILE__)) end it "casts to string" do @session.attach_file :"form_image", __FILE__ @session.click_button('awesome') - extract_results(@session)['image'].should == File.basename(__FILE__) + expect(extract_results(@session)['image']).to eq(File.basename(__FILE__)) end end @@ -30,51 +30,51 @@ it "should set a file path by id" do @session.attach_file "form_document", @test_file_path @session.click_button('Upload Single') - @session.should have_content(File.read(@test_file_path)) + expect(@session).to have_content(File.read(@test_file_path)) end it "should set a file path by label" do @session.attach_file "Single Document", @test_file_path @session.click_button('Upload Single') - @session.should have_content(File.read(@test_file_path)) + expect(@session).to have_content(File.read(@test_file_path)) end it "should not break if no file is submitted" do @session.click_button('Upload Single') - @session.should have_content('No file uploaded') + expect(@session).to have_content('No file uploaded') end it "should send content type text/plain when uploading a text file" do @session.attach_file "Single Document", @test_file_path @session.click_button 'Upload Single' - @session.should have_content('text/plain') + expect(@session).to have_content('text/plain') end it "should send content type image/jpeg when uploading an image" do @session.attach_file "Single Document", @test_jpg_file_path @session.click_button 'Upload Single' - @session.should have_content('image/jpeg') + expect(@session).to 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)) + expect(@session.body).to include("1 | ")#number of files + expect(@session).to 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.to_s =~ /^selenium/ @session.attach_file "Multiple Documents", [@test_file_path, @another_test_file_path] @session.click_button('Upload Multiple') - @session.body.should include("2 | ")#number of files - @session.body.should include(File.read(@test_file_path)) - @session.body.should include(File.read(@another_test_file_path)) + expect(@session.body).to include("2 | ")#number of files + expect(@session.body).to include(File.read(@test_file_path)) + expect(@session.body).to include(File.read(@another_test_file_path)) end it "should not send anything when attaching no files to a multiple upload field" do @session.click_button('Upload Empty Multiple') - @session.body.should include("Successfully ignored empty file field") + expect(@session.body).to include("Successfully ignored empty file field") end end @@ -97,7 +97,7 @@ it "should set a file path by partial label when false" do @session.attach_file "Imag", __FILE__, :exact => false @session.click_button('awesome') - extract_results(@session)['image'].should == File.basename(__FILE__) + expect(extract_results(@session)['image']).to eq(File.basename(__FILE__)) end it "not allow partial matches when true" do diff --git a/lib/capybara/spec/session/body_spec.rb b/lib/capybara/spec/session/body_spec.rb index fe5b47ac9..9073cb672 100644 --- a/lib/capybara/spec/session/body_spec.rb +++ b/lib/capybara/spec/session/body_spec.rb @@ -1,20 +1,20 @@ Capybara::SpecHelper.spec '#body' do it "should return the unmodified page body" do @session.visit('/') - @session.should have_content('Hello world!') # wait for content to appear if visit is async - @session.body.should include('Hello world!') + expect(@session).to have_content('Hello world!') # wait for content to appear if visit is async + expect(@session.body).to include('Hello world!') end if "".respond_to?(:encoding) context "encoding of response between ascii and utf8" do it "should be valid with html entities" do @session.visit('/with_html_entities') - lambda { @session.body.encode!("UTF-8") }.should_not raise_error + expect { @session.body.encode!("UTF-8") }.not_to raise_error end it "should be valid without html entities" do @session.visit('/with_html') - lambda { @session.body.encode!("UTF-8") }.should_not raise_error + expect { @session.body.encode!("UTF-8") }.not_to raise_error end end end diff --git a/lib/capybara/spec/session/check_spec.rb b/lib/capybara/spec/session/check_spec.rb index 30d38fb13..bee1219ca 100644 --- a/lib/capybara/spec/session/check_spec.rb +++ b/lib/capybara/spec/session/check_spec.rb @@ -6,64 +6,64 @@ describe "'checked' attribute" do it "should be true if checked" do @session.check("Terms of Use") - @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_true + expect(@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked']).to be_truthy end it "should be false if unchecked" do - @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_false + expect(@session.find(:xpath, "//input[@id='form_terms_of_use']")['checked']).to be_falsey end end it "should trigger associated events", :requires => [:js] do @session.visit('/with_js') @session.check('checkbox_with_event') - @session.should have_css('#checkbox_event_triggered'); + expect(@session).to have_css('#checkbox_event_triggered'); end describe "checking" do it "should not change an already checked checkbox" do - @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true + expect(@session.find(:xpath, "//input[@id='form_pets_dog']")['checked']).to be_truthy @session.check('form_pets_dog') - @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true + expect(@session.find(:xpath, "//input[@id='form_pets_dog']")['checked']).to be_truthy end it "should check an unchecked checkbox" do - @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false + expect(@session.find(:xpath, "//input[@id='form_pets_cat']")['checked']).to be_falsey @session.check('form_pets_cat') - @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_true + expect(@session.find(:xpath, "//input[@id='form_pets_cat']")['checked']).to be_truthy end end describe "unchecking" do it "should not change an already unchecked checkbox" do - @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false + expect(@session.find(:xpath, "//input[@id='form_pets_cat']")['checked']).to be_falsey @session.uncheck('form_pets_cat') - @session.find(:xpath, "//input[@id='form_pets_cat']")['checked'].should be_false + expect(@session.find(:xpath, "//input[@id='form_pets_cat']")['checked']).to be_falsey end it "should uncheck a checked checkbox" do - @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_true + expect(@session.find(:xpath, "//input[@id='form_pets_dog']")['checked']).to be_truthy @session.uncheck('form_pets_dog') - @session.find(:xpath, "//input[@id='form_pets_dog']")['checked'].should be_false + expect(@session.find(:xpath, "//input[@id='form_pets_dog']")['checked']).to be_falsey end end it "should check a checkbox by id" do @session.check("form_pets_cat") @session.click_button('awesome') - extract_results(@session)['pets'].should include('dog', 'cat', 'hamster') + expect(extract_results(@session)['pets']).to include('dog', 'cat', 'hamster') end it "should check a checkbox by label" do @session.check("Cat") @session.click_button('awesome') - extract_results(@session)['pets'].should include('dog', 'cat', 'hamster') + expect(extract_results(@session)['pets']).to include('dog', 'cat', 'hamster') end it "casts to string" do @session.check(:"form_pets_cat") @session.click_button('awesome') - extract_results(@session)['pets'].should include('dog', 'cat', 'hamster') + expect(extract_results(@session)['pets']).to include('dog', 'cat', 'hamster') end context "with a locator that doesn't exist" do @@ -87,7 +87,7 @@ it "should accept partial matches when false" do @session.check('Ham', :exact => false) @session.click_button('awesome') - extract_results(@session)['pets'].should include('hamster') + expect(extract_results(@session)['pets']).to include('hamster') end it "should not accept partial matches when true" do @@ -101,7 +101,7 @@ it "can check boxes by their value" do @session.check('form[pets][]', :option => "cat") @session.click_button('awesome') - extract_results(@session)['pets'].should include('cat') + expect(extract_results(@session)['pets']).to include('cat') end it "should raise an error if option not found" do diff --git a/lib/capybara/spec/session/choose_spec.rb b/lib/capybara/spec/session/choose_spec.rb index 8cbf77d62..4959b64d3 100644 --- a/lib/capybara/spec/session/choose_spec.rb +++ b/lib/capybara/spec/session/choose_spec.rb @@ -6,19 +6,19 @@ it "should choose a radio button by id" do @session.choose("gender_male") @session.click_button('awesome') - extract_results(@session)['gender'].should == 'male' + expect(extract_results(@session)['gender']).to eq('male') end it "should choose a radio button by label" do @session.choose("Both") @session.click_button('awesome') - extract_results(@session)['gender'].should == 'both' + expect(extract_results(@session)['gender']).to eq('both') end it "casts to string" do @session.choose("Both") @session.click_button(:'awesome') - extract_results(@session)['gender'].should == 'both' + expect(extract_results(@session)['gender']).to eq('both') end context "with a locator that doesn't exist" do @@ -42,7 +42,7 @@ it "should accept partial matches when false" do @session.choose("Mal", :exact => false) @session.click_button('awesome') - extract_results(@session)['gender'].should == 'male' + expect(extract_results(@session)['gender']).to eq('male') end it "should not accept partial matches when true" do @@ -56,7 +56,7 @@ it "can check radio buttons by their value" do @session.choose('form[gender]', :option => "male") @session.click_button('awesome') - extract_results(@session)['gender'].should == "male" + expect(extract_results(@session)['gender']).to eq("male") end it "should raise an error if option not found" do diff --git a/lib/capybara/spec/session/click_button_spec.rb b/lib/capybara/spec/session/click_button_spec.rb index 56e164ef0..4366b0c9f 100644 --- a/lib/capybara/spec/session/click_button_spec.rb +++ b/lib/capybara/spec/session/click_button_spec.rb @@ -11,31 +11,31 @@ it "casts to string" do @session.click_button(:'Relative Action') - @session.current_path.should == '/relative' - extract_results(@session)['relative'].should == 'Relative Action' + expect(@session.current_path).to eq('/relative') + expect(extract_results(@session)['relative']).to eq('Relative Action') 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' + expect(extract_results(@session)['terms_of_use']).to eq('1') end end context "with a form that has a relative url as an action" do it "should post to the correct url" do @session.click_button('Relative Action') - @session.current_path.should == '/relative' - extract_results(@session)['relative'].should == 'Relative Action' + expect(@session.current_path).to eq('/relative') + expect(extract_results(@session)['relative']).to eq('Relative Action') end end context "with a form that has no action specified" do it "should post to the correct url" do @session.click_button('No Action') - @session.current_path.should == '/form' - extract_results(@session)['no_action'].should == 'No Action' + expect(@session.current_path).to eq('/form') + expect(extract_results(@session)['no_action']).to eq('No Action') end end @@ -47,23 +47,23 @@ end it "should serialise and submit search fields" do - @results['html5_search'].should == 'what are you looking for' + expect(@results['html5_search']).to eq('what are you looking for') end it "should serialise and submit email fields" do - @results['html5_email'].should == 'person@email.com' + expect(@results['html5_email']).to eq('person@email.com') end it "should serialise and submit url fields" do - @results['html5_url'].should == 'http://www.example.com' + expect(@results['html5_url']).to eq('http://www.example.com') end it "should serialise and submit tel fields" do - @results['html5_tel'].should == '911' + expect(@results['html5_tel']).to eq('911') end it "should serialise and submit color fields" do - @results['html5_color'].upcase.should == '#FFFFFF' + expect(@results['html5_color'].upcase).to eq('#FFFFFF') end end @@ -74,78 +74,78 @@ end it "should serialize and submit text fields" do - @results['first_name'].should == 'John' + expect(@results['first_name']).to eq('John') end it "should escape fields when submitting" do - @results['phone'].should == '+1 555 7021' + expect(@results['phone']).to eq('+1 555 7021') end it "should serialize and submit password fields" do - @results['password'].should == 'seeekrit' + expect(@results['password']).to eq('seeekrit') end it "should serialize and submit hidden fields" do - @results['token'].should == '12345' + expect(@results['token']).to eq('12345') end it "should not serialize fields from other forms" do - @results['middle_name'].should be_nil + expect(@results['middle_name']).to 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 + expect(@results['awesome']).to eq('awesome') + expect(@results['crappy']).to be_nil end it "should serialize radio buttons" do - @results['gender'].should == 'female' + expect(@results['gender']).to eq('female') end it "should default radio value to 'on' if none specified" do - @results['valueless_radio'].should == 'on' + expect(@results['valueless_radio']).to eq('on') end it "should serialize check boxes" do - @results['pets'].should include('dog', 'hamster') - @results['pets'].should_not include('cat') + expect(@results['pets']).to include('dog', 'hamster') + expect(@results['pets']).not_to include('cat') end it "should default checkbox value to 'on' if none specififed" do - @results['valueless_checkbox'].should == 'on' + expect(@results['valueless_checkbox']).to eq('on') end it "should serialize text areas" do - @results['description'].should == 'Descriptive text goes here' + expect(@results['description']).to eq('Descriptive text goes here') end it "should serialize select tag with values" do - @results['locale'].should == 'en' + expect(@results['locale']).to eq('en') end it "should serialize select tag without values" do - @results['region'].should == 'Norway' + expect(@results['region']).to eq('Norway') end it "should serialize first option for select tag with no selection" do - @results['city'].should == 'London' + expect(@results['city']).to eq('London') end it "should not serialize a select tag without options" do - @results['tendency'].should be_nil + expect(@results['tendency']).to be_nil end it "should convert lf to cr/lf in submitted textareas" do - @results['newline'].should == "\r\nNew line after and before textarea tag\r\n" + expect(@results['newline']).to eq("\r\nNew line after and before textarea tag\r\n") end it "should not submit disabled fields" do - @results['disabled_text_field'].should be_nil - @results['disabled_textarea'].should be_nil - @results['disabled_checkbox'].should be_nil - @results['disabled_radio'].should be_nil - @results['disabled_select'].should be_nil - @results['disabled_file'].should be_nil + expect(@results['disabled_text_field']).to be_nil + expect(@results['disabled_textarea']).to be_nil + expect(@results['disabled_checkbox']).to be_nil + expect(@results['disabled_radio']).to be_nil + expect(@results['disabled_select']).to be_nil + expect(@results['disabled_file']).to be_nil end end end @@ -153,24 +153,24 @@ 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' + expect(extract_results(@session)['first_name']).to eq('John') end it "should work with partial matches" do @session.click_button('Go') - @session.should have_content('You landed') + expect(@session).to have_content('You landed') end end context "with title given on a submit button" do it "should submit the associated form" do @session.click_button('What an Awesome Button') - extract_results(@session)['first_name'].should == 'John' + expect(extract_results(@session)['first_name']).to eq('John') end it "should work with partial matches" do @session.click_button('What an Awesome') - extract_results(@session)['first_name'].should == 'John' + expect(extract_results(@session)['first_name']).to eq('John') end end @@ -181,19 +181,19 @@ end it "should serialize and submit text fields" do - @results['outside_input'].should == 'outside_input' + expect(@results['outside_input']).to eq('outside_input') end it "should serialize text areas" do - @results['outside_textarea'].should == 'Some text here' + expect(@results['outside_textarea']).to eq('Some text here') end it "should serialize select tags" do - @results['outside_select'].should == 'Ruby' + expect(@results['outside_select']).to eq('Ruby') end it "should not serliaze fields associated with a different form" do - @results['for_form2'].should be_nil + expect(@results['for_form2']).to be_nil end end @@ -205,12 +205,12 @@ end it "should submit the associated form" do - @results['which_form'].should == 'form2' + expect(@results['which_form']).to eq('form2') end it "should submit the button that was clicked, but not other buttons" do - @results['outside_button'].should == 'outside_button' - @results['unused'].should be_nil + expect(@results['outside_button']).to eq('outside_button') + expect(@results['unused']).to be_nil end end @@ -221,37 +221,37 @@ end it "should submit the associated form" do - @results['which_form'].should == 'form1' + expect(@results['which_form']).to eq('form1') end it "should submit the button that was clicked, but not other buttons" do - @results['outside_submit'].should == 'outside_submit' - @results['submit_form1'].should be_nil + expect(@results['outside_submit']).to eq('outside_submit') + expect(@results['submit_form1']).to be_nil end end context "with submit button for form1 located within form2" do it "should submit the form associated with the button" do @session.click_button('other_form_button') - extract_results(@session)['which_form'].should == "form1" + expect(extract_results(@session)['which_form']).to eq("form1") end end context "with submit button not associated with any form" do it "should not error when clicked" do - lambda { @session.click_button('no_form_button') }.should_not raise_error + expect { @session.click_button('no_form_button') }.not_to raise_error end end context "with alt given on an image button" do it "should submit the associated form" do @session.click_button('oh hai thar') - extract_results(@session)['first_name'].should == 'John' + expect(extract_results(@session)['first_name']).to eq('John') end it "should work with partial matches" do @session.click_button('hai') - extract_results(@session)['first_name'].should == 'John' + expect(extract_results(@session)['first_name']).to eq('John') end end @@ -259,82 +259,82 @@ 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' + expect(extract_results(@session)['first_name']).to eq('John') end it "should work with partial matches" do @session.click_button('kay') - extract_results(@session)['first_name'].should == 'John' + expect(extract_results(@session)['first_name']).to eq('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' + expect(extract_results(@session)['first_name']).to eq('John') end end context "with title given on an image button" do it "should submit the associated form" do @session.click_button('Okay 556 Image') - extract_results(@session)['first_name'].should == 'John' + expect(extract_results(@session)['first_name']).to eq('John') end it "should work with partial matches" do @session.click_button('Okay 556') - extract_results(@session)['first_name'].should == 'John' + expect(extract_results(@session)['first_name']).to eq('John') end end context "with text given on a button defined by ' } it "gives proper description" do - have_button('A button').description.should == "have button \"A button\"" + expect(have_button('A button').description).to eq("have button \"A button\"") end it "passes if there is such a button" do - html.should have_button('A button') + expect(html).to have_button('A button') end it "fails if there is no such button" do expect do - html.should have_button('No such Button') + expect(html).to have_button('No such Button') end.to raise_error(/expected to find button "No such Button"/) end end @@ -522,30 +522,30 @@ let(:html) { '

' } it "gives proper description" do - have_field('Text field').description.should == "have field \"Text field\"" + expect(have_field('Text field').description).to eq("have field \"Text field\"") end it "gives proper description for a given value" do - have_field('Text field', with: 'some value').description.should == "have field \"Text field\" with value \"some value\"" + expect(have_field('Text field', with: 'some value').description).to eq("have field \"Text field\" with value \"some value\"") end it "passes if there is such a field" do - html.should have_field('Text field') + expect(html).to have_field('Text field') end it "passes if there is such a field with value" do - html.should have_field('Text field', with: 'some value') + expect(html).to have_field('Text field', with: 'some value') end it "fails if there is no such field" do expect do - html.should have_field('No such Field') + expect(html).to have_field('No such Field') end.to raise_error(/expected to find field "No such Field"/) end it "fails if there is such field but with false value" do expect do - html.should have_field('Text field', with: 'false value') + expect(html).to have_field('Text field', with: 'false value') end.to raise_error(/expected to find field "Text field"/) end @@ -555,7 +555,7 @@ def to_s "some value" end end - html.should have_field('Text field', with: Foo.new) + expect(html).to have_field('Text field', with: Foo.new) end end @@ -566,23 +566,23 @@ def to_s end it "gives proper description" do - have_checked_field('it is checked').description.should == "have field \"it is checked\"" + expect(have_checked_field('it is checked').description).to eq("have field \"it is checked\"") end context "with should" do it "passes if there is such a field and it is checked" do - html.should have_checked_field('it is checked') + expect(html).to have_checked_field('it is checked') end it "fails if there is such a field but it is not checked" do expect do - html.should have_checked_field('unchecked field') + expect(html).to have_checked_field('unchecked field') end.to raise_error(/expected to find field "unchecked field"/) end it "fails if there is no such field" do expect do - html.should have_checked_field('no such field') + expect(html).to have_checked_field('no such field') end.to raise_error(/expected to find field "no such field"/) end end @@ -590,16 +590,16 @@ def to_s context "with should not" do it "fails if there is such a field and it is checked" do expect do - html.should_not have_checked_field('it is checked') + expect(html).not_to have_checked_field('it is checked') end.to raise_error(/expected not to find field "it is checked"/) end it "passes if there is such a field but it is not checked" do - html.should_not have_checked_field('unchecked field') + expect(html).not_to have_checked_field('unchecked field') end it "passes if there is no such field" do - html.should_not have_checked_field('no such field') + expect(html).not_to have_checked_field('no such field') end end end @@ -611,23 +611,23 @@ def to_s end it "gives proper description" do - have_unchecked_field('unchecked field').description.should == "have field \"unchecked field\"" + expect(have_unchecked_field('unchecked field').description).to eq("have field \"unchecked field\"") end context "with should" do it "passes if there is such a field and it is not checked" do - html.should have_unchecked_field('unchecked field') + expect(html).to have_unchecked_field('unchecked field') end it "fails if there is such a field but it is checked" do expect do - html.should have_unchecked_field('it is checked') + expect(html).to have_unchecked_field('it is checked') end.to raise_error(/expected to find field "it is checked"/) end it "fails if there is no such field" do expect do - html.should have_unchecked_field('no such field') + expect(html).to have_unchecked_field('no such field') end.to raise_error(/expected to find field "no such field"/) end end @@ -635,16 +635,16 @@ def to_s context "with should not" do it "fails if there is such a field and it is not checked" do expect do - html.should_not have_unchecked_field('unchecked field') + expect(html).not_to have_unchecked_field('unchecked field') end.to raise_error(/expected not to find field "unchecked field"/) end it "passes if there is such a field but it is checked" do - html.should_not have_unchecked_field('it is checked') + expect(html).not_to have_unchecked_field('it is checked') end it "passes if there is no such field" do - html.should_not have_unchecked_field('no such field') + expect(html).not_to have_unchecked_field('no such field') end end end @@ -653,16 +653,16 @@ def to_s let(:html) { '' } it "gives proper description" do - have_select('Select Box').description.should == "have select box \"Select Box\"" + expect(have_select('Select Box').description).to eq("have select box \"Select Box\"") end it "passes if there is such a select" do - html.should have_select('Select Box') + expect(html).to have_select('Select Box') end it "fails if there is no such select" do expect do - html.should have_select('No such Select box') + expect(html).to have_select('No such Select box') end.to raise_error(/expected to find select box "No such Select box"/) end end @@ -671,16 +671,16 @@ def to_s let(:html) { '
Lovely table
' } it "gives proper description" do - have_table('Lovely table').description.should == "have table \"Lovely table\"" + expect(have_table('Lovely table').description).to eq("have table \"Lovely table\"") end it "passes if there is such a select" do - html.should have_table('Lovely table') + expect(html).to have_table('Lovely table') end it "fails if there is no such select" do expect do - html.should have_table('No such Table') + expect(html).to have_table('No such Table') end.to raise_error(/expected to find table "No such Table"/) end end diff --git a/spec/rspec_spec.rb b/spec/rspec_spec.rb index 046a450ce..ca8d3b6a8 100644 --- a/spec/rspec_spec.rb +++ b/spec/rspec_spec.rb @@ -3,18 +3,18 @@ describe 'capybara/rspec', :type => :feature do it "should include Capybara in rspec" do visit('/foo') - page.body.should include('Another World') + expect(page.body).to include('Another World') end context "resetting session" do it "sets a cookie in one example..." do visit('/set_cookie') - page.body.should include('Cookie set to test_cookie') + expect(page.body).to include('Cookie set to test_cookie') end it "...then it is not available in the next" do visit('/get_cookie') - page.body.should_not include('test_cookie') + expect(page.body).not_to include('test_cookie') end end @@ -24,16 +24,16 @@ end it "...then it has returned to the default in the next example" do - Capybara.current_driver.should == :rack_test + expect(Capybara.current_driver).to eq(:rack_test) end end it "switches to the javascript driver when giving it as metadata", :js => true do - Capybara.current_driver.should == Capybara.javascript_driver + expect(Capybara.current_driver).to eq(Capybara.javascript_driver) end it "switches to the given driver when giving it as metadata", :driver => :culerity do - Capybara.current_driver.should == :culerity + expect(Capybara.current_driver).to eq(:culerity) end end @@ -46,6 +46,6 @@ feature "Feature DSL" do scenario "is pulled in" do visit('/foo') - page.body.should include('Another World') + expect(page.body).to include('Another World') end end diff --git a/spec/selenium_spec.rb b/spec/selenium_spec.rb index 57e4b7b21..3c9a66b2a 100644 --- a/spec/selenium_spec.rb +++ b/spec/selenium_spec.rb @@ -11,7 +11,7 @@ module TestSessions Selenium = Capybara::Session.new(:selenium_focus, TestApp) end -Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :skip => [ +Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :capybara_skip => [ :response_headers, :status_code, :trigger @@ -25,13 +25,13 @@ module TestSessions describe '#driver' do it "should be a selenium driver" do - @session.driver.should be_an_instance_of(Capybara::Selenium::Driver) + expect(@session.driver).to be_an_instance_of(Capybara::Selenium::Driver) end end describe '#mode' do it "should remember the mode" do - @session.mode.should == :selenium_focus + expect(@session.mode).to eq(:selenium_focus) end end @@ -39,7 +39,7 @@ module TestSessions it "freshly reset session should not be touched" do @session.instance_variable_set(:@touched, true) @session.reset! - @session.instance_variable_get(:@touched).should be_false + expect(@session.instance_variable_get(:@touched)).to eq false end end @@ -55,12 +55,12 @@ module TestSessions it "should have return code 1 when running selenium_driver_rspec_failure.rb" do `rspec spec/fixtures/selenium_driver_rspec_failure.rb` - $?.exitstatus.should be 1 + expect($?.exitstatus).to be 1 end it "should have return code 0 when running selenium_driver_rspec_success.rb" do `rspec spec/fixtures/selenium_driver_rspec_success.rb` - $?.exitstatus.should be 0 + expect($?.exitstatus).to be 0 end end end @@ -73,10 +73,10 @@ module TestSessions describe '#quit' do it "should reset browser when quit" do - @driver.browser.should be + expect(@driver.browser).to be @driver.quit #access instance variable directly so we don't create a new browser instance - @driver.instance_variable_get(:@browser).should be_nil + expect(@driver.instance_variable_get(:@browser)).to be_nil end end end diff --git a/spec/selenium_spec_chrome.rb b/spec/selenium_spec_chrome.rb index 306ed7311..6aa4e3584 100644 --- a/spec/selenium_spec_chrome.rb +++ b/spec/selenium_spec_chrome.rb @@ -14,7 +14,7 @@ module TestSessions Chrome = Capybara::Session.new(:selenium_chrome, ChromeTestApp) end -Capybara::SpecHelper.run_specs TestSessions::Chrome, "selenium_chrome", :skip => [ +Capybara::SpecHelper.run_specs TestSessions::Chrome, "selenium_chrome", :capybara_skip => [ :response_headers, :status_code, :trigger diff --git a/spec/server_spec.rb b/spec/server_spec.rb index 9012eddf7..896a8b790 100644 --- a/spec/server_spec.rb +++ b/spec/server_spec.rb @@ -8,7 +8,7 @@ @res = Net::HTTP.start(@server.host, @server.port) { |http| http.get('/') } - @res.body.should include('Hello Server') + expect(@res.body).to include('Hello Server') end it "should do nothing when no server given" do @@ -42,7 +42,7 @@ @server = Capybara::Server.new(@app).boot @res = Net::HTTP.start(@server.host, 22789) { |http| http.get('/') } - @res.body.should include('Hello Server') + expect(@res.body).to include('Hello Server') Capybara.server_port = nil end @@ -52,7 +52,7 @@ @server = Capybara::Server.new(@app, 22790).boot @res = Net::HTTP.start(@server.host, 22790) { |http| http.get('/') } - @res.body.should include('Hello Server') + expect(@res.body).to include('Hello Server') Capybara.server_port = nil end @@ -65,10 +65,10 @@ @server2 = Capybara::Server.new(@app2).boot @res1 = Net::HTTP.start(@server1.host, @server1.port) { |http| http.get('/') } - @res1.body.should include('Hello Server') + expect(@res1.body).to include('Hello Server') @res2 = Net::HTTP.start(@server2.host, @server2.port) { |http| http.get('/') } - @res2.body.should include('Hello Second Server') + expect(@res2.body).to include('Hello Second Server') end it "should use the server if it already running" do @@ -81,13 +81,13 @@ @server2b = Capybara::Server.new(@app2).boot @res1 = Net::HTTP.start(@server1b.host, @server1b.port) { |http| http.get('/') } - @res1.body.should include('Hello Server') + expect(@res1.body).to include('Hello Server') @res2 = Net::HTTP.start(@server2b.host, @server2b.port) { |http| http.get('/') } - @res2.body.should include('Hello Second Server') + expect(@res2.body).to include('Hello Second Server') - @server1a.port.should == @server1b.port - @server2a.port.should == @server2b.port + expect(@server1a.port).to eq(@server1b.port) + expect(@server2a.port).to eq(@server2b.port) end it "should raise server errors when the server errors before the timeout" do @@ -97,9 +97,9 @@ raise 'kaboom' end - proc do + expect do Capybara::Server.new(proc {|e|}).boot - end.should raise_error(RuntimeError, 'kaboom') + end.to raise_error(RuntimeError, 'kaboom') ensure # TODO refactor out the defaults so it's reliant on unset state instead of # a one-time call in capybara.rb @@ -110,7 +110,7 @@ it "is not #responsive? when Net::HTTP raises a SystemCallError" do app = lambda { [200, {}, ['Hello, world']] } server = Capybara::Server.new(app) - Net::HTTP.should_receive(:start).and_raise(SystemCallError.allocate) + expect(Net::HTTP).to receive(:start).and_raise(SystemCallError.allocate) expect(server.responsive?).to eq false end end