如果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 }
。
答案 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