-
Notifications
You must be signed in to change notification settings - Fork 170
Various changes to get specs to pass on windows #225
Conversation
@@ -93,7 +93,7 @@ def generate_lock_and_install | |||
|
|||
lock_data = policyfile_compiler.lock.to_lock | |||
|
|||
File.open(policyfile_lock_expanded_path, "w+") do |f| | |||
File.open(policyfile_lock_expanded_path, "wb+") do |f| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the encoding to ASCII-8BIT
doesn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure about it becoming ASCII.
I do know that on windows, it will do a bunch of things if you don't specify binary mode.
In text mode, carriage return–linefeed combinations are translated into single linefeeds on input, and linefeed characters are translated to carriage return–linefeed combinations on output. When a Unicode stream-I/O function operates in text mode (the default), the source or destination stream is assumed to be a sequence of multibyte characters. Therefore, the Unicode stream-input functions convert multibyte characters to wide characters (as if by a call to the mbtowc function). For the same reason, the Unicode stream-output functions convert wide characters to multibyte characters (as if by a call to the wctomb function).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http://www.ruby-doc.org/core-2.1.4/IO.html#method-c-new
Check out the "b"
flag description there. We may already be specifying UTF8 encoding somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this will matter for writing. I'll try some things out.
LGTM |
@@ -93,7 +93,7 @@ def edit_repo | |||
edit_repo | |||
system_command('git config --local user.name "Alice"', cwd: cookbook_path).error! | |||
system_command('git config --local user.email "alice@example.com"', cwd: cookbook_path).error! | |||
system_command("git commit -a -m 'update readme' --author 'Alice <alice@example.com>'", cwd: cookbook_path).error! | |||
system_command('git commit -a -m "update readme" --author "Alice <alice@example.com>"', cwd: cookbook_path).error! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this all about? Also, looks like this adds two extra spaces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces: I had to create a fresh vm to develop on. And vim with default
settings is stupid.
Quotes: cmd.exe is stupid. It freaks out when using single quotes
On Tue, Nov 11, 2014 at 1:18 PM, Dan DeLeo notifications@github.com wrote:
In spec/unit/cookbook_profiler/git_spec.rb:
@@ -93,7 +93,7 @@ def edit_repo
edit_repo
system_command('git config --local user.name "Alice"', cwd: cookbook_path).error!
system_command('git config --local user.email "alice@example.com"', cwd: cookbook_path).error!
system_command("git commit -a -m 'update readme' --author 'Alice alice@example.com'", cwd: cookbook_path).error!
system_command('git commit -a -m "update readme" --author "Alice alice@example.com"', cwd: cookbook_path).error!
What's this all about? Also, looks like this adds two extra spaces?
—
Reply to this email directly or view it on GitHub
/~https://github.com/opscode/chef-dk/pull/225/files#r20181106.
Fix the spaces and then |
1afa88f
to
24690bf
Compare
@@ -89,7 +89,7 @@ def upload_policy | |||
end | |||
|
|||
def write_updated_lockfile | |||
File.open(policyfile_lock_expanded_path, "w+") do |f| | |||
File.open(policyfile_lock_expanded_path, "wb+") do |f| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is what we need, we can have a helper with_file
and make sure we don't break when we call File.open()
somewhere else later on.
@sersut factored out the File.open stuff |
FYI - there's an impact of #180 on this fix - the scope of this should be limited to cli_spec.rb. The code change I made is below, but this did not include the fixes in this PR. diff --git a/spec/unit/cli_spec.rb b/spec/unit/cli_spec.rb
index 8144602..b91ebb5 100644
--- a/spec/unit/cli_spec.rb
+++ b/spec/unit/cli_spec.rb
@@ -167,6 +167,12 @@ E
context "sanity_check!" do
context "on unix" do
+ before do
+ allow(Chef::Platform).to receive(:windows?).and_return(false)
+ stub_const("File::PATH_SEPARATOR", ':')
+ allow(cli).to receive(:path_key).and_return('PATH')
+ end
+
it "complains if embedded is first" do
expect(cli).to receive(:env).and_return({'PATH' => '/opt/chefdk/embedded/bin:/opt/chefdk/bin' })
allow(cli).to receive(:omnibus_embedded_bin_dir).and_return("/opt/chefdk/embedded/bin")
@@ -208,6 +214,7 @@ E
before do
allow(Chef::Platform).to receive(:windows?).and_return(true)
stub_const("File::PATH_SEPARATOR", ';')
+ allow(cli).to receive(:path_key).and_return('PATH')
end
it "complains if embedded is first" do |
@bwmeier I did something slightly different, it should have the same end result. |
Oh, after applying the #180 fix, I also had to include a change to exec_spec.rb to explicitly set the File::PATH_SEPARATOR: diff --git a/spec/unit/command/exec_spec.rb b/spec/unit/command/exec_spec.rb
index ba14724..6af639d 100644
--- a/spec/unit/command/exec_spec.rb
+++ b/spec/unit/command/exec_spec.rb
@@ -80,6 +80,7 @@ describe ChefDK::Command::Exec do
before do
allow(command_instance).to receive(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir)
allow(command_instance).to receive(:omnibus_bin_dir).and_return(omnibus_bin_dir)
+ stub_const("File::PATH_SEPARATOR", ':')
end
it "should call exec to fire off the command with the correct environment" do
@@ -115,6 +116,7 @@ describe ChefDK::Command::Exec do
before do
allow(command_instance).to receive(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir)
allow(command_instance).to receive(:omnibus_bin_dir).and_return(omnibus_bin_dir)
+ stub_const("File::PATH_SEPARATOR", ':')
end
it "should raise Errno::ENOENT" do |
That makes sense. |
@@ -103,5 +103,8 @@ def omnibus_env | |||
end | |||
end | |||
|
|||
def with_file(path, mode='wb+', &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add some comments here for why choosing this mode by default.
Overall 👍 |
Various changes to get specs to pass on windows
cc @btm @danielsdeleo @adamedx