【发布时间】:2016-04-29 06:29:47
【问题描述】:
我想知道如何在我的所有 rspec 文件中替换这样的代码:
describe ApiController do
context 'article list exist' do
#...
it { should respond_with :success }
it { should render_template 'refresh_article_in_article_list' }
end
end
到
describe ApiController do
context 'article list exist' do
#...
it do
should respond_with :success
should render_template 'refresh_article_in_article_list'
end
end
end
我可以用 vim 宏替换一个,但不能用多行替换。
在this post 的帮助下,我尝试在 ruby gsub 中执行此操作,但失败了,我将继续搜索:
"it { should respond_with :success }\n\nit { should render_template 'refresh_article' }".gsub(/(?<value>{.*})|(it {)|( })/, 'it do \k<value>\nend'))
=> "it do \\nend should respond_with :successit do \\nend\n\nit do \\nend should render_template 'refresh_article'it do \\nend"
【问题讨论】:
-
你有多少这样的?也许只是手动更改它们并忘记它?
-
@sergio-tulentsev 我可能有超过 15000 条这样的一行。 :)