diff options
author | John Keiser <jkeiser@opscode.com> | 2014-08-27 21:06:59 -0700 |
---|---|---|
committer | Adam Edwards <adamed@opscode.com> | 2014-08-30 12:31:09 -0700 |
commit | bc3d6871086721d2049bd2e28e8801d0eed176ff (patch) | |
tree | 48b608e6bd893e3697350433c7efd1aacb9cfca8 | |
parent | 482f8bb073ddd322017b9366fb8aac2301e56e3a (diff) | |
download | chef-bc3d6871086721d2049bd2e28e8801d0eed176ff.tar.gz |
Move Chef::Config path functions to Chef::Util::PathHelper
-rw-r--r-- | lib/chef/client.rb | 1 | ||||
-rw-r--r-- | lib/chef/config.rb | 85 | ||||
-rw-r--r-- | lib/chef/mixin/shell_out.rb | 4 | ||||
-rw-r--r-- | lib/chef/platform.rb | 2 | ||||
-rw-r--r-- | lib/chef/platform/provider_mapping.rb | 2 | ||||
-rw-r--r-- | lib/chef/util/path_helper.rb | 60 | ||||
-rw-r--r-- | spec/unit/config_spec.rb | 42 | ||||
-rw-r--r-- | spec/unit/util/path_helper_spec.rb | 134 |
8 files changed, 197 insertions, 133 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb index 69e191bdf8..2de3ca3e64 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -25,7 +25,6 @@ require 'chef/log' require 'chef/rest' require 'chef/api_client' require 'chef/api_client/registration' -require 'chef/platform/query_helpers' require 'chef/node' require 'chef/role' require 'chef/file_cache' diff --git a/lib/chef/config.rb b/lib/chef/config.rb index 48161a0d17..e8a9839d71 100644 --- a/lib/chef/config.rb +++ b/lib/chef/config.rb @@ -23,6 +23,7 @@ require 'chef/log' require 'chef/exceptions' require 'mixlib/config' require 'chef/util/selinux' +require 'chef/util/path_helper' require 'pathname' class Chef @@ -30,6 +31,8 @@ class Chef extend Mixlib::Config + PathHelper = Chef::Util::PathHelper + # Evaluates the given string as config. # # +filename+ is used for context in stacktraces, but doesn't need to be the name of an actual file. @@ -58,57 +61,17 @@ class Chef configuration.inspect end - def self.on_windows? - RUBY_PLATFORM =~ /mswin|mingw|windows/ - end - - BACKSLASH = '\\'.freeze - - def self.platform_path_separator - if on_windows? - File::ALT_SEPARATOR || BACKSLASH - else - File::SEPARATOR - end - end - - def self.path_join(*args) - args = args.flatten - args.inject do |joined_path, component| - unless [ File::SEPARATOR, File::ALT_SEPARATOR, platform_path_separator ].include?(joined_path[-1,1]) - joined_path += platform_path_separator - end - joined_path += component - end - end - def self.platform_specific_path(path) - if on_windows? - # turns /etc/chef/client.rb into C:/chef/client.rb - if env['SYSTEMDRIVE'] && path[0] == '/' && path.split('/')[2] == 'chef' - path = File.join(env['SYSTEMDRIVE'], path.split('/')[2..-1]) + path = PathHelper.cleanpath(path) + if Chef::Platform.windows? + # turns \etc\chef\client.rb and \var\chef\client.rb into C:/chef/client.rb + if env['SYSTEMDRIVE'] && path[0] == '\\' && path.split('\\')[2] == 'chef' + path = PathHelper.join(env['SYSTEMDRIVE'], path.split('\\', 3)[2]) end - # ensure all forward slashes are backslashes - path = path.gsub(File::SEPARATOR, (File::ALT_SEPARATOR || BACKSLASH)) end path end - def self.platform_dirname(path) - if on_windows? - slash = path.rindex(/[\\#{platform_separator}\\#{File::SEPARATOR}]/) - if slash.nil? - '.' - elsif slash == 0 - '/' - else - path[0..slash-1] - end - else - ::File.dirname(path) - end - end - def self.add_formatter(name, file_path=nil) formatters << [name, file_path] end @@ -117,11 +80,10 @@ class Chef configurable(:config_file) default(:config_dir) do - puts "Default config_dir: '#{config_file}'" if config_file - platform_dirname(config_file) + PathHelper.dirname(config_file) else - path_join(user_home, ".chef#{platform_path_separator}") + PathHelper.join(user_home, ".chef", "") end end @@ -167,7 +129,7 @@ class Chef # In local mode, we auto-discover the repo root by looking for a path with "cookbooks" under it. # This allows us to run config-free. path = cwd - until File.directory?(path_join(path, "cookbooks")) + until File.directory?(PathHelper.join(path, "cookbooks")) new_path = File.expand_path('..', path) if new_path == path Chef::Log.warn("No cookbooks directory found at or above current directory. Assuming #{Dir.pwd}.") @@ -181,9 +143,9 @@ class Chef def self.derive_path_from_chef_repo_path(child_path) if chef_repo_path.kind_of?(String) - path_join(chef_repo_path, child_path) + PathHelper.join(chef_repo_path, child_path) else - chef_repo_path.map { |path| path_join(path, child_path)} + chef_repo_path.map { |path| PathHelper.join(path, child_path)} end end @@ -255,7 +217,7 @@ class Chef # this is under the user's home directory. default(:cache_path) do if local_mode - path_join(config_dir, 'local-mode-cache') + PathHelper.join(config_dir, 'local-mode-cache') else primary_cache_root = platform_specific_path("/var") primary_cache_path = platform_specific_path("/var/chef") @@ -264,8 +226,7 @@ class Chef # Otherwise, we'll create .chef under the user's home directory and use that as # the cache path. unless path_accessible?(primary_cache_path) || path_accessible?(primary_cache_root) - secondary_cache_path = File.join(user_home, '.chef') - secondary_cache_path.gsub!(File::SEPARATOR, platform_path_separator) # Safety, mainly for Windows... + secondary_cache_path = PathHelper.join(user_home, '.chef') Chef::Log.info("Unable to access cache at #{primary_cache_path}. Switching cache to #{secondary_cache_path}") secondary_cache_path else @@ -280,20 +241,20 @@ class Chef end # Where cookbook files are stored on the server (by content checksum) - default(:checksum_path) { path_join(cache_path, "checksums") } + default(:checksum_path) { PathHelper.join(cache_path, "checksums") } # Where chef's cache files should be stored - default(:file_cache_path) { path_join(cache_path, "cache") } + default(:file_cache_path) { PathHelper.join(cache_path, "cache") } # Where backups of chef-managed files should go - default(:file_backup_path) { path_join(cache_path, "backup") } + default(:file_backup_path) { PathHelper.join(cache_path, "backup") } # The chef-client (or solo) lockfile. # # If your `file_cache_path` resides on a NFS (or non-flock()-supporting # fs), it's recommended to set this to something like # '/tmp/chef-client-running.pid' - default(:lockfile) { path_join(file_cache_path, "chef-client-running.pid") } + default(:lockfile) { PathHelper.join(file_cache_path, "chef-client-running.pid") } ## Daemonization Settings ## # What user should Chef run as? @@ -389,7 +350,7 @@ class Chef # Path to the default CA bundle files. default :ssl_ca_path, nil default(:ssl_ca_file) do - if on_windows? and embedded_path = embedded_dir + if Chef::Platform.windows? and embedded_path = embedded_dir cacert_path = File.join(embedded_path, "ssl/certs/cacert.pem") cacert_path if File.exist?(cacert_path) else @@ -401,7 +362,7 @@ class Chef # certificates in this directory will be added to whatever CA bundle ruby # is using. Use this to add self-signed certs for your Chef Server or local # HTTP file servers. - default(:trusted_certs_dir) { path_join(config_dir, "trusted_certs") } + default(:trusted_certs_dir) { PathHelper.join(config_dir, "trusted_certs") } # Where should chef-solo download recipes from? default :recipe_url, nil @@ -505,7 +466,7 @@ class Chef default(:syntax_check_cache_path) { cache_options[:path] } # Deprecated: - default(:cache_options) { { :path => path_join(file_cache_path, "checksums") } } + default(:cache_options) { { :path => PathHelper.join(file_cache_path, "checksums") } } # Set to false to silence Chef 11 deprecation warnings: default :chef11_deprecation_warnings, true @@ -553,7 +514,7 @@ class Chef # Those lists of regular expressions define what chef considers a # valid user and group name - if on_windows? + if Chef::Platform.windows? set_defaults_for_windows else set_defaults_for_nix diff --git a/lib/chef/mixin/shell_out.rb b/lib/chef/mixin/shell_out.rb index 3f80290f90..881c94b862 100644 --- a/lib/chef/mixin/shell_out.rb +++ b/lib/chef/mixin/shell_out.rb @@ -20,7 +20,6 @@ require 'chef/shell_out' require 'mixlib/shellout' -require 'chef/config' class Chef module Mixin @@ -97,3 +96,6 @@ class Chef end end end + +# Break circular dep +require 'chef/config' diff --git a/lib/chef/platform.rb b/lib/chef/platform.rb index 8f494731ab..d7a3e209bc 100644 --- a/lib/chef/platform.rb +++ b/lib/chef/platform.rb @@ -16,8 +16,8 @@ # limitations under the License. # -require 'chef/platform/provider_mapping' require 'chef/platform/query_helpers' +require 'chef/platform/provider_mapping' class Chef class Platform diff --git a/lib/chef/platform/provider_mapping.rb b/lib/chef/platform/provider_mapping.rb index d61298e182..7f79c38a6a 100644 --- a/lib/chef/platform/provider_mapping.rb +++ b/lib/chef/platform/provider_mapping.rb @@ -16,8 +16,8 @@ # limitations under the License. # -require 'chef/config' require 'chef/log' +require 'chef/exceptions' require 'chef/mixin/params_validate' require 'chef/version_constraint/platform' diff --git a/lib/chef/util/path_helper.rb b/lib/chef/util/path_helper.rb index 534a9087ae..1877667b9a 100644 --- a/lib/chef/util/path_helper.rb +++ b/lib/chef/util/path_helper.rb @@ -16,15 +16,50 @@ # limitations under the License. # -require 'chef/platform' -require 'chef/exceptions' - class Chef class Util class PathHelper # Maximum characters in a standard Windows path (260 including drive letter and NUL) WIN_MAX_PATH = 259 + def self.dirname(path) + if Chef::Platform.windows? + # Find the first slash, not counting trailing slashes + end_slash = path.size + while true + slash = path.rindex(/[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]/, end_slash - 1) + if !slash + return end_slash == path.size ? '.' : path_separator + elsif slash == end_slash - 1 + end_slash = slash + else + return path[0..slash-1] + end + end + else + ::File.dirname(path) + end + end + + BACKSLASH = '\\'.freeze + + def self.path_separator + if Chef::Platform.windows? + File::ALT_SEPARATOR || BACKSLASH + else + File::SEPARATOR + end + end + + def self.join(*args) + args.flatten.inject do |joined_path, component| + unless [ File::SEPARATOR, path_separator ].include?(joined_path[-1]) + joined_path += path_separator + end + joined_path += component + end + end + def self.validate_path(path) if Chef::Platform.windows? unless printable?(path) @@ -32,7 +67,7 @@ class Chef Chef::Log.error(msg) raise Chef::Exceptions::ValidationFailed, msg end - + if windows_max_length_exceeded?(path) Chef::Log.debug("Path '#{path}' is longer than #{WIN_MAX_PATH}, prefixing with'\\\\?\\'") path.insert(0, "\\\\?\\") @@ -50,7 +85,7 @@ class Chef return true end end - + false end @@ -75,7 +110,7 @@ class Chef if Chef::Platform.windows? # Add the \\?\ API prefix on Windows unless add_prefix is false # Downcase on Windows where paths are still case-insensitive - abs_path.gsub!(::File::SEPARATOR, ::File::ALT_SEPARATOR) + abs_path.gsub!(::File::SEPARATOR, path_separator) if add_prefix && abs_path !~ /^\\\\?\\/ abs_path.insert(0, "\\\\?\\") end @@ -86,9 +121,22 @@ class Chef abs_path end + def self.cleanpath(path) + path = Pathname.new(path).cleanpath.to_s + # ensure all forward slashes are backslashes + if Chef::Platform.windows? + path = path.gsub(File::SEPARATOR, path_separator) + end + path + end + def self.paths_eql?(path1, path2) canonical_path(path1) == canonical_path(path2) end end end end + +# Break a require loop when require chef/util/path_helper +require 'chef/platform' +require 'chef/exceptions' diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb index 570c0e9d5e..ecc2173af5 100644 --- a/spec/unit/config_spec.rb +++ b/spec/unit/config_spec.rb @@ -19,8 +19,9 @@ require 'spec_helper' require 'chef/exceptions' +require 'chef/util/path_helper' -describe Chef::Config do +describe Chef::Config, :focus do describe "config attribute writer: chef_server_url" do before do Chef::Config.chef_server_url = "https://junglist.gen.nz" @@ -125,11 +126,7 @@ describe Chef::Config do end before :each do - if is_windows - Chef::Config.stub(:on_windows?).and_return(true) - else - Chef::Config.stub(:on_windows?).and_return(false) - end + Chef::Platform.stub(:windows?).and_return(is_windows) end describe "class method: platform_specific_path" do @@ -272,27 +269,6 @@ describe Chef::Config do Chef::Config[:environment_path].should == environment_path end - describe "joining platform specific paths" do - it "joins components when some end with separators" do - expected = to_platform("/foo/bar/baz") - expected = "C:#{expected}" if is_windows - Chef::Config.path_join(is_windows ? 'C:\\foo\\' : "/foo/", "bar", "baz").should == expected - end - - if is_windows - it "joins components on Windows when some end with unix separators" do - expected = 'C:\\foo/bar\\baz' - Chef::Config.path_join('C:\\foo/', "bar", "baz").should == expected - end - end - - it "joins components that don't end in separators" do - expected = to_platform("/foo/bar/baz") - expected = "C:#{expected}" if is_windows - Chef::Config.path_join(is_windows ? 'C:\\foo' : "/foo", "bar", "baz").should == expected - end - end - describe "setting the config dir" do context "when the config file is /etc/chef/client.rb" do @@ -301,7 +277,7 @@ describe Chef::Config do Chef::Config.config_file = to_platform("/etc/chef/client.rb") end - it "config_dir is /etc/chef", :focus do + it "config_dir is /etc/chef" do Chef::Config.config_dir.should == to_platform("/etc/chef") end @@ -327,13 +303,13 @@ describe Chef::Config do end - context "when the user's home dir is /home/charlie" do + context "when the user's home dir is /home/charlie/" do before do Chef::Config.user_home = to_platform("/home/charlie") end - it "config_dir is /home/charlie/.chef" do - Chef::Config.config_dir.should == to_platform("/home/charlie/.chef/") + it "config_dir is /home/charlie/.chef/" do + Chef::Config.config_dir.should == Chef::Util::PathHelper.join(to_platform("/home/charlie/.chef"), '') end context "and chef is running in local mode" do @@ -341,8 +317,8 @@ describe Chef::Config do Chef::Config.local_mode = true end - it "config_dir is /home/charlie/.chef" do - Chef::Config.config_dir.should == to_platform("/home/charlie/.chef/") + it "config_dir is /home/charlie/.chef/" do + Chef::Config.config_dir.should == Chef::Util::PathHelper.join(to_platform("/home/charlie/.chef"), '') end end end diff --git a/spec/unit/util/path_helper_spec.rb b/spec/unit/util/path_helper_spec.rb index 36ba19fce6..eb89aa083a 100644 --- a/spec/unit/util/path_helper_spec.rb +++ b/spec/unit/util/path_helper_spec.rb @@ -20,101 +20,179 @@ require 'chef/util/path_helper' require 'spec_helper' describe Chef::Util::PathHelper do - let(:path_helper) { Chef::Util::PathHelper } + PathHelper = Chef::Util::PathHelper + + [ false, true ].each do |is_windows| + context "on #{is_windows ? "windows" : "unix"}" do + before(:each) do + Chef::Platform.stub(:windows?).and_return(is_windows) + end + + describe "join" do + it "joins components when some end with separators" do + expected = PathHelper.cleanpath("/foo/bar/baz") + expected = "C:#{expected}" if is_windows + PathHelper.join(is_windows ? 'C:\\foo\\' : "/foo/", "bar", "baz").should == expected + end + + it "joins components that don't end in separators" do + expected = PathHelper.cleanpath("/foo/bar/baz") + expected = "C:#{expected}" if is_windows + PathHelper.join(is_windows ? 'C:\\foo' : "/foo", "bar", "baz").should == expected + end + + it "joins starting with '' resolve to absolute paths" do + PathHelper.join('', 'a', 'b').should == "#{PathHelper.path_separator}a#{PathHelper.path_separator}b" + end + + it "joins ending with '' add a / to the end" do + PathHelper.join('a', 'b', '').should == "a#{PathHelper.path_separator}b#{PathHelper.path_separator}" + end + + if is_windows + it "joins components on Windows when some end with unix separators" do + expected = 'C:\\foo/bar\\baz' + PathHelper.join('C:\\foo/', "bar", "baz").should == expected + end + end + end + + if is_windows + it "path_separator is \\" do + PathHelper.path_separator.should == '\\' + end + else + it "path_separator is /" do + PathHelper.path_separator.should == '/' + end + end + + if is_windows + it "cleanpath changes slashes into backslashes and leaves backslashes alone" do + PathHelper.cleanpath('/a/b\\c/d/').should == '\\a\\b\\c\\d' + end + it "cleanpath does not remove leading double backslash" do + PathHelper.cleanpath('\\\\a/b\\c/d/').should == '\\\\a\\b\\c\\d' + end + else + it "cleanpath removes extra slashes alone" do + PathHelper.cleanpath('//a///b/c/d/').should == '/a/b/c/d' + end + end + + describe "dirname" do + it "dirname('abc') is '.'" do + PathHelper.dirname('abc').should == '.' + end + it "dirname('/') is '/'" do + PathHelper.dirname(PathHelper.path_separator).should == PathHelper.path_separator + end + it "dirname('a/b/c') is 'a/b'" do + PathHelper.dirname(PathHelper.join('a', 'b', 'c')).should == PathHelper.join('a', 'b') + end + it "dirname('a/b/c/') is 'a/b'" do + PathHelper.dirname(PathHelper.join('a', 'b', 'c', '')).should == PathHelper.join('a', 'b') + end + it "dirname('/a/b/c') is '/a/b'" do + PathHelper.dirname(PathHelper.join('', 'a', 'b', 'c')).should == PathHelper.join('', 'a', 'b') + end + end + end + end describe "validate_path" do context "on windows" do before(:each) do # pass by default Chef::Platform.stub(:windows?).and_return(true) - path_helper.stub(:printable?).and_return(true) - path_helper.stub(:windows_max_length_exceeded?).and_return(false) + PathHelper.stub(:printable?).and_return(true) + PathHelper.stub(:windows_max_length_exceeded?).and_return(false) end it "returns the path if the path passes the tests" do - expect(path_helper.validate_path("C:\\ThisIsRigged")).to eql("C:\\ThisIsRigged") + expect(PathHelper.validate_path("C:\\ThisIsRigged")).to eql("C:\\ThisIsRigged") end it "does not raise an error if everything looks great" do - expect { path_helper.validate_path("C:\\cool path\\dude.exe") }.not_to raise_error + expect { PathHelper.validate_path("C:\\cool path\\dude.exe") }.not_to raise_error end it "raises an error if the path has invalid characters" do - path_helper.stub(:printable?).and_return(false) - expect { path_helper.validate_path("Newline!\n") }.to raise_error(Chef::Exceptions::ValidationFailed) + PathHelper.stub(:printable?).and_return(false) + expect { PathHelper.validate_path("Newline!\n") }.to raise_error(Chef::Exceptions::ValidationFailed) end it "Adds the \\\\?\\ prefix if the path exceeds MAX_LENGTH and does not have it" do long_path = "C:\\" + "a" * 250 + "\\" + "b" * 250 prefixed_long_path = "\\\\?\\" + long_path - path_helper.stub(:windows_max_length_exceeded?).and_return(true) - expect(path_helper.validate_path(long_path)).to eql(prefixed_long_path) + PathHelper.stub(:windows_max_length_exceeded?).and_return(true) + expect(PathHelper.validate_path(long_path)).to eql(prefixed_long_path) end end end describe "windows_max_length_exceeded?" do it "returns true if the path is too long (259 + NUL) for the API" do - expect(path_helper.windows_max_length_exceeded?("C:\\" + "a" * 250 + "\\" + "b" * 6)).to be_true + expect(PathHelper.windows_max_length_exceeded?("C:\\" + "a" * 250 + "\\" + "b" * 6)).to be_true end it "returns false if the path is not too long (259 + NUL) for the standard API" do - expect(path_helper.windows_max_length_exceeded?("C:\\" + "a" * 250 + "\\" + "b" * 5)).to be_false + expect(PathHelper.windows_max_length_exceeded?("C:\\" + "a" * 250 + "\\" + "b" * 5)).to be_false end it "returns false if the path is over 259 characters but uses the \\\\?\\ prefix" do - expect(path_helper.windows_max_length_exceeded?("\\\\?\\C:\\" + "a" * 250 + "\\" + "b" * 250)).to be_false + expect(PathHelper.windows_max_length_exceeded?("\\\\?\\C:\\" + "a" * 250 + "\\" + "b" * 250)).to be_false end end describe "printable?" do it "returns true if the string contains no non-printable characters" do - expect(path_helper.printable?("C:\\Program Files (x86)\\Microsoft Office\\Files.lst")).to be_true + expect(PathHelper.printable?("C:\\Program Files (x86)\\Microsoft Office\\Files.lst")).to be_true end it "returns true when given 'abc' in unicode" do - expect(path_helper.printable?("\u0061\u0062\u0063")).to be_true + expect(PathHelper.printable?("\u0061\u0062\u0063")).to be_true end it "returns true when given japanese unicode" do - expect(path_helper.printable?("\uff86\uff87\uff88")).to be_true + expect(PathHelper.printable?("\uff86\uff87\uff88")).to be_true end it "returns false if the string contains a non-printable character" do - expect(path_helper.printable?("\my files\work\notes.txt")).to be_false + expect(PathHelper.printable?("\my files\work\notes.txt")).to be_false end # This isn't necessarily a requirement, but here to be explicit about functionality. it "returns false if the string contains a newline or tab" do - expect(path_helper.printable?("\tThere's no way,\n\t *no* way,\n\t that you came from my loins.\n")).to be_false + expect(PathHelper.printable?("\tThere's no way,\n\t *no* way,\n\t that you came from my loins.\n")).to be_false end end describe "canonical_path" do context "on windows", :windows_only do it "returns an absolute path with backslashes instead of slashes" do - expect(path_helper.canonical_path("\\\\?\\C:/windows/win.ini")).to eq("\\\\?\\c:\\windows\\win.ini") + expect(PathHelper.canonical_path("\\\\?\\C:/windows/win.ini")).to eq("\\\\?\\c:\\windows\\win.ini") end it "adds the \\\\?\\ prefix if it is missing" do - expect(path_helper.canonical_path("C:/windows/win.ini")).to eq("\\\\?\\c:\\windows\\win.ini") + expect(PathHelper.canonical_path("C:/windows/win.ini")).to eq("\\\\?\\c:\\windows\\win.ini") end it "returns a lowercase path" do - expect(path_helper.canonical_path("\\\\?\\C:\\CASE\\INSENSITIVE")).to eq("\\\\?\\c:\\case\\insensitive") + expect(PathHelper.canonical_path("\\\\?\\C:\\CASE\\INSENSITIVE")).to eq("\\\\?\\c:\\case\\insensitive") end end context "not on windows", :unix_only do context "ruby is at least 1.9", :ruby_gte_19_only do it "returns a canonical path" do - expect(path_helper.canonical_path("/etc//apache.d/sites-enabled/../sites-available/default")).to eq("/etc/apache.d/sites-available/default") + expect(PathHelper.canonical_path("/etc//apache.d/sites-enabled/../sites-available/default")).to eq("/etc/apache.d/sites-available/default") end end context "ruby is less than 1.9", :ruby_18_only do it "returns a canonical path" do - expect { path_helper.canonical_path("/etc//apache.d/sites-enabled/../sites-available/default") }.to raise_error(NotImplementedError) + expect { PathHelper.canonical_path("/etc//apache.d/sites-enabled/../sites-available/default") }.to raise_error(NotImplementedError) end end end @@ -122,15 +200,15 @@ describe Chef::Util::PathHelper do describe "paths_eql?" do it "returns true if the paths are the same" do - path_helper.stub(:canonical_path).with("bandit").and_return("c:/bandit/bandit") - path_helper.stub(:canonical_path).with("../bandit/bandit").and_return("c:/bandit/bandit") - expect(path_helper.paths_eql?("bandit", "../bandit/bandit")).to be_true + PathHelper.stub(:canonical_path).with("bandit").and_return("c:/bandit/bandit") + PathHelper.stub(:canonical_path).with("../bandit/bandit").and_return("c:/bandit/bandit") + expect(PathHelper.paths_eql?("bandit", "../bandit/bandit")).to be_true end it "returns false if the paths are different" do - path_helper.stub(:canonical_path).with("bandit").and_return("c:/Bo/Bandit") - path_helper.stub(:canonical_path).with("../bandit/bandit").and_return("c:/bandit/bandit") - expect(path_helper.paths_eql?("bandit", "../bandit/bandit")).to be_false + PathHelper.stub(:canonical_path).with("bandit").and_return("c:/Bo/Bandit") + PathHelper.stub(:canonical_path).with("../bandit/bandit").and_return("c:/bandit/bandit") + expect(PathHelper.paths_eql?("bandit", "../bandit/bandit")).to be_false end end end |