【发布时间】:2019-03-01 16:16:51
【问题描述】:
如果不推荐使用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语法或使用config.expect_with(:rspec) { |c| c.syntax = :should }显式启用:should。
【问题讨论】:
-
Rspec 有很棒的文档,并且期望语法已经成为默认语法已经有一段时间了。例如,您正在寻找 include matcher
-
RSpec 3,而不是 Rails!,鼓励用户使用新的 expect 语法 - 如博客文章中所述。 RSpec 3 会在首次使用任何旧语法方法时打印警告 ... 除非明确启用了 should 语法。 rspec.info/blog/2013/07/the-plan-for-rspec-3
标签: ruby-on-rails ruby-on-rails-5 rspec-rails