Last active
April 8, 2021 10:36
-
-
Save MiroslavCsonka/1385080166952724cfba54264ad36760 to your computer and use it in GitHub Desktop.
Snapshot testing in RSpec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def expect_to_match_xml_fixture(xml, fixture_path) | |
expected = Nokogiri::XML(xml, &:noblanks).to_xml | |
fixture_path = Rails.root.join("spec/fixtures", fixture_path) | |
File.write(fixture_path, expected) if ENV["REPLACE_FIXTURE_SNAPSHOTS"] == "true" | |
actual = Nokogiri::XML(File.read(fixture_path), &:noblanks).to_xml | |
expect(expected).to eq(actual) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment