Sha256: dc6046360f71875105bc7aadc0f8d877d03f1fb276af25554d4837f303600969

Contents?: true

Size: 765 Bytes

Versions: 11

Compression:

Stored size: 765 Bytes

Contents

# frozen_string_literal: true
require "test_helper"

class Measured::Cache::JsonWriterTest < ActiveSupport::TestCase
  class JsonTestWithWriter < Measured::Cache::Json
    prepend Measured::Cache::JsonWriter
  end

  setup do
    @cache = JsonTestWithWriter.new("test.json")
    @table_json = JSON.pretty_generate({ "a" => { "b" => { "numerator" => 2, "denominator" => 3 } } })
    @table_hash = { "a" => { "b" => Rational(2, 3) } }
  end

  test "#write writes the file" do
    f = stub
    f.expects(:write).with("// Do not modify this file directly. Regenerate it with 'rake cache:write'.\n")
    f.expects(:write).with(@table_json)

    File.expects(:open).with(@cache.path, "w").returns(123).yields(f)
    assert_equal 123, @cache.write(@table_hash)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

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