diff options
author | adamedx <adamed@opscode.com> | 2013-08-02 12:15:50 -0700 |
---|---|---|
committer | adamedx <adamed@opscode.com> | 2013-08-02 12:15:50 -0700 |
commit | 316f6a24557e922f7bfeb1a382b70564e010ef31 (patch) | |
tree | d79b16bc8c9623b5d7caca2588a65b52e2d2d6c7 | |
parent | 491ddbbbe8e5037ec3321f26a0872e36b47bb665 (diff) | |
download | chef-316f6a24557e922f7bfeb1a382b70564e010ef31.tar.gz |
Use constants instead of lets for semantically constant symbols
-rw-r--r-- | spec/unit/provider/remote_file/cache_control_data_spec.rb | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/spec/unit/provider/remote_file/cache_control_data_spec.rb b/spec/unit/provider/remote_file/cache_control_data_spec.rb index 2baf86bcf6..2ae3c41214 100644 --- a/spec/unit/provider/remote_file/cache_control_data_spec.rb +++ b/spec/unit/provider/remote_file/cache_control_data_spec.rb @@ -19,6 +19,15 @@ require 'spec_helper' require 'uri' +CACHE_FILE_TRUNCATED_FRIENDLY_FILE_NAME_LENGTH = 64 +CACHE_FILE_MD5_HEX_LENGTH = 32 +CACHE_FILE_JSON_FILE_EXTENSION_LENGTH = 5 +CACHE_FILE_PATH_LIMIT = + CACHE_FILE_TRUNCATED_FRIENDLY_FILE_NAME_LENGTH + + 1 + + CACHE_FILE_MD5_HEX_LENGTH + + CACHE_FILE_JSON_FILE_EXTENSION_LENGTH # {friendly}-{md5hex}.json == 102 + describe Chef::Provider::RemoteFile::CacheControlData do let(:uri) { URI.parse("http://www.google.com/robots.txt") } @@ -169,17 +178,13 @@ describe Chef::Provider::RemoteFile::CacheControlData do # local cache file names generated from the long uri exceeded # local file system path limits resulting in exceptions from # file system API's on both Windows and Unix systems. - context "and the URI results in a file cache path that exceeds 102 characters in length" do - let(:truncated_friendly_file_name_length) { 64 } - let(:md5_hex_length) { 32 } - let(:json_file_extension_length) { 5 } - let(:cache_file_path_limit) { truncated_friendly_file_name_length + 1 + md5_hex_length + json_file_extension_length } # {friendly}-{md5hex}.json == 102 - let(:long_remote_path) { "http://www.bing.com/" + ('0' * (truncated_friendly_file_name_length * 2 )) } + context "and the URI results in a file cache path that exceeds #{CACHE_FILE_PATH_LIMIT} characters in length" do + let(:long_remote_path) { "http://www.bing.com/" + ('0' * (CACHE_FILE_TRUNCATED_FRIENDLY_FILE_NAME_LENGTH * 2 )) } let(:uri) { URI.parse(long_remote_path) } - let(:truncated_remote_uri) { URI.parse(long_remote_path[0...truncated_friendly_file_name_length]) } + let(:truncated_remote_uri) { URI.parse(long_remote_path[0...CACHE_FILE_TRUNCATED_FRIENDLY_FILE_NAME_LENGTH]) } let(:truncated_file_cache_path) do cache_control_data_truncated = Chef::Provider::RemoteFile::CacheControlData.load_and_validate(truncated_remote_uri, current_file_checksum) - cache_control_data_truncated.send('sanitized_cache_file_basename')[0...truncated_friendly_file_name_length] + cache_control_data_truncated.send('sanitized_cache_file_basename')[0...CACHE_FILE_TRUNCATED_FRIENDLY_FILE_NAME_LENGTH] end it "truncates the file cache path to 102 characters" do @@ -189,13 +194,13 @@ describe Chef::Provider::RemoteFile::CacheControlData do cache_control_data.save - normalized_cache_path.length.should == cache_file_path_limit + normalized_cache_path.length.should == CACHE_FILE_PATH_LIMIT end - it "uses a file cache path that starts with the first 64 characters of the URI" do + it "uses a file cache path that starts with the first #{CACHE_FILE_TRUNCATED_FRIENDLY_FILE_NAME_LENGTH} characters of the URI" do normalized_cache_path = cache_control_data.send('sanitized_cache_file_basename') - truncated_file_cache_path.length.should == truncated_friendly_file_name_length + truncated_file_cache_path.length.should == CACHE_FILE_TRUNCATED_FRIENDLY_FILE_NAME_LENGTH normalized_cache_path.start_with?(truncated_file_cache_path).should == true end end |