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

- old
+ new

@@ -38,66 +38,67 @@ respond_to do |format| format.html { "html!" } format.json { "json!" } end - req(:html).body.should == "html!" - req(:json).body.should == "json!" + expect(req(:html).body).to eq("html!") + expect(req(:json).body).to eq("json!") end it 'respects quality' do respond_to do |format| format.html { "html!" } format.json { "json!" } end - req("text/html;q=0.7, application/json;q=0.3").body.should == "html!" - req("text/html;q=0.3, application/json;q=0.7").body.should == "json!" + expect(req("text/html;q=0.7, application/json;q=0.3").body).to eq("html!") + expect(req("text/html;q=0.3, application/json;q=0.7").body).to eq("json!") end it 'allows using mime types' do respond_to do |format| format.on('text/html') { "html!" } format.json { "json!" } end - req(:html).body.should == "html!" + expect(req(:html).body).to eq("html!") end it 'allows using wildcards in format matchers' do respond_to do |format| format.on('text/*') { "text!" } format.json { "json!" } end - req(:html).body.should == "text!" + expect(req(:html).body).to eq("text!") end it 'allows using catch all wildcards in format matchers' do respond_to do |format| format.on('*/*') { "anything!" } format.json { "json!" } end - req(:html).body.should == "anything!" + expect(req(:html).body).to eq("anything!") end it 'prefers concret over generic' do respond_to do |format| format.on('text/*') { "text!" } format.on('*/*') { "anything!" } format.json { "json!" } end - req(:json).body.should == "json!" - req(:html).body.should == "text!" + expect(req(:json).body).to eq("json!") + expect(req(:html).body).to eq("text!") end it 'does not set up default handlers' do respond_to - req.should_not be_ok - status.should == 406 + expect(req).not_to be_ok + expect(status).to eq(500) + expect(body).to eq("Unknown template engine") end end describe "Helpers#respond_with" do describe "matching" do @@ -105,157 +106,158 @@ respond_with(:ignore) do |format| format.html { "html!" } format.json { "json!" } end - req(:html).body.should == "html!" - req(:json).body.should == "json!" + expect(req(:html).body).to eq("html!") + expect(req(:json).body).to eq("json!") end it 'respects quality' do respond_with(:ignore) do |format| format.html { "html!" } format.json { "json!" } end - req("text/html;q=0.7, application/json;q=0.3").body.should == "html!" - req("text/html;q=0.3, application/json;q=0.7").body.should == "json!" + expect(req("text/html;q=0.7, application/json;q=0.3").body).to eq("html!") + expect(req("text/html;q=0.3, application/json;q=0.7").body).to eq("json!") end it 'allows using mime types' do respond_with(:ignore) do |format| format.on('text/html') { "html!" } format.json { "json!" } end - req(:html).body.should == "html!" + expect(req(:html).body).to eq("html!") end it 'allows using wildcards in format matchers' do respond_with(:ignore) do |format| format.on('text/*') { "text!" } format.json { "json!" } end - req(:html).body.should == "text!" + expect(req(:html).body).to eq("text!") end it 'allows using catch all wildcards in format matchers' do respond_with(:ignore) do |format| format.on('*/*') { "anything!" } format.json { "json!" } end - req(:html).body.should == "anything!" + expect(req(:html).body).to eq("anything!") end it 'prefers concret over generic' do respond_with(:ignore) do |format| format.on('text/*') { "text!" } format.on('*/*') { "anything!" } format.json { "json!" } end - req(:json).body.should == "json!" - req(:html).body.should == "text!" + expect(req(:json).body).to eq("json!") + expect(req(:html).body).to eq("text!") end end describe "default behavior" do it 'converts objects to json out of the box' do respond_with 'a' => 'b' - OkJson.decode(req(:json).body).should == {'a' => 'b'} + expect(OkJson.decode(req(:json).body)).to eq({'a' => 'b'}) end it 'handles multiple routes correctly' do respond_app do get('/') { respond_with 'a' => 'b' } get('/:name') { respond_with 'a' => params[:name] } end - OkJson.decode(req('/', :json).body).should == {'a' => 'b'} - OkJson.decode(req('/b', :json).body).should == {'a' => 'b'} - OkJson.decode(req('/c', :json).body).should == {'a' => 'c'} + expect(OkJson.decode(req('/', :json).body)).to eq({'a' => 'b'}) + expect(OkJson.decode(req('/b', :json).body)).to eq({'a' => 'b'}) + expect(OkJson.decode(req('/c', :json).body)).to eq({'a' => 'c'}) end it "calls to_EXT if available" do respond_with Struct.new(:to_pdf).new("hello") - req(:pdf).body.should == "hello" + expect(req(:pdf).body).to eq("hello") end - it 'results in a 406 if format cannot be produced' do + it 'results in a 500 if format cannot be produced' do respond_with({}) - req(:html).should_not be_ok - status.should == 406 + expect(req(:html)).not_to be_ok + expect(status).to eq(500) + expect(body).to eq("Unknown template engine") end end describe 'templates' do it 'looks for templates with name.target.engine' do respond_with :foo, :name => 'World' - req(:html).should be_ok - body.should == "Hello World!" + expect(req(:html)).to be_ok + expect(body).to eq("Hello World!") end it 'looks for templates with name.engine for specific engines' do respond_with :bar - req(:html).should be_ok - body.should == "guten Tag!" + expect(req(:html)).to be_ok + expect(body).to eq("guten Tag!") end it 'does not use name.engine for engines producing other formats' do respond_with :not_html - req(:html).should_not be_ok - status.should == 406 - body.should be_empty + expect(req(:html)).not_to be_ok + expect(status).to eq(500) + expect(body).to eq("Unknown template engine") end it 'falls back to #json if no template is found' do respond_with :foo, :name => 'World' - req(:json).should be_ok - OkJson.decode(body).should == {'name' => 'World'} + expect(req(:json)).to be_ok + expect(OkJson.decode(body)).to eq({'name' => 'World'}) end it 'favors templates over #json' do respond_with :bar, :name => 'World' - req(:json).should be_ok - body.should == 'json!' + expect(req(:json)).to be_ok + expect(body).to eq('json!') end it 'falls back to to_EXT if no template is found' do object = {:name => 'World'} def object.to_pdf; "hi" end respond_with :foo, object - req(:pdf).should be_ok - body.should == "hi" + expect(req(:pdf)).to be_ok + expect(body).to eq("hi") end unless defined? JRUBY_VERSION it 'uses yajl for json' do respond_with :baz - req(:json).should be_ok - body.should == "\"yajl!\"" + expect(req(:json)).to be_ok + expect(body).to eq("\"yajl!\"") end end end describe 'customizing' do it 'allows customizing' do respond_with(:foo, :name => 'World') { |f| f.html { 'html!' }} - req(:html).should be_ok - body.should == "html!" + expect(req(:html)).to be_ok + expect(body).to eq("html!") end it 'falls back to default behavior if none matches' do respond_with(:foo, :name => 'World') { |f| f.json { 'json!' }} - req(:html).should be_ok - body.should == "Hello World!" + expect(req(:html)).to be_ok + expect(body).to eq("Hello World!") end it 'favors generic rule over default behavior' do respond_with(:foo, :name => 'World') { |f| f.on('*/*') { 'generic!' }} - req(:html).should be_ok - body.should == "generic!" + expect(req(:html)).to be_ok + expect(body).to eq("generic!") end end describe "inherited" do it "registers RespondWith in an inherited app" do @@ -268,11 +270,11 @@ respond_with :json end end self.app = Sinatra.new(app) - req('/a', :json).should_not be_ok + expect(req('/a', :json)).not_to be_ok end end end describe :respond_to do @@ -281,23 +283,23 @@ respond_to :json, :html get('/a') { 'ok' } get('/b') { 'ok' } end - req('/b', :xml).should_not be_ok - req('/b', :html).should be_ok + expect(req('/b', :xml)).not_to be_ok + expect(req('/b', :html)).to be_ok end it 'still allows provides' do respond_app do respond_to :json, :html get('/a') { 'ok' } get('/b', :provides => :json) { 'ok' } end - req('/b', :html).should_not be_ok - req('/b', :json).should be_ok + expect(req('/b', :html)).not_to be_ok + expect(req('/b', :json)).to be_ok end it 'plays well with namespaces' do respond_app do register Sinatra::Namespace @@ -306,10 +308,10 @@ get { 'json' } end get('/b') { 'anything' } end - req('/a', :html).should_not be_ok - req('/b', :html).should be_ok + expect(req('/a', :html)).not_to be_ok + expect(req('/b', :html)).to be_ok end end end