Skip to content

Instantly share code, notes, and snippets.

@fred-o
Created February 13, 2020 14:45
Show Gist options
  • Save fred-o/0545e805f2367a8dba9bd5d5af70f7cf to your computer and use it in GitHub Desktop.
Save fred-o/0545e805f2367a8dba9bd5d5af70f7cf to your computer and use it in GitHub Desktop.
#!/bin/bash
input=$1
perl -i -pe 's/^( +)(?!expect)([^ ]*q?)(\.should)/$1expect($2)$3/ ' $input
perl -i -pe 's/\.(should|to)\.(not\.)?(eql|equal)/.$2toEqual/' $input
perl -i -pe 's/\.(should|to)\.(not\.)?be.instance[oO]f/.$2toBeInstanceOf/' $input
perl -i -pe 's/\.(should|to)\.(not\.)?be.empty/.$2toBeEmpty()/' $input
perl -i -pe 's/\.(should|to)\.(not\.)?be.defined/.$2toBeDefined()/' $input
perl -i -pe 's/\.(should|to)\.(not\.)?be.undefined/.$2toBeUndefined()/' $input
perl -i -pe 's/\.(should|to)\.(not\.)?be.null/.$2toBeNull()/' $input
perl -i -pe 's/\.(should|to)\.(not\.)?have.property/.$2toHaveProperty/' $input
perl -i -pe 's/\.(should|to)\.(not\.)?have.been.calledWith/.$2toHaveBeenCalledWith/' $input
perl -i -pe 's/\.(should|to)\.(not\.)?have.been.calledOnce/.$2toHaveBeenCalledTimes(1)/' $input
perl -i -pe 's/\.(should|to)\.(not\.)?have.been.calledTwice/.$2toHaveBeenCalledTimes(2)/' $input
perl -i -pe 's/\.(should|to)\.(not\.)?have.been.calledThrice/.$2toHaveBeenCalledTimes(3)/' $input
perl -i -pe 's/\.(should|to)\.(not\.)?have.been.called/.$2toHaveBeenCalled()/' $input
perl -i -pe 's/\.(should|to)\.(not\.)?have.length\b/.$2toHaveLength/' $input
perl -i -pe 's/\.toEqual +null/.toBeNull()/' $input
git diff $input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment