Switch to new RSpec expectation syntax
authorLunar <lunar@anargeek.net>
Tue, 6 May 2014 13:02:58 +0000 (13:02 +0000)
committerLunar <lunar@anargeek.net>
Tue, 6 May 2014 13:16:01 +0000 (13:16 +0000)
Gemfile.lock
coquelicot.gemspec
spec/coquelicot/app_spec.rb
spec/coquelicot/depot_spec.rb
spec/coquelicot/jyraphe_migrator_spec.rb
spec/coquelicot/rack/multipart_parser_spec.rb
spec/coquelicot/rack/upload_spec.rb
spec/coquelicot/stored_file_spec.rb
spec/coquelicot_spec.rb
spec/spec_helper.rb

index 81164b5..4f8a783 100644 (file)
@@ -114,6 +114,6 @@ DEPENDENCIES
   hpricot
   rack-test
   rake
-  rspec (~> 2.6)
+  rspec (~> 2.11)
   timecop
   tzinfo
index 859849a..7701e50 100644 (file)
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
   s.require_paths = ['lib']
 
   s.add_development_dependency 'rake'
-  s.add_development_dependency 'rspec', '~>2.6'
+  s.add_development_dependency 'rspec', '~>2.11'
   s.add_development_dependency 'hpricot'
   s.add_development_dependency 'timecop'
   s.add_development_dependency 'rack-test'
index 16f80e8..28609d9 100644 (file)
@@ -53,14 +53,14 @@ describe Coquelicot::Application do
     context 'using the default language' do
       it 'should display the maximum file size' do
         visit '/'
-        find(:xpath, '//label[@for="file"]').
-            should have_content("max. size: #{Coquelicot.settings.max_file_size.as_size}")
+        expect(find(:xpath, '//label[@for="file"]')).
+            to have_content("max. size: #{Coquelicot.settings.max_file_size.as_size}")
       end
       context 'when I explicitly request french' do
         it 'should display a page in french' do
           visit '/'
           click_link 'fr'
-          page.should have_content('Partager')
+          expect(page).to have_content('Partager')
           reset_session!
         end
         # will fail without ordered Hash, see:
@@ -81,7 +81,7 @@ describe Coquelicot::Application do
             end
           end
           it 'should display an error in french' do
-            page.should have_content('Le fichier est vide')
+            expect(page).to have_content('Le fichier est vide')
           end
         end
       end
@@ -91,7 +91,7 @@ describe Coquelicot::Application do
       context 'when I do nothing special' do
         it 'should display a page in french' do
           visit '/'
-          page.should have_content('Partager')
+          expect(page).to have_content('Partager')
         end
         context 'when the max upload size is 1 KiB' do
           around do |example|
@@ -105,7 +105,7 @@ describe Coquelicot::Application do
           end
           it 'should display "1 Kio" as the max upload size' do
             visit '/'
-            page.should have_content('1 Kio')
+            expect(page).to have_content('1 Kio')
           end
           # will fail without ordered Hash, see:
           # <https://github.com/jnicklas/capybara/issues/670>
@@ -117,7 +117,7 @@ describe Coquelicot::Application do
               click_button 'submit'
             end
             it 'should display an error in french' do
-              page.should have_content('plus gros que la taille maximale')
+              expect(page).to have_content('plus gros que la taille maximale')
             end
           end
         end
@@ -137,7 +137,7 @@ describe Coquelicot::Application do
             end
           end
           it 'should display an error in french' do
-            page.should have_content('Le fichier est vide')
+            expect(page).to have_content('Le fichier est vide')
           end
         end
       end
@@ -149,7 +149,7 @@ describe Coquelicot::Application do
           reset_session!
         end
         it 'should display a page in german' do
-          page.should have_content('Verteile')
+          expect(page).to have_content('Verteile')
         end
        # will fail without ordered Hash, see:
        # <https://github.com/jnicklas/capybara/issues/670>
@@ -160,7 +160,7 @@ describe Coquelicot::Application do
             click_button 'submit'
           end
           it 'should display a page in german' do
-            page.should have_content('Verteile eine weitere Datei')
+            expect(page).to have_content('Verteile eine weitere Datei')
           end
         end
       end
@@ -173,14 +173,14 @@ describe Coquelicot::Application do
       context 'using the default language' do
         it 'should display the "about text" in English' do
           visit '/'
-          find('.about').text.should == 'This is an about text'
+          expect(find('.about').text).to be == 'This is an about text'
         end
       end
       context 'when I explicitly request French' do
         it 'should display the "about text" in French' do
           visit '/'
           click_link 'fr'
-          find('.about').text.should == 'Ceci est un texte'
+          expect(find('.about').text).to be == 'Ceci est un texte'
           reset_session!
         end
       end
@@ -188,7 +188,7 @@ describe Coquelicot::Application do
         include_context 'browser prefers french'
         it 'should display the "about text" in French' do
           visit '/'
-          find('.about').text.should == 'Ceci est un texte'
+          expect(find('.about').text).to be == 'Ceci est un texte'
         end
       end
     end
@@ -200,7 +200,7 @@ describe Coquelicot::Application do
       end
       it 'should offer a "git clone" to the local URI' do
         visit '/'
-        find('#footer').should have_content('git clone http://www.example.com/coquelicot.git')
+        expect(find('#footer')).to have_content('git clone http://www.example.com/coquelicot.git')
       end
     end
     context 'when a local Git repository is not usable' do
@@ -213,17 +213,17 @@ describe Coquelicot::Application do
       end
       it 'should offer a link to retrieve the source' do
         visit '/'
-        find('#footer').text.should =~ /curl.*gem unpack.*\.gem$/
+        expect(find('#footer').text).to match /curl.*gem unpack.*\.gem$/
       end
       it 'should log a warning' do
         logger = double('Logger')
-        logger.should_receive(:warn).with(/Unable to provide access to local Git repository/)
+        expect(logger).to receive(:warn).with(/Unable to provide access to local Git repository/)
         app.any_instance.stub(:logger).and_return(logger)
         visit '/'
       end
       it 'should log a warning only on the first request' do
         logger = double('Logger')
-        logger.should_receive(:warn).once
+        expect(logger).to receive(:warn).once
         app.any_instance.stub(:logger).and_return(logger)
         visit '/'
         visit '/'
@@ -237,7 +237,7 @@ describe Coquelicot::Application do
       end
       it 'should offer a link to retrieve the source' do
         visit '/'
-        find('#footer').text.should =~ /curl.*gem unpack.*\.gem$/
+        expect(find('#footer').text).to match /curl.*gem unpack.*\.gem$/
       end
     end
   end
@@ -248,25 +248,25 @@ describe Coquelicot::Application do
     end
     it 'should display the README file' do
       title = File.open(File.expand_path('../../../README', __FILE__)) { |f| f.readline.strip }
-      find('h1').should have_content(title)
+      expect(find('h1')).to have_content(title)
     end
   end
 
   describe 'get /about-your-data' do
     it 'should display some info about data retention' do
       visit '/about-your-data'
-      find('h1').should have_content('About your data…')
+      expect(find('h1')).to have_content('About your data…')
     end
     context 'when using SSL' do
       it 'should notice the connection is encrypted' do
         visit 'https://example.com/about-your-data'
-        page.should have_content('Exchanges between your computer and example.com are encrypted.')
+        expect(page).to have_content('Exchanges between your computer and example.com are encrypted.')
       end
     end
     context 'when not using SSL' do
       it 'should notice the connection is encrypted' do
         visit 'http://example.com/about-your-data'
-        page.should_not have_content('Exchanges between your computer and example.org are encrypted.')
+        expect(page).to_not have_content('Exchanges between your computer and example.org are encrypted.')
       end
     end
   end
@@ -279,11 +279,11 @@ describe Coquelicot::Application do
         visit '/source'
       end
       it 'should send a file to be saved' do
-        page.response_headers['Content-Type'].should == 'application/octet-stream'
-        page.response_headers['Content-Disposition'].should =~ /^attachment;/
+        expect(page.response_headers['Content-Type']).to be == 'application/octet-stream'
+        expect(page.response_headers['Content-Disposition']).to match /^attachment;/
       end
       it 'should send a file with a proposed name correct for coquelicot gem' do
-        page.response_headers['Content-Disposition'].should =~ /filename="coquelicot-.*\.gem"/
+        expect(page.response_headers['Content-Disposition']).to match /filename="coquelicot-.*\.gem"/
       end
       if defined? Gem::Package.new
         context 'the downloaded gem' do
@@ -296,15 +296,15 @@ describe Coquelicot::Application do
             end
           end
           it 'should be named "coquelicot"' do
-            @gem.spec.name.should == 'coquelicot'
+            expect(@gem.spec.name).to be == 'coquelicot'
           end
           it "should have a version containing 'onecoolhostname' for the hostname" do
