Skip to content

Instantly share code, notes, and snippets.

@ConorSheehan1
Last active March 29, 2019 14:26
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 ConorSheehan1/5c2ca28e6ac9814e7acc8d45786e5342 to your computer and use it in GitHub Desktop.
Save ConorSheehan1/5c2ca28e6ac9814e7acc8d45786e5342 to your computer and use it in GitHub Desktop.
regular expressions for updating ruby syntax (tested using sublime-text-3 replace function)

Hash

  1. {:x => y} -> {x: y}

    Find Replace Comment
    :(\w+) => \1:

Rspec

  1. foo.should -> expect(foo).to

    Find Replace Comment
    ^(\s*)(.*)\.should_ \1expect(\2).to
    to not_ to_not # handle should not_ case
  2. foo.stub(:bar) -> allow(foo).to receive(:bar)

    Find Replace Comment
    before \{\s(.*)\.stub\((.*)\) before { allow(\1).to receive(\2) # do before blocks first
    ^(^(?!.*(\#|before)))(\s*)(.*)\.stub\((.*)\) \3allow(\4).to receive(\5) # if before block or comment, skip
  3. foo.stub_chain(:bar, :baz) -> allow(foo).to receive_message_chain(:bar, :baz)

    Find Replace Comment
    before\s\{\s(.*)\.stub_chain\((.*)\) before { allow(\1).to receive_message_chain(\2) # do before blocks first
    ^(^(?!.*(\#|before)))(\s*)(.*)\.stub_chain\((.*)\) \3allow(\4).to receive_message_chain(\5) # skip if comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment