次の仕様が必要だとします。
it { should allow_value("git://host.xz/path/to/repo.git/").for(:url) }
it { should allow_value("git://user@host.xz/path/to/repo.git/").for(:url) }
it { should allow_value("git://host.xz:123/path/to/repo.git/").for(:url) }
it { should allow_value("git://user@host.xz:123/path/to/repo.git/").for(:url) }
...
私が書くことができれば、それはより簡単でよりコンパクトになるでしょう:
"git://{user@,}host.xz{:123,}/path/to/repo.git".expand.each do |p|
it { should allow_value(p).for(:url) }
end
またはさらに良い:
"{git,ssh,http,https,rsync}://[user@]host.xz[:123]/path/to/repo.git[/]".expand.each do |p|
it { should allow_value(p).for(:url) }
end
Rubyでこれを実現する方法は何ですか?
編集 最初に試したのはbracecompでしたが、1.9.3では動作しませんでした。
[1] pry(main)> require 'bracecomp'
[2] pry(main)> 'server-{a,b}-{07..10}'.expand
TypeError: scan() yielded Symbol (must be Array[2])
from bracecomp.y:66:in `scan'