-            @gem.spec.version.to_s.should =~ /\.onecoolhostname\./
+            expect(@gem.spec.version.to_s).to match /\.onecoolhostname\./
           end
           it "should have a version containing today's date" do
             Timecop.freeze(Time.now) do
               date_str = Date.today.strftime('%Y%m%d')
-              @gem.spec.version.to_s.should =~ /\.#{date_str}$/
+              expect(@gem.spec.version.to_s).to match /\.#{date_str}$/
             end
           end
           it 'should at least contain this spec file' do
@@ -313,7 +313,7 @@ describe Coquelicot::Application do
             @gem.spec.files.each do |file|
               content = File.read(file, :encoding => 'binary') if file.end_with?(this_file)
             end
-            content.should == File.read(__FILE__, :encoding => 'binary')
+            expect(content).to be == File.read(__FILE__, :encoding => 'binary')
           end
         end
       else
@@ -325,15 +325,15 @@ describe Coquelicot::Application do
             end
           end
           it 'should be named "coquelicot"' do
-            @gem.metadata.name.should == 'coquelicot'
+            expect(@gem.metadata.name).to be == 'coquelicot'
           end
           it "should have a version containing 'onecoolhostname' for the hostname" do
-            @gem.metadata.version.to_s.should =~ /\.onecoolhostname\./
+            expect(@gem.metadata.version.to_s).to match /\.onecoolhostname\./
           end
           it "should have a version containing today's date" do
             Timecop.freeze(Time.now) do
               date_str = Date.today.strftime('%Y%m%d')
-              @gem.metadata.version.to_s.should =~ /\.#{date_str}$/
+              expect(@gem.metadata.version.to_s).to match /\.#{date_str}$/
             end
           end
           it 'should at least contain this spec file' do
@@ -342,7 +342,7 @@ describe Coquelicot::Application do
             @gem.each do |file|
               content = file.read if file.full_name.end_with?(this_file)
             end
-            content.should == File.open(__FILE__, 'rb').read
+            expect(content).to be == File.open(__FILE__, 'rb').read
           end
         end
       end
@@ -357,7 +357,7 @@ describe Coquelicot::Application do
         post '/authenticate', :file => Rack::Test::UploadedFile.new(path, 'text/plain')
       end
       it 'should get status 413 (Request entity too large)' do
-        last_response.status.should == 413
+        expect(last_response.status).to be == 413
       end
     end
   end
@@ -371,7 +371,7 @@ describe Coquelicot, '.run!' do
       stderr = capture(:stderr) do
         expect { Coquelicot.run! %w{} }.to raise_error(SystemExit)
       end
-      stderr.should =~ /Usage:/
+      expect(stderr).to match /Usage:/
     end
   end
   context 'when using "-h"' do
@@ -379,13 +379,13 @@ describe Coquelicot, '.run!' do
       stderr = capture(:stderr) do
         expect { Coquelicot.run! %w{-h} }.to raise_error(SystemExit)
       end
-      stderr.should =~ /Usage:/
+      expect(stderr).to match /Usage:/
     end
   end
   context 'when using "-c <settings.yml>"' do
     it 'should use the given setting file' do
       settings_file = File.expand_path('../../../conf/settings-default.yml', __FILE__)
-      Coquelicot::Application.should_receive(:config_file).with(settings_file)
+      expect(Coquelicot::Application).to receive(:config_file).with(settings_file)
       stderr = capture(:stderr) do
         expect { Coquelicot.run! ['-c', settings_file] }.to raise_error(SystemExit)
       end
@@ -407,7 +407,7 @@ describe Coquelicot, '.run!' do
         stderr = capture(:stderr) do
           expect { Coquelicot.run! ['-c', @settings_path] }.to raise_error(SystemExit)
         end
-        Coquelicot.settings.depot_path.should == '/nonexistent'
+        expect(Coquelicot.settings.depot_path).to be == '/nonexistent'
       end
     end
     context 'when the given settings file does not exist' do
@@ -415,7 +415,7 @@ describe Coquelicot, '.run!' do
         stderr = capture(:stderr) do
           expect { Coquelicot.run! %w{-c non-existent.yml} }.to raise_error(SystemExit)
         end
-        stderr.should =~ /cannot access/
+        expect(stderr).to match /cannot access/
       end
     end
   end
@@ -424,7 +424,7 @@ describe Coquelicot, '.run!' do
       stderr = capture(:stderr) do
         expect { Coquelicot.run! %w{--invalid-option} }.to raise_error(SystemExit)
       end
-      stderr.should =~ /not a valid option/
+      expect(stderr).to match /not a valid option/
     end
   end
   context 'when given "whatever"' do
@@ -432,7 +432,7 @@ describe Coquelicot, '.run!' do
       stderr = capture(:stderr) do
         expect { Coquelicot.run! %w{whatever} }.to raise_error(SystemExit)
       end
-      stderr.should =~ /not a valid command/
+      expect(stderr).to match /not a valid command/
     end
   end
   shared_context 'command accepts options' do
@@ -441,7 +441,7 @@ describe Coquelicot, '.run!' do
         stderr = capture(:stderr) do
           expect { Coquelicot.run!([command, '--help']) }.to raise_error(SystemExit)
         end
-        stderr.should =~ /Usage:/
+        expect(stderr).to match /Usage:/
       end
     end
     context 'when given an invalid option' do
@@ -449,7 +449,7 @@ describe Coquelicot, '.run!' do
         stderr = capture(:stderr) do
           expect { Coquelicot.run!([command, '--invalid-option']) }.to raise_error(SystemExit)
         end
-        stderr.should =~ /not a valid option/
+        expect(stderr).to match /not a valid option/
       end
     end
   end
@@ -463,21 +463,21 @@ describe Coquelicot, '.run!' do
     end
     context 'with default options' do
       it 'should daemonize' do
-        ::Unicorn::Launcher.should_receive(:daemonize!)
+        expect(::Unicorn::Launcher).to receive(:daemonize!)
         ::Rainbows::HttpServer.stub(:new).and_return(double('HttpServer').as_null_object)
         Coquelicot.run! %w{start}
       end
       it 'should start the web server' do
         ::Unicorn::Launcher.stub(:daemonize!)
         server = double('HttpServer')
-        server.should_receive(:start).and_return(double('Thread').as_null_object)
+        expect(server).to receive(:start).and_return(double('Thread').as_null_object)
         ::Rainbows::HttpServer.stub(:new).and_return(server)
         Coquelicot.run! %w{start}
       end
     end
     context 'when given the --no-daemon option' do
       it 'should not daemonize' do
-        ::Unicorn::Launcher.should_receive(:daemonize!).never
+        expect(::Unicorn::Launcher).to receive(:daemonize!).never
         ::Rainbows::HttpServer.stub(:new).and_return(double('HttpServer').as_null_object)
         Coquelicot.run! %w{start --no-daemon}
       end
@@ -486,15 +486,15 @@ describe Coquelicot, '.run!' do
         app.set :listen, ['127.0.0.1:42']
         ::Rainbows::HttpServer.any_instance.stub(:start) do
           server = ::Rainbows.server
-          server.config.set[:pid].should == @depot_path
-          server.config.set[:listeners].should == ['127.0.0.1:42']
+          expect(server.config.set[:pid]).to be == @depot_path
+          expect(server.config.set[:listeners]).to be == ['127.0.0.1:42']
           double('Thread').as_null_object
         end
         Coquelicot.run! %w{start --no-daemon}
       end
       it 'should start the web server' do
         server = double('HttpServer')
-        server.should_receive(:start).and_return(double('Thread').as_null_object)
+        expect(server).to receive(:start).and_return(double('Thread').as_null_object)
         ::Rainbows::HttpServer.stub(:new).and_return(server)
         Coquelicot.run! %w{start --no-daemon}
       end
@@ -513,7 +513,7 @@ describe Coquelicot, '.run!' do
         app.set :pid, "#{@depot_path}/pid"
       end
       it 'should stop the web server' do
-        Process.should_receive(:kill).with(:TERM, pid)
+        expect(Process).to receive(:kill).with(:TERM, pid)
         Coquelicot.run! %w{stop}
       end
     end
@@ -523,7 +523,7 @@ describe Coquelicot, '.run!' do
         stderr = capture(:stderr) do
           expect { Coquelicot.run! %w{stop} }.to raise_error(SystemExit)
         end
-        stderr.should =~ /Unable to read/
+        expect(stderr).to match /Unable to read/
       end
     end
     context 'when the pid file contains garbage' do
@@ -537,7 +537,7 @@ describe Coquelicot, '.run!' do
         stderr = capture(:stderr) do
           expect { Coquelicot.run! %w{stop} }.to raise_error(SystemExit)
         end
-        stderr.should =~ /Bad PID file/
+        expect(stderr).to match /Bad PID file/
       end
     end
   end
@@ -546,14 +546,14 @@ describe Coquelicot, '.run!' do
     include_context 'command accepts options'
 
     it 'should call gc!' do
