2

If should is deprecated, I do not want to enable it's usage. What is the new expect syntax for this?

   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

Deprecation Warnings:

Using should from rspec-expectations' old :should syntax without explicitly enabling the syntax is deprecated. Use the new :expect syntax or explicitly enable :should with config.expect_with(:rspec) { |c| c.syntax = :should } instead.

notapatch
  • 6,569
  • 6
  • 41
  • 45
user2012677
  • 5,465
  • 6
  • 51
  • 113
  • Rspec has fantastic documentation and expect syntax has been the default for quite a while now. For instance you are looking for the [include matcher](https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/include-matcher) – engineersmnky Mar 01 '19 at 21:50
  • RSpec 3, not Rails!, encouraged users to use the new expect syntax - as explained in the blog post. _RSpec 3 print a warning on first usage of any the old syntax methods_ ... _unless the should syntax has been explicitly enabled._ http://rspec.info/blog/2013/07/the-plan-for-rspec-3/ – notapatch Feb 03 '20 at 13:41

1 Answers1

0

You might consider using expect().to be(), so in your case:

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

More info on rspec matchers here: https://relishapp.com/rspec/rspec-expectations/docs/built-in-matchers

NM Pennypacker
  • 6,704
  • 11
  • 36
  • 38
  • 2
    It would actually be more like `expect(response.header['Content-Type']).to include( 'text/html'`)` and obviously the inversion is `not_to include` – engineersmnky Mar 01 '19 at 21:48