使用--format doc保持rspec约定

ted*_*ted 1 ruby rspec ruby-on-rails

Betterspec建议使用类似以下内容的方法:

subject { assigns('message') }
it { should match /it was born in Billville/ }
Run Code Online (Sandbox Code Playgroud)

作为良好的做法。但是如果我想以doc格式(rspec -f doc)运行rspec,我会收到:

When you call a matcher in an example without a String, like this:    
  specify { object.should matcher }    
or this:    
  it { should matcher }    
RSpec expects the matcher to have a #description method. You should either
add a String to the example this matcher is being used in, or give it a
description method. Then you won't have to suffer this lengthy warning again.
Run Code Online (Sandbox Code Playgroud)

所以这

it "some desc" do 
  should match /it was born in Billville/ 
end
Run Code Online (Sandbox Code Playgroud)

不会发出令人讨厌的信息,但看起来很丑。

关于如何保持rspec约定和代码干净的任何想法,仍然有一些漂亮的输出(例如-f doc)?

rspec v.2.13.0

Myr*_*ton 5

作为RSpec的维护者,betterspecs.org上列出了许多我不同意的内容。我已经在几个月前就对该项目的github问题发表了评论,但可悲的是,我认为我的任何担忧都没有得到解决:(。

无论如何,我认为当doc输出与您想要的内容匹配时,可以使用单行语法,但通常不行。通常,单行语法的doc输出过于具体,例如,它以doc字符串形式返回,should eq "dfgh"即使这不是一般情况下的行为-类似于对行为returns a string without vowels removed的更好,更真实的描述。

因此,我的建议是不要使用单行语法,除非它产生所需的输出。不要仅仅因为Betterspecs.org推荐它而使用它。我认为它的许多建议都是不好的建议。

  • https://www.destroyallsoftware.com/很棒。它要花钱,但是我强烈推荐它。我还通过电子邮件发送了bestspecs.org维护者,询问他是否愿意更新内容来解决我的问题。 (2认同)