-      Coquelicot.depot.should_receive(:gc!).once
+      expect(Coquelicot.depot).to receive(:gc!).once
       Coquelicot.run! %w{gc}
     end
   end
   context 'when given "migrate-jyraphe"' do
     let(:args) { %w{all args} }
     it 'should call the migrator' do
-      Coquelicot::JyrapheMigrator.should_receive(:run!).with(args)
+      expect(Coquelicot::JyrapheMigrator).to receive(:run!).with(args)
       Coquelicot.run!(%w{migrate-jyraphe} + args)
     end
   end
index bf4eb5a..2dce8da 100644 (file)
@@ -23,7 +23,7 @@ module Coquelicot
     describe '.new' do
       it 'should record the given path' do
         depot = Depot.new('/test')
-        depot.path.should == '/test'
+        expect(depot.path).to be == '/test'
       end
     end
 
@@ -47,27 +47,27 @@ module Coquelicot
 
     describe '#add_file' do
       it 'should generate a random file name' do
-        depot.should_receive(:gen_random_file_name).
+        expect(depot).to receive(:gen_random_file_name).
           and_return('file', 'link')
         add_file
       end
       context 'when it generates a name that is already in use' do
         it 'should find another name' do
           FileUtils.touch File.expand_path('file', @tmpdir)
-          depot.should_receive(:gen_random_file_name).
+          expect(depot).to receive(:gen_random_file_name).
             and_return('file', 'another', 'link')
           add_file
         end
       end
       context 'when it generates the same name with another client' do
         it 'should find another name' do
-          depot.should_receive(:gen_random_file_name).
+          expect(depot).to receive(:gen_random_file_name).
             and_return('file', 'another', 'link')
           raised = false
-          StoredFile.should_receive(:create).ordered.
+          expect(StoredFile).to receive(:create).ordered.
               with(/\/file$/, pass, instance_of(Hash)).
               and_raise(Errno::EEXIST.new(File.expand_path('file', @tmpdir)))
-          StoredFile.should_receive(:create).ordered.
+          expect(StoredFile).to receive(:create).ordered.
               with(/\/another$/, pass, instance_of(Hash))
           add_file
         end
@@ -99,16 +99,16 @@ module Coquelicot
           }.to change { depot.size }.by(1)
         end
         it 'should return a randomly generated link name' do
-          depot.should_receive(:gen_random_file_name).
+          expect(depot).to receive(:gen_random_file_name).
             and_return('file', 'link')
           link = add_file
-          link.should == 'link'
+          expect(link).to be == 'link'
         end
         it 'should add the new link to the ".links" file' do
-          depot.should_receive(:gen_random_file_name).
+          expect(depot).to receive(:gen_random_file_name).
             and_return('file', 'link')
           add_file
-          File.read(File.expand_path('.links', @tmpdir)).should =~ /^link\s+file$/
+          expect(File.read(File.expand_path('.links', @tmpdir))).to match /^link\s+file$/
         end
         context 'when it generates a link name that is already taken' do
           before(:each) do
@@ -120,10 +120,10 @@ module Coquelicot
             @link = add_file
           end
           it 'should not overwrite the existing link' do
-            depot.size.should == 2
+            expect(depot.size).to be == 2
           end
           it 'should find another name' do
-            @link.should == 'another_link'
+            expect(@link).to be == 'another_link'
           end
         end
       end
@@ -132,7 +132,7 @@ module Coquelicot
     describe '#get_file' do
       context 'when there is no link with the given name' do
         it 'should return nil' do
-          depot.get_file('link').should be_nil
+          expect(depot.get_file('link')).to be_nil
         end
       end
       context 'when there is a link with the given name' do
@@ -140,24 +140,24 @@ module Coquelicot
           @link = add_file
         end
         it 'should return a StoredFile' do
-          depot.get_file(@link).should be_a(StoredFile)
+          expect(depot.get_file(@link)).to be_a(StoredFile)
         end
         it 'should return the right file' do
           stored_file = depot.get_file(@link, pass)
           buf = ''
           stored_file.each { |data| buf << data }
-          buf.should == 'Content'
+          expect(buf).to be == 'Content'
         end
       end
       context 'when there is a link with no matching file' do
         before(:each) do
-          depot.should_receive(:gen_random_file_name).
+          expect(depot).to receive(:gen_random_file_name).
             and_return('file', 'link')
           @link = add_file
           File.unlink File.expand_path('file', @tmpdir)
         end
         it 'should return nil' do
-          depot.get_file(@link).should be_nil
+          expect(depot.get_file(@link)).to be_nil
         end
       end
     end
@@ -169,7 +169,7 @@ module Coquelicot
       end
       context 'when there is a link with the given name' do
         before(:each) do
-          depot.should_receive(:gen_random_file_name).
+          expect(depot).to receive(:gen_random_file_name).
             and_return('file', 'link')
           add_file
         end
@@ -177,7 +177,7 @@ module Coquelicot
       end
       context 'when there is a link with no matching file' do
         before(:each) do
-          depot.should_receive(:gen_random_file_name).
+          expect(depot).to receive(:gen_random_file_name).
             and_return('file', 'link')
           add_file
           File.unlink File.expand_path('file', @tmpdir)
@@ -194,7 +194,7 @@ module Coquelicot
       end
       context 'when there is a file' do
         before(:each) do
-          depot.should_receive(:gen_random_file_name).
+          expect(depot).to receive(:gen_random_file_name).
             and_return('file', 'link')
           add_file
         end
@@ -234,14 +234,14 @@ module Coquelicot
           end
           it 'should remove files' do
             subject
-            Dir.glob("#{@tmpdir}/file*").should be_empty
+            expect(Dir.glob("#{@tmpdir}/file*")).to be_empty
           end
         end
       end
       context 'when there is a file that expires after the gone period' do
         let(:expire) { Coquelicot.settings.gone_period + 42 }
         before(:each) do
-          depot.should_receive(:gen_random_file_name).
+          expect(depot).to receive(:gen_random_file_name).
             and_return('file', 'link')
           add_file
         end
@@ -259,7 +259,7 @@ module Coquelicot
       end
       context 'when there is a link but no associated file' do
         before(:each) do
-          depot.should_receive(:gen_random_file_name).
+          expect(depot).to receive(:gen_random_file_name).
             and_return('file', 'link')
           add_file
           File.unlink File.expand_path('file', @tmpdir)
@@ -270,7 +270,7 @@ module Coquelicot
       end
       context 'when there is a corrupted file' do
         before(:each) do
-          depot.should_receive(:gen_random_file_name).
+          expect(depot).to receive(:gen_random_file_name).
             and_return('file', 'link')
           add_file
           @file_path = File.expand_path('file', @tmpdir)
@@ -282,7 +282,7 @@ module Coquelicot
           stderr = capture(:stderr) do
             depot.gc!
           end
-          stderr.should =~ /^W: #{@file_path} is not a Coquelicot file\. Skipping\./
+          expect(stderr).to match /^W: #{@file_path} is not a Coquelicot file\. Skipping\./
         end
         it 'should not remove files' do
           capture(:stderr) do
index 15dee31..109d1a5 100644 (file)
@@ -87,10 +87,10 @@ module Coquelicot
           before(:each) { migrator.migrate! }
           subject { get_first_migrated_file }
           it 'should have the same length' do
-            subject.meta['Length'].should == File.stat(__FILE__).size
+            expect(subject.meta['Length']).to be == File.stat(__FILE__).size
           end
           it 'should have the same mime type' do
-            subject.meta['Content-type'].should == 'application/x-ruby'
+            expect(subject.meta['Content-type']).to be == 'application/x-ruby'
           end
         end
       end
@@ -122,7 +122,7 @@ module Coquelicot
           before(:each) { migrator.migrate! }
           subject { get_first_migrated_file }
           it 'should be labeled as "one-time only"' do
-            subject.meta['One-time-only'].should be_true
+            expect(subject.meta['One-time-only']).to be_true
           end
         end
       end
@@ -142,7 +142,7 @@ module Coquelicot
           before(:each) { migrator.migrate! }
           it 'should need a pass' do
             stored_file = get_first_migrated_file
-            stored_file.meta.should_not include('Content-type')
+            expect(stored_file.meta).not_to include('Content-type')
           end
           it 'should be readable with a wrong pass' do
             expect {
@@ -151,7 +151,7 @@ module Coquelicot
           end
           it 'should be readable with the same pass' do
             stored_file = get_first_migrated_file(pass)
-            stored_file.meta.should include('Content-type')
+            expect(stored_file.meta).to include('Content-type')
           end
         end
       end
@@ -162,7 +162,7 @@ module Coquelicot
                                         :expire_at => -1)
         end
         it 'should issue a warning' do
-          output.should_receive(:puts).
+          expect(output).to receive(:puts).
               with(/^W: R[0-9a-z]{32} expiration time has been reduced/)
           migrator.migrate!
         end
@@ -176,7 +176,7 @@ module Coquelicot
             Timecop.freeze(Time.now) do
               migrator.migrate!
               stored_file = get_first_migrated_file
-              stored_file.meta['Expire-at'].should ==
+              expect(stored_file.meta['Expire-at']).to be ==
                   (Time.now + Coquelicot.settings.maximum_expire * 60).to_i
             end
           end
@@ -191,7 +191,7 @@ module Coquelicot
              :expire_at => (Time.now + Coquelicot.settings.maximum_expire * 60 + 5).to_i)
         end
         it 'should issue a warning' do
-          output.should_receive(:puts).
+          expect(output).to receive(:puts).
               with(/^W: R[0-9a-z]{32} expiration time has been reduced/)
           migrator.migrate!
         end
@@ -205,7 +205,7 @@ module Coquelicot
             Timecop.freeze(Time.now) do
               migrator.migrate!
               stored_file = get_first_migrated_file
-              stored_file.meta['Expire-at'].should ==
+              expect(stored_file.meta['Expire-at']).to be ==
                   (Time.now + Coquelicot.settings.maximum_expire * 60).to_i
             end
           end
@@ -218,7 +218,7 @@ module Coquelicot
                                         :expire_at => 'unparseable')
         end
         it 'should issue a warning' do
-          output.should_receive(:puts).
+          expect(output).to receive(:puts).
               with(/^W: R[0-9a-z]{32} has an unparseable expiration time\. Skipping\./)
           migrator.migrate!
         end
@@ -235,7 +235,7 @@ module Coquelicot
           FileUtils.rm(File.expand_path(File.basename(__FILE__), "#{@jyraphe_var_path}/files"))
         end
         it 'should issue a warning' do
-          output.should_receive(:puts).
+          expect(output).to receive(:puts).
               with(/^W: R[0-9a-z]{32} refers to a non-existent file\. Skipping\./)
           migrator.migrate!
         end
@@ -252,7 +252,7 @@ module Coquelicot
           File.truncate(File.expand_path(File.basename(__FILE__), "#{@jyraphe_var_path}/files"), 0)
         end
         it 'should issue a warning' do
-          output.should_receive(:puts).
+          expect(output).to receive(:puts).
               with(/^W: R[0-9a-z]{32} refers to a file with mismatching size\. Skipping\./)
           migrator.migrate!
         end
@@ -278,21 +278,21 @@ module Coquelicot
           migrator.migrate!
         end
         it 'should begin with "RewriteEngine on"' do
-          migrator.apache_rewrites.should satisfy do |s|
+          expect(migrator.apache_rewrites).to satisfy do |s|
             s.start_with?('RewriteEngine on')
           end
         end
         context 'when given no prefix' do
           it 'should contain a rule appropriate for an .htaccess' do
             jyraphe, coquelicot = migrator.migrated.to_a[0]
-            migrator.apache_rewrites.split("\n").should include(
+            expect(migrator.apache_rewrites.split("\n")).to include(
                 "RewriteRule ^file-#{jyraphe}$ #{coquelicot} [L,R=301]")
           end
         end
         context 'when given a prefix' do
           it 'should contain rules with the prefix' do
             jyraphe, coquelicot = migrator.migrated.to_a[0]
-            migrator.apache_rewrites('/dl/').split("\n").should include(
+            expect(migrator.apache_rewrites('/dl/').split("\n")).to include(
                 "RewriteRule ^/dl/file-#{jyraphe}$ /dl/#{coquelicot} [L,R=301]")
           end
         end
@@ -308,10 +308,10 @@ module Coquelicot
         context 'when given no prefix' do
           it 'should contain two rule appropriate for an .htaccess' do
             jyraphe, coquelicot = migrator.migrated.to_a[0]
-            migrator.apache_rewrites.split("\n").should include(
+            expect(migrator.apache_rewrites.split("\n")).to include(
                 "RewriteRule ^file-#{jyraphe}$ #{coquelicot} [L,R=301]")
             jyraphe, coquelicot = migrator.migrated.to_a[1]
-            migrator.apache_rewrites.split("\n").should include(
+            expect(migrator.apache_rewrites.split("\n")).to include(
                 "RewriteRule ^file-#{jyraphe}$ #{coquelicot} [L,R=301]")
           end
         end
@@ -329,8 +329,8 @@ module Coquelicot
               JyrapheMigrator.run! []
             }.to raise_error(SystemExit)
           end
-          stderr.should =~ /Usage:/
-          stderr.should =~ /--help for more details/
+          expect(stderr).to match /Usage:/
+          expect(stderr).to match /--help for more details/
         end
       end
       context 'when given a path to a random directory' do
@@ -341,7 +341,7 @@ module Coquelicot
               JyrapheMigrator.run! [path]
             }.to raise_error(SystemExit)
           end
-          stderr.should =~ /is not a Jyraphe/
+          expect(stderr).to match /is not a Jyraphe/
         end
       end
       context 'when given a path to a Jyraphe var directory' do
@@ -350,12 +350,12 @@ module Coquelicot
           capture(:stdout) do
             JyrapheMigrator.run! [@jyraphe_var_path]
           end
-          Coquelicot.settings.depot_path.should == @depot_path
+          expect(Coquelicot.settings.depot_path).to be == @depot_path
         end
         it 'should migrate using the given Jyraphe var directory' do
           migrator = double('JyrapheMigrator').as_null_object
-          migrator.should_receive(:migrate!)
-          JyrapheMigrator.should_receive(:new).with(@jyraphe_var_path).
+          expect(migrator).to receive(:migrate!)
+          expect(JyrapheMigrator).to receive(:new).with(@jyraphe_var_path).
               and_return(migrator)
           capture(:stdout) do
             JyrapheMigrator.run! [@jyraphe_var_path]
@@ -363,19 +363,19 @@ module Coquelicot
         end
         it 'should print rewrite rules after migrating' do
           migrator = double('JyrapheMigrator').as_null_object
-          migrator.should_receive(:migrate!).ordered
-          migrator.should_receive(:apache_rewrites).ordered.and_return('rules')
+          expect(migrator).to receive(:migrate!).ordered
+          expect(migrator).to receive(:apache_rewrites).ordered.and_return('rules')
           JyrapheMigrator.stub(:new).and_return(migrator)
           stdout = capture(:stdout) do
             JyrapheMigrator.run! [@jyraphe_var_path]
           end
-          stdout.strip.should == 'rules'
+          expect(stdout.strip).to be == 'rules'
         end
       end
       context 'when using "-p"' do
         it 'should print rewrite rules using the given prefix' do
           migrator = double('JyrapheMigrator').as_null_object
-          migrator.should_receive(:apache_rewrites).with('/prefix/')
+          expect(migrator).to receive(:apache_rewrites).with('/prefix/')
           JyrapheMigrator.stub(:new).and_return(migrator)
           capture(:stdout) do
             JyrapheMigrator.run! ['-p', '/prefix/', @jyraphe_var_path]
@@ -389,7 +389,7 @@ module Coquelicot
               JyrapheMigrator.run! ['-h']
             }.to raise_error(SystemExit)
           end
-          stderr.should =~ /Usage:/
+          expect(stderr).to match /Usage:/
         end
       end
     end
index 60f47fe..c5337d5 100644 (file)
@@ -31,7 +31,7 @@ module Coquelicot::Rack
       context 'when given a block taking one argument' do
         it 'should run the block with a new parser as argument' do
           MultipartParser.parse(env) do |p|
-            p.should be_a(MultipartParser)
+            expect(p).to be_a(MultipartParser)
           end
         end
       end
@@ -48,7 +48,7 @@ module Coquelicot::Rack
       context 'when used once' do
         it 'should call the block on start' do
           mock = double
-          mock.should_receive(:act)
+          expect(mock).to receive(:act)
           MultipartParser.parse(env) do |p|
             p.start { mock.act }
           end
@@ -57,8 +57,8 @@ module Coquelicot::Rack
       context 'when used twice in a row' do
         it 'should call both blocks on start' do
           mock = double
-          mock.should_receive(:run).ordered
-          mock.should_receive(:walk).ordered
+          expect(mock).to receive(:run).ordered
+          expect(mock).to receive(:walk).ordered
           MultipartParser.parse(env) do |p|
             p.start { mock.run }
             p.start { mock.walk }
@@ -68,8 +68,8 @@ module Coquelicot::Rack
       context 'when used twice with steps inbetween' do
         it 'should call both blocks on start' do
           mock = double
-          mock.should_receive(:run).ordered
-          mock.should_receive(:walk).ordered
+          expect(mock).to receive(:run).ordered
+          expect(mock).to receive(:walk).ordered
           MultipartParser.parse(env) do |p|
             p.start { mock.run }
             p.many_fields
@@ -99,7 +99,7 @@ module Coquelicot::Rack
       context 'when used alone' do
         it 'should call the given block only once' do
           mock = double
-          mock.should_receive(:act).once
+          expect(mock).to receive(:act).once
           MultipartParser.parse(env) do |p|
             p.many_fields do |params|
               mock.act
@@ -109,7 +109,7 @@ module Coquelicot::Rack
         it 'should call the given block for all fields' do
           MultipartParser.parse(env) do |p|
             p.many_fields do |params|
-              params.should == { 'one' => '1', 'two' => '2', 'three' => '3' }
+              expect(params).to be == { 'one' => '1', 'two' => '2', 'three' => '3' }
             end
           end
         end
@@ -117,7 +117,7 @@ module Coquelicot::Rack
       context 'positioned after "field"' do
         it 'should call the given block only once' do
           mock = double
-          mock.should_receive(:act).once
+          expect(mock).to receive(:act).once
           MultipartParser.parse(env) do |p|
             p.field :one
             p.many_fields do |params|
@@ -129,7 +129,7 @@ module Coquelicot::Rack
           MultipartParser.parse(env) do |p|
             p.field :one
             p.many_fields do |params|
-              params.should == { 'two' => '2', 'three' => '3' }
+              expect(params).to be == { 'two' => '2', 'three' => '3' }
             end
           end
         end
@@ -137,7 +137,7 @@ module Coquelicot::Rack
       context 'positioned before "field"' do
         it 'should call the given block only once' do
           mock = double
-          mock.should_receive(:act).once
+          expect(mock).to receive(:act).once
           MultipartParser.parse(env) do |p|
             p.many_fields do |params|
               mock.act
@@ -148,7 +148,7 @@ module Coquelicot::Rack
         it 'should call the given block for the first two fields' do
           MultipartParser.parse(env) do |p|
             p.many_fields do |params|
-              params.should == { 'one' => '1', 'two' => '2' }
+              expect(params).to be == { 'one' => '1', 'two' => '2' }
             end
             p.field :three
           end
@@ -157,8 +157,8 @@ module Coquelicot::Rack
       context 'before and after "field"' do
         it 'should call each given block only once' do
           mock = double
-          mock.should_receive(:run).ordered
-          mock.should_receive(:walk).ordered
+          expect(mock).to receive(:run).ordered
+          expect(mock).to receive(:walk).ordered
           MultipartParser.parse(env) do |p|
             p.many_fields do |params|
               mock.run
@@ -172,11 +172,11 @@ module Coquelicot::Rack
         it 'should call each given block for the first and last fields, respectively' do
           MultipartParser.parse(env) do |p|
             p.many_fields do |params|
-              params.should == { 'one' => '1' }
+              expect(params).to be == { 'one' => '1' }
             end
             p.field :two
             p.many_fields do |params|
-              params.should == { 'three' => '3' }
+              expect(params).to be == { 'three' => '3' }
             end
           end
         end
@@ -202,9 +202,9 @@ module Coquelicot::Rack
       context 'when positioned like the request' do
         it 'should call a block for each field' do
           mock = double
-          mock.should_receive(:first).with('1').ordered
-          mock.should_receive(:second).with('2').ordered
-          mock.should_receive(:third).with('3').ordered
+          expect(mock).to receive(:first).with('1').ordered
+          expect(mock).to receive(:second).with('2').ordered
+          expect(mock).to receive(:third).with('3').ordered
           MultipartParser.parse(env) do |p|
             p.field(:one)   { |value| mock.first  value }
             p.field(:two)   { |value| mock.second value }
@@ -224,7 +224,7 @@ module Coquelicot::Rack
       context 'when request field does not match after many_fields' do
         it 'should not call the field block' do
           mock = double
-          mock.should_not_receive(:foo)
+          expect(mock).not_to receive(:foo)
           MultipartParser.parse(env) do |p|
             p.many_fields
             p.field(:whatever) { mock.foo }
@@ -234,7 +234,7 @@ module Coquelicot::Rack
       context 'when request field  match after many_fields' do
         it 'should call the field block' do
           mock = double
-          mock.should_receive(:foo).with('3')
+          expect(mock).to receive(:foo).with('3')
           MultipartParser.parse(env) do |p|
             p.many_fields
             p.field(:three) { |value| mock.foo(value) }
@@ -253,9 +253,9 @@ module Coquelicot::Rack
         context 'when positioned like the request' do
           it 'should call the given block in the right order' do
             mock = double
-            mock.should_receive(:first).ordered
-            mock.should_receive(:second).ordered
-            mock.should_receive(:third).ordered
+            expect(mock).to receive(:first).ordered
+            expect(mock).to receive(:second).ordered
+            expect(mock).to receive(:third).ordered
             MultipartParser.parse(env) do |p|
               p.field(:field1) { |value| mock.first }
               p.field(:field2) { |value| mock.second }
@@ -270,7 +270,7 @@ module Coquelicot::Rack
             MultipartParser.parse(env) do |p|
               p.many_fields
               p.file(:field3) do |filename, content_type, reader|
-                filename.should == filename
+                expect(filename).to be == filename
                 while reader.call; end # flush file data
               end
             end
@@ -279,7 +279,7 @@ module Coquelicot::Rack
             MultipartParser.parse(env) do |p|
               p.many_fields
               p.file(:field3) do |filename, content_type, reader|
-                content_type.should == 'text/plain'
+                expect(content_type).to be == 'text/plain'
                 while reader.call; end # flush file data
               end
             end
@@ -293,7 +293,7 @@ module Coquelicot::Rack
                 data << buf until (buf = reader.call).nil?
               end
             end
-            data.should == slurp(file)
+            expect(data).to be == slurp(file)
           end
         end
       end
@@ -308,9 +308,9 @@ module Coquelicot::Rack
         context 'when positioned like the request' do
           it 'should call the given block in the right order' do
             mock = double
-            mock.should_receive(:first).ordered
-            mock.should_receive(:second).ordered
-            mock.should_receive(:third).ordered
+            expect(mock).to receive(:first).ordered
+            expect(mock).to receive(:second).ordered
+            expect(mock).to receive(:third).ordered
             MultipartParser.parse(env) do |p|
               p.field(:field1) { |value| mock.first }
               p.file(:field2) do |filename, content_type, reader|
@@ -330,7 +330,7 @@ module Coquelicot::Rack
               end
               p.field(:field3)
             end
-            data.should == slurp(file)
+            expect(data).to be == slurp(file)
           end
         end
       end
@@ -344,8 +344,8 @@ module Coquelicot::Rack
         context 'when positioned like the request' do
           it 'should call the given block in the right order' do
             mock = double
-            mock.should_receive(:first).ordered
-            mock.should_receive(:second).ordered
+            expect(mock).to receive(:first).ordered
+            expect(mock).to receive(:second).ordered
             MultipartParser.parse(env) do |p|
               p.file(:field1) do |filename, content_type, reader|
                 mock.first
@@ -365,18 +365,18 @@ module Coquelicot::Rack
             data2 = ''
             MultipartParser.parse(env) do |p|
               p.file(:field1) do |filename, content_type, reader|
-                filename.should == filename1
+                expect(filename).to be == filename1
                 buf = ''
                 data1 << buf until (buf = reader.call).nil?
               end
               p.file(:field2) do |filename, content_type, reader|
-                filename.should == filename2
+                expect(filename).to be == filename2
                 buf = ''
                 data2 << buf until (buf = reader.call).nil?
               end
             end
-            data1.should == slurp(file1)
-            data2.should == slurp(file2)
+            expect(data1).to be == slurp(file1)
+            expect(data2).to be == slurp(file2)
           end
         end
       end
@@ -392,8 +392,8 @@ module Coquelicot::Rack
       end
       context 'when used once' do
         it 'should call the block on finish' do
-          mock = mock('Object')
-          mock.should_receive(:act)
+          mock = double
+          expect(mock).to receive(:act)
           MultipartParser.parse(env) do |p|
             p.finish { mock.act }
           end
@@ -402,8 +402,8 @@ module Coquelicot::Rack
       context 'when used twice in a row' do
         it 'should call both blocks on finish (in reverse order)' do
           mock = double
-          mock.should_receive(:run).ordered
-          mock.should_receive(:walk).ordered
+          expect(mock).to receive(:run).ordered
+          expect(mock).to receive(:walk).ordered
           MultipartParser.parse(env) do |p|
             p.finish { mock.walk }
             p.finish { mock.run }
@@ -413,8 +413,8 @@ module Coquelicot::Rack
       context 'when used twice with steps inbetween' do
         it 'should call both blocks on finish (in reverse order)' do
           mock = double
-          mock.should_receive(:run).ordered
-          mock.should_receive(:walk).ordered
+          expect(mock).to receive(:run).ordered
+          expect(mock).to receive(:walk).ordered
           MultipartParser.parse(env) do |p|
             p.finish { mock.walk }
             p.many_fields
index 0e5008b..57b55f9 100644 (file)
@@ -37,12 +37,12 @@ module Coquelicot::Rack
       context 'when receiving GET /' do
         let(:env) { { 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/' } }
         it 'should pass the request to the lower app' do
-          subject.body.should == 'Lower'
+          expect(subject.body).to be == 'Lower'
         end
         it 'should ensure the forwarded rack.input is rewindable' do
           spec_app = double
-          spec_app.should_receive(:call) do |env|
-            env['rack.input'].should respond_to(:rewind)
+          expect(spec_app).to receive(:call) do |env|
+            expect(env['rack.input']).to respond_to(:rewind)
             [200, {'Content-Type' => 'text/plain'}, ['mock']]
           end
           input = StringIO.new('foo=bar&quux=blabb')
@@ -54,7 +54,7 @@ module Coquelicot::Rack
       context 'when called for GET /upload' do
         let(:env) { { 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/upload' } }
         it 'should pass the request to the lower app' do
-          subject.body.should == 'Lower'
+          expect(subject.body).to be == 'Lower'
         end
       end
       context 'when called for POST /upload' do
@@ -70,7 +70,7 @@ module Coquelicot::Rack
           let(:input) { '' }
           it 'should log a warning during the first request' do
             logger = double('Logger')
-            logger.should_receive(:warn).with(/rewindable/).once
+            expect(logger).to receive(:warn).with(/rewindable/).once
             env['rack.logger'] = logger
             # set it to nil to stop Sinatra from messing up
             upload = Class.new(Upload) { set :logging, nil }.new(lower_app)
@@ -124,14 +124,14 @@ MULTIPART_DATA
             Coquelicot.settings.authenticator.stub(:authenticate).and_return(true)
           end
           it 'should issue a temporary redirect' do
-            subject.status.should satisfy{|s| [302,303].include?(s) }
+            expect(subject.status).to satisfy{|s| [302,303].include?(s) }
           end
           it 'should redirect to the ready page' do
-            subject.headers['Location'].should =~ %r{http://example\.org/ready/}
+            expect(subject.headers['Location']).to match %r{http://example\.org/ready/}
           end
           it 'should add a file to the depot' do
             filename = File.basename(file)
-            Coquelicot.depot.should_receive(:add_file).
+            expect(Coquelicot.depot).to receive(:add_file).
                 with(file_key, hash_including('Filename' => filename)).
                 and_yield.and_yield
             subject
@@ -148,13 +148,13 @@ MULTIPART_DATA
           end
           context 'when there is a request Content-Length header' do
             it 'should bail out with 413 (Request Entity Too Large)' do
-              subject.status.should == 413
+              expect(subject.status).to be == 413
             end
             it 'should display "File is bigger than maximum allowed size"' do
-              subject.body.should include('File is bigger than maximum allowed size')
+              expect(subject.body).to include('File is bigger than maximum allowed size')
             end
             it 'should display the maximum file size' do
-              subject.body.should include('100 B')
+              expect(subject.body).to include('100 B')
             end
           end
           context 'when there is no request Content-Length header' do
@@ -162,13 +162,13 @@ MULTIPART_DATA
               env['CONTENT_LENGTH'] = nil
             end
             it 'should bail out with 413 (Request Entity Too Large)' do
-              subject.status.should == 413
+              expect(subject.status).to be == 413
             end
             it 'should display "File is bigger than maximum allowed size"' do
-              subject.body.should include('File is bigger than maximum allowed size')
+              expect(subject.body).to include('File is bigger than maximum allowed size')
             end
             it 'should display the maximum file size' do
-              subject.body.should include('100 B')
+              expect(subject.body).to include('100 B')
             end
           end
           context 'when the request Content-Length header is lying to us' do
@@ -176,13 +176,13 @@ MULTIPART_DATA
               env['CONTENT_LENGTH'] = 99
             end
             it 'should bail out with 413 (Request Entity Too Large)' do
-              subject.status.should == 413
+              expect(subject.status).to be == 413
             end
             it 'should display "File is bigger than maximum allowed size"' do
-              subject.body.should include('File is bigger than maximum allowed size')
+              expect(subject.body).to include('File is bigger than maximum allowed size')
             end
             it 'should display the maximum file size' do
-              subject.body.should include('100 B')
+              expect(subject.body).to include('100 B')
             end
           end
         end
@@ -222,7 +222,7 @@ MULTIPART_DATA
             subject.status == 400
           end
           it 'should display "Bad Request: fields in unacceptable order"' do
-            subject.body.should include('Bad Request: fields in unacceptable order')
+            expect(subject.body).to include('Bad Request: fields in unacceptable order')
           end
         end
         context 'when authentication fails' do
@@ -234,7 +234,7 @@ MULTIPART_DATA
             subject.status == 403
           end
           it 'should display "Forbidden"' do
-            subject.body.should include('Forbidden')
+            expect(subject.body).to include('Forbidden')
           end
           it 'should not add a file' do
             expect { subject }.to_not change { Coquelicot.depot.size }
@@ -250,7 +250,7 @@ MULTIPART_DATA
             subject.status == 503
           end
           it 'should display the error message' do
-            subject.body.should include('Something bad happened!')
+            expect(subject.body).to include('Something bad happened!')
           end
           it 'should not add a file' do
             expect { subject }.to_not change { Coquelicot.depot.size }
@@ -281,22 +281,22 @@ MULTIPART_DATA
             Coquelicot.settings.authenticator.stub(:authenticate).and_return(true)
           end
           it 'should pass to the lower app' do
-            subject.body.should == 'Lower'
+            expect(subject.body).to be == 'Lower'
           end
           it 'should set X_COQUELICOT_FORWARD in env' do
             mock_app = double
-            mock_app.should_receive(:call).
+            expect(mock_app).to receive(:call).
                 with(hash_including('X_COQUELICOT_FORWARD')).
                 and_return([200, {'Content-Type' => 'text/plain'}, ['forward mock']])
             Upload.new(mock_app).call(env)
           end
           it 'should forward interesting params' do
             mock_app = double
-            mock_app.should_receive(:call) do
+            expect(mock_app).to receive(:call) do
               request = Sinatra::Request.new(env)
-              request.params['upload_password'].should == 'whatever'
-              request.params['expire'].should == '60'
-              request.params['one_time'].should == 'true'
+              expect(request.params['upload_password']).to be == 'whatever'
+              expect(request.params['expire']).to be == '60'
+              expect(request.params['one_time']).to be == 'true'
               [200, {'Content-Type' => 'text/plain'}, ['forward mock']]
             end
             Upload.new(mock_app).call(env)
@@ -315,7 +315,7 @@ MULTIPART_DATA
             subject.status == 403
           end
           it 'should display "Forbidden: expiration time too big"' do
-            subject.body.should include('Forbidden: expiration time too big')
+            expect(subject.body).to include('Forbidden: expiration time too big')
           end
           it 'should not add a file' do
             expect { subject }.to_not change { Coquelicot.depot.size }
index 8e75032..d1d126a 100644 (file)
@@ -72,7 +72,7 @@ module Coquelicot
         let(:hmac) { (1..hmac_len).to_a.collect { |c| c.chr }.join }
         context "when given #{method} as method" do
           it 'should use PKCS5.pbkdf2_hmac_sha1' do
-            OpenSSL::PKCS5.should_receive(:pbkdf2_hmac_sha1).
+            expect(OpenSSL::PKCS5).to receive(:pbkdf2_hmac_sha1).
               with('secret', 'salt', 2000, hmac_len).
               and_return(hmac)
             StoredFile.get_cipher('secret', 'salt', method)
@@ -81,7 +81,7 @@ module Coquelicot
             OpenSSL::PKCS5.stub(:pbkdf2_hmac_sha1).
               and_return(hmac)
             cipher = OpenSSL::Cipher.new 'AES-256-CBC'
-            cipher.should_receive(:key=).with(hmac[0..key_len-1])
+            expect(cipher).to receive(:key=).with(hmac[0..key_len-1])
             OpenSSL::Cipher.stub(:new).and_return(cipher)
             StoredFile.get_cipher('secret', 'salt', method)
           end
@@ -89,13 +89,13 @@ module Coquelicot
             OpenSSL::PKCS5.stub(:pbkdf2_hmac_sha1).
               and_return(hmac)
             cipher = OpenSSL::Cipher.new 'AES-256-CBC'
-            cipher.should_receive(:iv=).with(hmac[key_len..-1])
+            expect(cipher).to receive(:iv=).with(hmac[key_len..-1])
             OpenSSL::Cipher.stub(:new).and_return(cipher)
             StoredFile.get_cipher('secret', 'salt', method)
           end
           it 'should return an OpenSSL::Cipher' do
             cipher = StoredFile.get_cipher('secret', 'salt', method)
-            cipher.should be_a(OpenSSL::Cipher)
+            expect(cipher).to be_a(OpenSSL::Cipher)
           end
         end
       end
@@ -106,7 +106,7 @@ module Coquelicot
         StoredFile.gen_salt.length == StoredFile::SALT_LEN
       end
       it 'should call OpenSSL::Random every time' do
-        OpenSSL::Random.should_receive(:random_bytes).
+        expect(OpenSSL::Random).to receive(:random_bytes).
             and_return(1, 2)
         StoredFile.gen_salt == 1
         StoredFile.gen_salt == 2
@@ -185,14 +185,14 @@ module Coquelicot
         end
         let(:clear_meta) { read_meta(@stored_file_path) }
         it 'should write Coquelicot file version' do
-          clear_meta['Coquelicot'].should == '2.0'
+          expect(clear_meta['Coquelicot']).to be == '2.0'
         end
         it 'should generate a random Salt' do
           salt = Base64.decode64(clear_meta['Salt'])
-          salt.should == test_salt
+          expect(salt).to be == test_salt
         end
         it 'should record expiration time' do
-          clear_meta['Expire-at'].should == expire_at
+          expect(clear_meta['Expire-at']).to be == expire_at
         end
       end
       shared_context 'in encrypted part' do |path_regex|
@@ -208,7 +208,7 @@ module Coquelicot
           StoredFile.stub(:get_cipher).and_return(cipher)
           @content = StringIO.new
           open = File.method(:open)
-          File.should_receive(:open).at_least(1).times do |path, *args, &block|
+          expect(File).to receive(:open).at_least(1).times do |path, *args, &block|
             if path =~ path_regex
               ret = block.call(@content)
               @cipher = cipher.dup
@@ -223,8 +223,8 @@ module Coquelicot
         include_context 'in encrypted part', /stored_file$/
         it 'should contain metadata as YAML block' do
           create_stored_file
-          @cipher.content.split(/^---(?: |\n)/, 3).length.should == 2
-          YAML.load(@cipher.content).should be_a(Hash)
+          expect(@cipher.content.split(/^---(?: |\n)/, 3).length).to be == 2
+          expect(YAML.load(@cipher.content)).to be_a(Hash)
         end
         context 'in encrypted metadata' do
           before(:each) do
@@ -232,10 +232,10 @@ module Coquelicot
             @meta = YAML.load(@cipher.content)
           end
           it 'should contain Length' do
-            @meta['Length'].should == @src_length
+            expect(@meta['Length']).to be == @src_length
           end
           it 'should Created-at' do
-            @meta.should include('Created-at')
+            expect(@meta).to include('Created-at')
           end
         end
       end
@@ -245,7 +245,7 @@ module Coquelicot
           create_stored_file
         end
         it 'should contain the file content' do
-          @cipher.content.should == slurp(@src)
+          expect(@cipher.content).to be == slurp(@src)
         end
         it 'should have the whole file for encrypted content' do
           @content.string == slurp(@src)
@@ -274,13 +274,13 @@ module Coquelicot
           Timecop.freeze(2012, 1, 1) do
             create_stored_file
             stored_file = StoredFile.open(@stored_file_path, @pass)
-            stored_file.created_at.should == Time.local(2012, 1, 1)
+            expect(stored_file.created_at).to be == Time.local(2012, 1, 1)
           end
         end
       end
       for_all_file_versions do
         it 'should return the creation time' do
-          stored_file.created_at.should == Time.at(reference['Created-at'])
+          expect(stored_file.created_at).to be == Time.at(reference['Created-at'])
         end
       end
     end
@@ -291,11 +291,11 @@ module Coquelicot
         it 'should return the date of expiration' do
           create_stored_file('Expire-at' => Time.local(2012, 1, 1))
           stored_file = StoredFile.open(@stored_file_path, @pass)
-          stored_file.expire_at.should == Time.local(2012, 1, 1)
+          expect(stored_file.expire_at).to be == Time.local(2012, 1, 1)
         end
       end
       for_all_file_versions do
-        specify { stored_file.expire_at.should == Time.at(reference['Expire-at']) }
+        specify { expect(stored_file.expire_at).to be == Time.at(reference['Expire-at']) }
       end
     end
 
@@ -306,7 +306,7 @@ module Coquelicot
           Timecop.freeze do
             create_stored_file('Expire-at' => Time.now - 60)
             stored_file = StoredFile.open(@stored_file_path, @pass)
-            stored_file.should be_expired
+            expect(stored_file).to be_expired
           end
         end
       end
@@ -315,7 +315,7 @@ module Coquelicot
           Timecop.freeze do
             create_stored_file('Expire-at' => Time.now + 60)
             stored_file = StoredFile.open(@stored_file_path, @pass)
-            stored_file.should_not be_expired
+            expect(stored_file).not_to be_expired
           end
         end
       end
@@ -327,14 +327,14 @@ module Coquelicot
         it 'should be true' do
           create_stored_file('One-time-only' => true)
           stored_file = StoredFile.open(@stored_file_path, @pass)
-          stored_file.should be_one_time_only
+          expect(stored_file).to be_one_time_only
         end
       end
       context 'when file is not labelled as "one time only"' do
         it 'should be false' do
           create_stored_file
           stored_file = StoredFile.open(@stored_file_path, @pass)
-          stored_file.should_not be_one_time_only
+          expect(stored_file).not_to be_one_time_only
         end
       end
     end
@@ -349,11 +349,11 @@ module Coquelicot
         end
         it 'should overwrite file contents with \0' do
           Dir.glob("#{@stored_file_path}*").each do |path|
-            File.should_receive(:open) do |*args, &block|
+            expect(File).to receive(:open) do |*args, &block|
               length = File.stat(path).size
               file = StringIO.new(slurp(path))
               block.call(file)
-              file.string.should == "\0" * length
+              expect(file.string).to be == "\0" * length
             end
           end
           @stored_file.empty!
@@ -361,7 +361,7 @@ module Coquelicot
         it 'should truncate files' do
           @stored_file.empty!
           Dir.glob("#{@stored_file_path}*").each do |path|
-            File.stat(path).size.should == 0
+            expect(File.stat(path).size).to be == 0
           end
         end
       end
@@ -371,11 +371,11 @@ module Coquelicot
       for_all_file_versions do
         let(:stored_file) { StoredFile.open(stored_file_path, 'secret') }
         it 'should return a Lockfile' do
-          stored_file.lockfile.should be_a(Lockfile)
+          expect(stored_file.lockfile).to be_a(Lockfile)
         end
         it 'should create a Lockfile using the path followed by ".lock"' do
-          Lockfile.should_receive(:new) do |path, options|
-            path.should == "#{stored_file_path}.lock"
+          expect(Lockfile).to receive(:new) do |path, options|
+            expect(path).to be == "#{stored_file_path}.lock"
           end
           stored_file.lockfile
         end
@@ -390,7 +390,7 @@ module Coquelicot
             stored_file.each do |data|
               buf << data
             end
-            buf.should == reference['Content']
+            expect(buf).to be == reference['Content']
           end
         end
       end
@@ -414,7 +414,7 @@ module Coquelicot
           StoredFile.stub(:get_cipher).and_return(cipher)
 
           stored_file = StoredFile.open(stored_file_path, 'secret')
-          cipher.should_receive(:reset)
+          expect(cipher).to receive(:reset)
           stored_file.close
         end
       end
@@ -437,7 +437,7 @@ module Coquelicot
             another = StoredFile.open(@stored_file_path, @pass)
             buf = ''
             another.each { |data| buf << data }
-            buf.should == slurp(@src)
+            expect(buf).to be == slurp(@src)
           end
         end
         context 'when the file has been fully sent' do
@@ -446,7 +446,7 @@ module Coquelicot
             @stored_file.each { |data| nil }
           end
           it 'should empty the file' do
-            @stored_file.should_receive(:empty!)
+            expect(@stored_file).to receive(:empty!)
             @stored_file.close
           end
         end
index 226ab87..c45b846 100644 (file)
@@ -54,7 +54,7 @@ describe 'Coquelicot' do
                         }
     return nil unless last_response.redirect?
     follow_redirect!
-    last_response.should be_ok
+    expect(last_response).to be_ok
     doc = Hpricot(last_response.body)
     return (doc/'.ready')[0].inner_text
   end
@@ -83,17 +83,17 @@ PART
 
   it "should offer an upload form" do
     get '/'
-    last_response.should be_ok
+    expect(last_response).to be_ok
     doc = Hpricot(last_response.body)
-    (doc/"form#upload").should have(1).items
+    expect(doc/"form#upload").to have(1).items
   end
 
   context "when I explicitely ask for french" do
     it "should offer an upload form in french" do
       get '/', :lang => 'fr'
-      last_response.should be_ok
+      expect(last_response).to be_ok
       doc = Hpricot(last_response.body)
-      (doc/"#submit").attr('value').should == 'Partager !'
+      expect((doc/"#submit").attr('value')).to be == 'Partager !'
     end
   end
 
@@ -110,37 +110,37 @@ PART
 
       it "should not store the file in cleartext" do
         files = Dir.glob("#{Coquelicot.depot.path}/*")
-        files.should have(2).items
-        File.new(files[0]).read().should_not include('should not store an uploaded file')
+        expect(files).to have(2).items
+        expect(File.new(files[0]).read()).to_not include('should not store an uploaded file')
       end
 
       it "should generate a random URL to download the file" do
-        @url.should_not include(File.basename(__FILE__))
+        expect(@url).to_not include(File.basename(__FILE__))
       end
 
       it "should store the file with a different name than the one in URL" do
         url_name = @url.split('/')[-1]
         files = Dir.glob("#{Coquelicot.depot.path}/*")
-        files.should have(2).items
-        url_name.should_not eql(File.basename(files[0]))
+        expect(files).to have(2).items
+        expect(url_name).to_not eql(File.basename(files[0]))
       end
 
       it "should encode the encryption key in URL as no password has been specified" do
         url_name = @url.split('/')[-1]
-        url_name.split('-').should have(2).items
+        expect(url_name.split('-')).to have(2).items
       end
 
       it "should say 'not found' is password in URL is wrong" do
         get "#{@url}wrong"
-        last_response.status.should == 404
+        expect(last_response.status).to be == 404
       end
 
       it "should download when using extra Base32 characters in URL" do
         splitted = @url.split('/')
         name = splitted[-1].upcase.gsub(/O/, '0').gsub(/L/, '1')
         get "#{splitted[0..-2].join '/'}/#{name}"
-        last_response.should be_ok
-        last_response['Content-Type'].should eql('text/x-script.ruby')
+        expect(last_response).to be_ok
+        expect(last_response['Content-Type']).to eql('text/x-script.ruby')
       end
 
       context "when the file has been downloaded" do
@@ -149,21 +149,21 @@ PART
         end
 
         it "should be the same file as the uploaded" do
-          last_response.should be_ok
-          last_response['Content-Type'].should eql('text/x-script.ruby')
-          last_response.body.should == slurp(__FILE__)
+          expect(last_response).to be_ok
+          expect(last_response['Content-Type']).to eql('text/x-script.ruby')
+          expect(last_response.body).to be == slurp(__FILE__)
         end
 
         it "should have sent the right Content-Length" do
-          last_response.should be_ok
-          last_response['Content-Length'].to_i.should == File.stat(__FILE__).size
+          expect(last_response).to be_ok
+          expect(last_response['Content-Length'].to_i).to be == File.stat(__FILE__).size
         end
 
         it "should always has the same Last-Modified header" do
           last_modified = last_response['Last-Modified']
-          last_modified.should_not be_nil
+          expect(last_modified).to_not be_nil
           get @url
-          last_response['Last-Modified'].should eql(last_modified)
+          expect(last_response['Last-Modified']).to eql(last_modified)
         end
       end
     end
@@ -174,8 +174,8 @@ PART
       end
       it "should not be accepted when uploaded" do
         url = upload :file => Rack::Test::UploadedFile.new(@empty_file.path, 'text/plain')
-        url.should be_nil
-        last_response.should_not be_redirect
+        expect(url).to be_nil
+        expect(last_response).to_not be_redirect
       end
       after do
         @empty_file.close true
@@ -184,14 +184,14 @@ PART
 
     it "should prevent upload without a password" do
       url = upload :upload_password => ''
-      url.should be_nil
-      last_response.status.should eql(403)
+      expect(url).to be_nil
+      expect(last_response.status).to eql(403)
     end
 
     it "should prevent upload with a wrong password" do
       url = upload :upload_password => 'bad'
-      url.should be_nil
-      last_response.status.should eql(403)
+      expect(url).to be_nil
+      expect(last_response.status).to eql(403)
     end
 
     context "when using AJAX to verify upload password" do
@@ -228,20 +228,20 @@ PART
       end
 
       it "should be the same as the uploaded file" do
-        last_response.should be_ok
-        last_response['Content-Type'].should eql('text/x-script.ruby')
-        last_response.body.should == slurp(__FILE__)
+        expect(last_response).to be_ok
+        expect(last_response['Content-Type']).to eql('text/x-script.ruby')
+        expect(last_response.body).to be == slurp(__FILE__)
       end
 
       it "should not be downloadable any more" do
         get @url
-        last_response.status.should eql(410)
+        expect(last_response.status).to eql(410)
       end
 
       it "should have zero'ed the file on the server" do
         files = Dir.glob("#{Coquelicot.depot.path}/*")
-        files.should have(2).items
-        File.lstat(files[0]).size.should eql(0)
+        expect(files).to have(2).items
+        expect(File.lstat(files[0]).size).to eql(0)
       end
     end
 
@@ -252,34 +252,34 @@ PART
 
       it "should not return an URL with the encryption key" do
         url_name = @url.split('/')[-1]
-        url_name.split('-').should have(1).items
+        expect(url_name.split('-')).to have(1).items
       end
 
       it "should offer a password form before download" do
         get @url
-        last_response.should be_ok
-        last_response['Content-Type'].should eql('text/html;charset=utf-8')
+        expect(last_response).to be_ok
+        expect(last_response['Content-Type']).to be == 'text/html;charset=utf-8'
         doc = Hpricot(last_response.body)
-        (doc/'input#file_key').should have(1).items
+        expect(doc/'input#file_key').to have(1).items
       end
 
       context "when given the correct password" do
         it "should download the same file" do
           post @url, :file_key => 'somethingSecret'
-          last_response.should be_ok
-          last_response['Content-Type'].should eql('text/x-script.ruby')
-          last_response.body.should == slurp(__FILE__)
+          expect(last_response).to be_ok
+          expect(last_response['Content-Type']).to be == 'text/x-script.ruby'
+          expect(last_response.body).to be == slurp(__FILE__)
         end
       end
 
       it "should prevent download without a password" do
         post @url
-        last_response.status.should eql(403)
+        expect(last_response.status).to eql(403)
       end
 
       it "should prevent download with a wrong password" do
         post @url, :file_key => 'BAD'
-        last_response.status.should eql(403)
+        expect(last_response.status).to eql(403)
       end
     end
 
@@ -292,33 +292,33 @@ PART
         # let's be the day after tomorrow
         Timecop.travel(Date.today + 2) do
           get @url
-          last_response.status.should eql(410)
+          expect(last_response.status).to eql(410)
         end
       end
     end
 
     it "should refuse an expiration time longer than the maximum" do
       upload :expire => 60 * 24 * 31 * 12 # 1 year
-      last_response.status.should eql(403)
+      expect(last_response.status).to eql(403)
     end
 
     it "should cleanup expired files" do
       url = upload :expire => 60, :file_key => 'test' # 1 hour
       url_name = url.split('/')[-1]
-      Dir.glob("#{Coquelicot.depot.path}/*").should have(2).items
+      expect(Dir.glob("#{Coquelicot.depot.path}/*")).to have(2).items
       # let's be the day after tomorrow
       Timecop.travel(Date.today + 2) do
         Coquelicot.depot.gc!
         files = Dir.glob("#{Coquelicot.depot.path}/*")
-        files.should have(2).items
-        File.lstat(files[0]).size.should eql(0)
-        Coquelicot.depot.get_file(url_name).expired?.should be_true
+        expect(files).to have(2).items
+        expect(File.lstat(files[0]).size).to eql(0)
+        expect(Coquelicot.depot.get_file(url_name)).to be_expired
       end
       # let's be after 'gone' period
       Timecop.travel(Time.now + (Coquelicot.settings.gone_period * 60)) do
         Coquelicot.depot.gc!
-        Dir.glob("#{Coquelicot.depot.path}/*").should have(0).items
-        Coquelicot.depot.get_file(url_name).should be_nil
+        expect(Dir.glob("#{Coquelicot.depot.path}/*")).to be_empty
+        expect(Coquelicot.depot.get_file(url_name)).to be_nil
       end
     end
   end
@@ -331,14 +331,14 @@ PART
     end
 
     it "should try to login to the IMAP server when using AJAX" do
-      imap = stub('Net::Imap').as_null_object
-      imap.should_receive(:login).with('user', 'password')
-      Net::IMAP.should_receive(:new).with('example.org', 993, true).and_return(imap)
+      imap = double('Net::Imap').as_null_object
+      expect(imap).to receive(:login).with('user', 'password')
+      expect(Net::IMAP).to receive(:new).with('example.org', 993, true).and_return(imap)
 
       request "/authenticate", :method => "POST", :xhr => true,
                                :params => { :imap_user     => 'user',
                                             :imap_password => 'password' }
-      last_response.should be_ok
+      expect(last_response).to be_ok
     end
   end
 end
index 7a49544..20ea845 100644 (file)
@@ -109,4 +109,8 @@ end
 ::RSpec.configure do |c|
   c.extend StoredFileHelpers
   c.include CoquelicotSpecHelpers
+
+  c.expect_with :rspec do |e|
+    e.syntax = :expect
+  end
 end