Ruby on rails RSpec 3-已弃用的“;应该";
如果不推荐使用Ruby on rails RSpec 3-已弃用的“;应该";,ruby-on-rails,ruby-on-rails-5,rspec-rails,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
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'old中的should
:should
语法
不推荐显式启用语法。使用新的:expect
语法或显式启用:应使用config.expect\u(:rspec)
{| c | c.syntax=:should}
您可以考虑使用<代码>()来对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
matchers的更多信息,请点击此处:它实际上更像expect(response.header['Content-Type'])。包含('text/html'
)`显然倒装是而不是包含rspec有很棒的文档,expect语法是相当长一段时间以来的默认语法。例如,您正在寻找的是RSpec3,而不是Rails!,鼓励用户使用新的expect语法-如博客文章中所述。RSpec 3在首次使用任何旧语法方法时打印警告。。。除非显式启用了should语法。