Skip to content

Instantly share code, notes, and snippets.

@jtrim
Created September 21, 2017 19:08
Show Gist options
  • Save jtrim/a747406d031fc6ca3852e594e337590a to your computer and use it in GitHub Desktop.
Save jtrim/a747406d031fc6ca3852e594e337590a to your computer and use it in GitHub Desktop.
# Example for https://twitter.com/jessetrimble/status/910940206924050432
def test_matches_fixture_document
(1..3).each do |row_number|
expected_value = fixture_spreadsheet.cell(row, "A")
assert_equal get_value_from_db, expected_value
end
end
###### Refactored to:
class FixtureDocument
def each_row(&block)
(1..3).each do |row_number|
value = fixture_spreadsheet.cell(row_number, "A")
# Whoops, forgot to: yield(value)
end
end
end
def test_matches_fixture_document
FixtureDocument.each_row do |expected_value|
assert_equal get_value_from_db, expected_value
end
end
# In the above example, the test is refactored to pull the details of what the fixture document is and how it's
# structured away from the tests, which is a good thing, but since we forgot to yield in our refactor, no assertions are
# ran, so there's no chance for the spec to fail!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment