Skip to content

Instantly share code, notes, and snippets.

@knzconnor
Forked from jbarnette/fixtures_test.rb
Created June 1, 2010 22:22
Show Gist options
  • Save knzconnor/421609 to your computer and use it in GitHub Desktop.
Save knzconnor/421609 to your computer and use it in GitHub Desktop.
require "test_helper"
require "yaml"
class FixtureTest < ActiveSupport::TestCase
fixtures :all
Dir[File.join Rails.root, "test", "fixtures", "**", "*.yml"].each do |file|
if fixtures = YAML.load(IO.read(file))
kind = File.basename file, ".yml"
fixtures.each do |key, _|
define_method "test_#{kind}_#{key}_fixture" do
model = send kind, key.to_sym
valid = model.valid?
assert model.valid?, "Expected #{kind}(:#{key}) to be valid, but " +
model.errors.full_messages.to_sentence
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment