Skip to content

Instantly share code, notes, and snippets.

@ilyazub
Created February 14, 2014 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilyazub/9002586 to your computer and use it in GitHub Desktop.
Save ilyazub/9002586 to your computer and use it in GitHub Desktop.
Rake task for upgrading Jasmine specs from 1.3 to 2.0.
desc "Upgrade Jasmine specs to 2.0 syntax"
namespace :jasmine do
task :upgrade_specs do
Dir.glob('spec/javascripts/units/**/*_spec.js.coffee') do |filename|
specs = File.read(filename)
specs = specs.gsub('.andReturn', '.and.returnValue')
specs = specs.gsub('.andCallFake', '.and.callFake')
specs = specs.gsub('.andCallThrough', '.and.callThrough')
specs = specs.gsub('.mostRecentCall', '.calls.mostRecent()')
specs = specs.gsub('.callCount', '.calls.count()')
specs = specs.gsub('.calls.length', '.calls.count()')
specs = specs.gsub('.Clock.useMock()', '.clock().install()')
specs = specs.gsub('.Clock', '.clock()')
specs = specs.gsub('.clock().uninstallMock()', '.clock().uninstall()')
File.open(filename, 'w') { |io| io.puts(specs) }
puts "#{filename} upgraded"
end
end
end
@shakerlxxv
Copy link

Excellent! I didn't actually use it as a rake task, but just the collected summary of api changes was great. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment