RSpec 3-不建议使用“应该”

问题描述 投票: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.