Rails 5.2-已贬值的“应该”

时间:2019-03-01 16:16:51

标签: ruby-on-rails ruby-on-rails-5 rspec-rails

如果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 }

1 个答案:

答案 0 :(得分: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