Sha256: f66d028c764710a79d1b262820e24e1f234b1991e7fed08954ba70cd84a4de2f

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

require File.join(File.dirname(__FILE__), %w[.. spec_helper])
include TwitterCldr::Shared

describe Resources do
  before(:each) do
    @resource = Resources.new
  end

  describe "#resource_for" do
    it "loads the requested resource from disk only once" do
      # note that it should convert the string "de" into a symbol
      mock(@resource).data_for(:de, "racehorse").once { "german racehorse resource" }

      # do it twice - the second one shouldn't call data_for
      @resource.resource_for("de", "racehorse").should == "german racehorse resource"
      @resource.resource_for("de", "racehorse").should == "german racehorse resource"
    end
  end

  describe "#data_for" do
    it "loads the correct file for the given locale and resource" do
      mock(YAML).load("data") { { "key" => "value" } }
      mock(File).read(File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), "resources", "de", "racehorse.yml")) { "data" }
      @resource.resource_for("de", "racehorse").should == { :key => "value" }
    end
  end

  describe "#deep_symbolize_keys" do
    it "should work with a regular hash" do
      result = @resource.send(:deep_symbolize_keys, { "twitter" => "rocks", "my" => "socks" })
      result.should == { :twitter => "rocks", :my => "socks"}
    end

    it "should work with nested hashes" do
      result = @resource.send(:deep_symbolize_keys, { "twitter" => { "rocks" => "my socks" } })
      result.should == { :twitter => { :rocks => "my socks" } }
    end

    it "should work with nested hashes and arrays" do
      result = @resource.send(:deep_symbolize_keys, { "twitter" => { "rocks_my" => [{ "socks" => "and mind" }, { "hard" => "core" }] } })
      result.should == { :twitter => { :rocks_my => [{ :socks => "and mind" }, { :hard => "core" }] } }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
twitter_cldr-1.0.0 spec/shared/resources_spec.rb