Created
February 24, 2012 21:53
-
-
Save jdewind/1904020 to your computer and use it in GitHub Desktop.
OCMock to Kiwi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
files = [ARGV[0] || Dir["*.m"]].flatten | |
files.each do |file| | |
content = File.read(file) | |
mapped_content = content.lines.map do |line| | |
[ | |
{from: /\[\[\[(.+) (?:stub|expect)\] andReturn:(.+)\] (.+)/, to: "[[%s stubAndReturn:%s] %s"}, | |
{from: /\[\[\[(.+) (?:stub|expect)\] andReturn\w+:(.+)\] (.+)/, to: "[[%s stubAndReturn:theValue(%s)] %s"}, | |
{from: /\[(?:\(\w+\s*\*\)){,1}\[(.+) expect\] (.+)/, to: "[[[%s should] receive] %s"}, | |
{from: /\[OCMockObject observerMock\]/, to: "[Kiwi observerMock]"}, | |
{from: /\[OCMockObject mockFor(Class|Protocol):(.+)/, to: "[Kiwi mockFor%s: %s"}, | |
{from: /\[OCMockObject niceMockFor(Class|Protocol):(.+)/, to: "[Kiwi nullMockFor%s: %s"} | |
].each do |x| | |
match = line.match(x[:from]) | |
if match | |
line = line.gsub(x[:from], x[:to] % match[1..-1]) | |
end | |
end | |
line | |
end | |
File.open(file, "w") { |f| f.print mapped_content.join("") } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment