You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was writing a little rake task to compare some data in our DB to fixture files, and found this module as the best one for doing pretty printed diffs of object.
I had a little bit of trouble finding out how to produce a diff without using Rspec though - I managed to get something working using:
I'm afraid there isn't, although there should be. If you want the same header that gets printed out under RSpec as well as an exit code, you could try something like this (the header is here, for reference):
defreport_diff(expected,actual)diff=SuperDiff::RSpec::Differ.diff(actual,expected)ifdiff.empty?diffelseheader=SuperDiff::Helpers.styledoheader"Diff:"newlinenewlineborder"┌ (Key) ──────────────────────────┐"newlineborder"│ "expected"‹-› in expected, not in actual"border" │"newlineborder"│ "actual"‹+› in actual, not in expected"border" │"newlineborder"│ "normal"‹ › in both expected and actual"border" │"newlineborder"└─────────────────────────────────┘"newlinenewlineend"#{header}#{diff}"endend
Now you can call report_diff on your values. If this returns an empty string, then both were the same; if not, then they weren't. You should be able to use this fact to return an exit code.
I was writing a little rake task to compare some data in our DB to fixture files, and found this module as the best one for doing pretty printed diffs of object.
I had a little bit of trouble finding out how to produce a diff without using Rspec though - I managed to get something working using:
However this lacks headings to say which item is before/after, and doesn't give a result I can use as an exit code.
Is there a good way to use this library in a standalone mode?
The text was updated successfully, but these errors were encountered: