Sha256: 958f30b740b81b939f268339a6d735d81355326a29b33103e70c80b2b52f2adb

Contents?: true

Size: 1.01 KB

Versions: 11

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true
require "test_helper"

# In general we do not want to expose the inner workings of the caching and unit systems as part of the API.
# But we do want to be able to test that there is no conflict between what's in the cache file and what is defined
# in the unit systems. So we compromise by reaching into implementation to force compare them.
class Measured::CacheConsistencyTest < ActiveSupport::TestCase
  measurable_subclasses.select { |m| m.unit_system.cached? }.each do |measurable|
    test "cached measurable #{ measurable } is not out of sync with the definition" do
      builder = measurable.unit_system.instance_variable_get("@conversion_table_builder")
      cache = builder.instance_variable_get("@cache")

      expected = builder.send(:generate_table)
      actual = cache.read

      assert expected == actual, "The contents of the file cache for `#{ measurable }` does not match what the unit system generated.\nTry running `rake cache:write` to update the caches."
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
measured-3.2.0 test/cache_consistency_test.rb
measured-3.1.0 test/cache_consistency_test.rb
measured-3.0.0 test/cache_consistency_test.rb
measured-2.8.2 test/cache_consistency_test.rb
measured-2.8.1 test/cache_consistency_test.rb
measured-2.8.0 test/cache_consistency_test.rb
measured-2.7.1 test/cache_consistency_test.rb
measured-2.7.0 test/cache_consistency_test.rb
measured-2.6.0 test/cache_consistency_test.rb
measured-2.5.2 test/cache_consistency_test.rb
measured-2.5.1 test/cache_consistency_test.rb