読者です 読者をやめる 読者になる 読者になる

英語で RSpec を書くために例文一覧を出力する

gems ディレクトリの */spec/**/*_spec.rb ファイルに対して 'it .* do' を grep する。

cd ~/.rvm/gems/ruby-1.9.3-p327/gems
find */spec -type f -name '*_spec.rb' | xargs grep -ho 'it .* do' | sort | uniq | less

みたいな感じ。以下のような出力が得られる。

:
it "accepts a URL as the path" do
it "accepts a block to change output" do
it "accepts a block" do
it "accepts a body" do
it "accepts a class as argument with a task to invoke" do
it "accepts a class as argument without a task to invoke" do
it "accepts a color as status" do
it "accepts a local file path with spaces" do
it "accepts a port" do
it "accepts a secure URL as the path" do
it "accepts a session without changes to tracked parameters" do
it "accepts a stub for save" do
it "accepts a stub for the primary_key" do
it "accepts a stub id" do
it "accepts a switch <value> assignment" do
it "accepts a switch=<value> assignment" do
it "accepts a timeout argument to #stop" do
it "accepts ajax requests without a valid token" do
it "accepts and executes a 'legal' %\w+% encoded instruction" do
it "accepts and interacts with a matcher" do
it "accepts array value" do
it "accepts arrays" do
it "accepts class and module objects" do
it "accepts conjoined short switches with input" do
it "accepts conjoined short switches" do
it "accepts data as a block" do
it "accepts explicitly provided cookies" do
it "accepts false as boolean()" do
it "accepts fixnum as instance_of(Fixnum)" do
it "accepts fixnum as kind_of(Numeric)" do
it "accepts float as an_instance_of(Numeric)" do
it "accepts get requests with 304 headers" do
it "accepts get requests with json responses with a local referrer" do
it "accepts get requests with json responses with no referrer" do
it "accepts hash value" do
it "accepts hashes" do
it "accepts http remote sources" do
it "accepts https remote sources" do
it "accepts inputs in the human name format" do
it "accepts options when assembling the parse tree" do
it "accepts params and builds query strings for GET requests" do
it "accepts params and builds url encoded params for POST requests" do
it "accepts params in the path" do
it "accepts post form requests with a remote referrer and correct authenticity_token field" do
it "accepts post form requests with correct authenticity_token field" do
it "accepts post requests with a local referrer" do
it "accepts post requests with a remote referrer and correct X-CSRF-Token header" do
it "accepts post requests with correct X-CSRF-Token header" do
it "accepts post requests with no referrer" do
it "accepts post requests with the same host in the referrer" do
it "accepts raw input in params for GET requests" do
it "accepts raw input in params for POST requests" do
it "accepts string as anything()" do
:

単語で検索すると、真似できそうなセンテンスが見つかる。また、 cause error と raise error のどっちにするか、みたいなことで悩まずに済む。

$ grep 'raise.*error' samples.txt | wc -l
     129
$ grep 'cause.*error' samples.txt | wc -l
       3
$ grep 'pass.*arg' samples.txt | wc -l
      95
$ grep 'pass.*param' samples.txt | wc -l
       9

うれしい。