spec/reloader_spec.rb in sinatra-contrib-1.4.7 vs spec/reloader_spec.rb in sinatra-contrib-2.0.0.beta1

- old
+ new

@@ -86,35 +86,35 @@ before(:each) do setup_example_app(:routes => ['get("/foo") { "foo" }']) end it "doesn't mess up the application" do - get('/foo').body.should == 'foo' + expect(get('/foo').body).to eq('foo') end it "knows when a route has been modified" do update_app_file(:routes => ['get("/foo") { "bar" }']) - get('/foo').body.should == 'bar' + expect(get('/foo').body).to eq('bar') end it "knows when a route has been added" do update_app_file( :routes => ['get("/foo") { "foo" }', 'get("/bar") { "bar" }'] ) - get('/foo').body.should == 'foo' - get('/bar').body.should == 'bar' + expect(get('/foo').body).to eq('foo') + expect(get('/bar').body).to eq('bar') end it "knows when a route has been removed" do update_app_file(:routes => ['get("/bar") { "bar" }']) - get('/foo').status.should == 404 + expect(get('/foo').status).to eq(404) end it "doesn't try to reload a removed file" do update_app_file(:routes => ['get("/foo") { "i shall not be reloaded" }']) FileUtils.rm app_file_path - get('/foo').body.strip.should == 'foo' + expect(get('/foo').body.strip).to eq('foo') end end describe "default inline templates reloading mechanism" do before(:each) do @@ -123,34 +123,34 @@ :inline_templates => { :foo => 'foo' } ) end it "doesn't mess up the application" do - get('/foo').body.strip.should == 'foo' + expect(get('/foo').body.strip).to eq('foo') end it "reloads inline templates in the app file" do update_app_file( :routes => ['get("/foo") { erb :foo }'], :inline_templates => { :foo => 'bar' } ) - get('/foo').body.strip.should == 'bar' + expect(get('/foo').body.strip).to eq('bar') end it "reloads inline templates in other file" do setup_example_app(:routes => ['get("/foo") { erb :foo }']) template_file_path = File.join(tmp_dir, 'templates.rb') File.open(template_file_path, 'w') do |f| f.write "__END__\n\n@@foo\nfoo" end require template_file_path app_const.inline_templates= template_file_path - get('/foo').body.strip.should == 'foo' + expect(get('/foo').body.strip).to eq('foo') update_file(template_file_path) do |f| f.write "__END__\n\n@@foo\nbar" end - get('/foo').body.strip.should == 'bar' + expect(get('/foo').body.strip).to eq('bar') end end describe "default middleware reloading mechanism" do it "knows when a middleware has been added" do @@ -158,21 +158,21 @@ update_app_file( :routes => ['get("/foo") { "foo" }'], :middlewares => [Rack::Head] ) get('/foo') # ...to perform the reload - app_const.middleware.should_not be_empty + expect(app_const.middleware).not_to be_empty end it "knows when a middleware has been removed" do setup_example_app( :routes => ['get("/foo") { "foo" }'], :middlewares => [Rack::Head] ) update_app_file(:routes => ['get("/foo") { "foo" }']) get('/foo') # ...to perform the reload - app_const.middleware.should be_empty + expect(app_const.middleware).to be_empty end end describe "default filter reloading mechanism" do it "knows when a before filter has been added" do @@ -227,33 +227,33 @@ :errors => { 403 => "'Access forbiden'" } ) end it "doesn't mess up the application" do - get('/secret').should be_client_error - get('/secret').body.strip.should == 'Access forbiden' + expect(get('/secret')).to be_client_error + expect(get('/secret').body.strip).to eq('Access forbiden') end it "knows when a error has been added" do update_app_file(:errors => { 404 => "'Nowhere'" }) - get('/nowhere').should be_not_found - get('/nowhere').body.should == 'Nowhere' + expect(get('/nowhere')).to be_not_found + expect(get('/nowhere').body).to eq('Nowhere') end it "knows when a error has been removed" do update_app_file(:routes => ['get("/secret") { 403 }']) - get('/secret').should be_client_error - get('/secret').body.should_not == 'Access forbiden' + expect(get('/secret')).to be_client_error + expect(get('/secret').body).not_to eq('Access forbiden') end it "knows when a error has been modified" do update_app_file( :routes => ['get("/secret") { 403 }'], :errors => { 403 => "'What are you doing here?'" } ) - get('/secret').should be_client_error - get('/secret').body.should == 'What are you doing here?' + expect(get('/secret')).to be_client_error + expect(get('/secret').body).to eq('What are you doing here?') end end describe "extension reloading" do it "doesn't duplicate routes with every reload" do @@ -350,24 +350,24 @@ end it "allows to specify a file to stop from being reloaded" do app_const.dont_reload app_file_path update_app_file(:routes => ['get("/foo") { "bar" }']) - get('/foo').body.strip.should == 'foo' + expect(get('/foo').body.strip).to eq('foo') end it "allows to specify a glob to stop matching files from being reloaded" do app_const.dont_reload '**/*.rb' update_app_file(:routes => ['get("/foo") { "bar" }']) - get('/foo').body.strip.should == 'foo' + expect(get('/foo').body.strip).to eq('foo') end it "doesn't interfere with other application's reloading policy" do app_const.dont_reload '**/*.rb' setup_example_app(:routes => ['get("/foo") { "foo" }']) update_app_file(:routes => ['get("/foo") { "bar" }']) - get('/foo').body.strip.should == 'bar' + expect(get('/foo').body.strip).to eq('bar') end end describe ".also_reload" do before(:each) do @@ -380,44 +380,69 @@ require @foo_path app_const.also_reload @foo_path end it "allows to specify a file to be reloaded" do - get('/foo').body.strip.should == 'foo' + expect(get('/foo').body.strip).to eq('foo') update_file(@foo_path) do |f| f.write 'class Foo; def self.foo() "bar" end end' end - get('/foo').body.strip.should == 'bar' + expect(get('/foo').body.strip).to eq('bar') end it "allows to specify glob to reaload matching files" do - get('/foo').body.strip.should == 'foo' + expect(get('/foo').body.strip).to eq('foo') update_file(@foo_path) do |f| f.write 'class Foo; def self.foo() "bar" end end' end - get('/foo').body.strip.should == 'bar' + expect(get('/foo').body.strip).to eq('bar') end it "doesn't try to reload a removed file" do update_file(@foo_path) do |f| f.write 'class Foo; def self.foo() "bar" end end' end FileUtils.rm @foo_path - get('/foo').body.strip.should == 'foo' + expect(get('/foo').body.strip).to eq('foo') end it "doesn't interfere with other application's reloading policy" do app_const.also_reload '**/*.rb' setup_example_app(:routes => ['get("/foo") { Foo.foo }']) - get('/foo').body.strip.should == 'foo' + expect(get('/foo').body.strip).to eq('foo') update_file(@foo_path) do |f| f.write 'class Foo; def self.foo() "bar" end end' end - get('/foo').body.strip.should == 'foo' + expect(get('/foo').body.strip).to eq('foo') end end + describe ".after_reload" do + before(:each) do + setup_example_app(:routes => ['get("/foo") { Foo.foo }']) + @foo_path = File.join(tmp_dir, 'foo.rb') + update_file(@foo_path) do |f| + f.write 'class Foo; def self.foo() "foo" end end' + end + $LOADED_FEATURES.delete @foo_path + require @foo_path + app_const.also_reload @foo_path + end + + it "allows block execution after reloading files" do + app_const.after_reload do + $reloaded = true + end + expect($reloaded).to eq(nil) + expect(get('/foo').body.strip).to eq('foo') + update_file(@foo_path) do |f| + f.write 'class Foo; def self.foo() "bar" end end' + end + expect($reloaded).to eq(true) + end + end + it "automatically registers the reloader in the subclasses" do class ::Parent < Sinatra::Base register Sinatra::Reloader enable :reloader end @@ -432,9 +457,9 @@ :routes => ['get("/foo") { "bar" }'], :enable_reloader => false, :parent => 'Parent' ) - get('/foo').body.should == 'bar' + expect(get('/foo').body).to eq('bar') end end