автоматизированный тест для проверки целостности прибора
class FixtureIntegrityTest < ActiveSupport::TestCase
context "fixture integrity" do
should "work" do
fixtures = Dir["test/fixtures/*.yml"].map do |file|
[file, File.basename(file).sub(/\..*/, "").singularize, YAML.load(ERB.new(File.read(file)).result)]
end
failures = fixtures.reject(&:last).map { |file,*| "#{file} is empty!"}
failures = failures.presence || fixtures.map do |_, klass, content|
content.select{ |_,fixture| fixture["id"] }.map do |name, _|
fixtures.map do |file, _, content|
content.select { |_,fixture| fixture[klass] == name }.map do |_, fixture|
"#{file} uses #{klass}: #{name}, but should use the id!"
end
end
end
end.flatten.compact
assert_equal [], failures
end
end
end