Skip to content

Instantly share code, notes, and snippets.

@jdewind
Created February 24, 2012 21:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdewind/1904020 to your computer and use it in GitHub Desktop.
Save jdewind/1904020 to your computer and use it in GitHub Desktop.
OCMock to Kiwi
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