Skip to content

Instantly share code, notes, and snippets.

@MiroslavCsonka
Last active April 8, 2021 10:36
Show Gist options
  • Save MiroslavCsonka/1385080166952724cfba54264ad36760 to your computer and use it in GitHub Desktop.
Save MiroslavCsonka/1385080166952724cfba54264ad36760 to your computer and use it in GitHub Desktop.
Snapshot testing in RSpec
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