Rails 5.2 - 折旧“应该”

问题描述 投票:1回答:1

如果不推荐使用should,我不想启用它的用法。什么是新的expect语法?

   describe '#show response' do 
        it "should return html data only" do 
          get :show, params: {:id => "bike"}
          response.header['Content-Type'].should include 'text/html'
        end

        it "should not return json data" do 
          get :show, params: {:id => "bike"}
          response.header['Content-Type'].should_not include 'application/json'
        end

        it "should not return js data" do 
          get :show, params: {:id => "bike"}
          response.header['Content-Type'].should_not include 'text/javascript'
        end
      end
    end

弃用警告:

在不明确启用语法的情况下,使用来自rspec-expectations的旧should语法的:should已弃用。使用新的:expect语法或使用:should显式启用config.expect_with(:rspec) { |c| c.syntax = :should }

ruby-on-rails ruby-on-rails-5 rspec-rails
1个回答
1
投票

您可以考虑使用expect().to eq(),所以在您的情况下:

expect(response.header['Content-Type'].include?('text/html')).to be true
expect(response.header['Content-Type'].include?('application/json')).to be false
expect(response.header['Content-Type'].include?('text/javascript')).to be false

有关rspec匹配器的更多信息,请访问:https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers

© www.soinside.com 2019 - 2024. All rights reserved.