如果不推荐使用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 }
。
您可以考虑使用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