Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/github/auth/keys_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def write!(keys)
Array(keys).each do |key|
unless keys_file_content.include? key.key
append_keys_file do |keys_file|
keys_file.write "\n" unless keys_file_content.empty?
keys_file.write key
keys_file.write "\n" unless keys_file_content.empty? || keys_file_content.end_with?("\n")
keys_file.write "#{key}\n"
end
end
end
Expand Down Expand Up @@ -57,7 +57,7 @@ def keys_file_content_without(keys)
content.gsub! /#{Regexp.escape key.key}( .*)?$\n?/, ''
end

content.strip!
content << "\n" unless content.empty? || content.end_with?("\n")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still want a newline if content.empty?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually - scratch that. We don't need a newline if the content is empty 😄

end
end
end
Expand Down
16 changes: 7 additions & 9 deletions spec/unit/github/auth/keys_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@
end
end

it 'does not leave a blank line' do
it 'includes a newline after the last key' do
subject.write! keys

expect(
keys_file.readlines.select { |line| line =~ /^$\n/ }
).to be_empty
expect(keys_file.read).to end_with("\n")
end
end

Expand All @@ -80,6 +78,7 @@

before do
keys_file.write existing_keys.join("\n")
keys_file.write "\n"
keys_file.rewind
end

Expand Down Expand Up @@ -132,6 +131,7 @@

before do
keys_file.write keys.join("\n")
keys_file.write "\n"
keys_file.rewind
end

Expand All @@ -152,12 +152,10 @@
end
end

it 'does not leave a blank line' do
subject.delete! key
it 'includes a newline after the last key' do
subject.write! keys
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, oops. Looks like a write! slipped in here. The test setup should be subject.delete! key

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, my bad, nice catch. C&P error. I'll fix shortly.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this in 4dd6f26, no worries. ❤️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for wrapping this up 🎊


expect(
keys_file.readlines.select { |line| line =~ /^$\n/ }
).to be_empty
expect(keys_file.read).to end_with("\n")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need to update this test to satisfy keys_file.rb#L60

content = keys_file.read
expect(content).to end_with("\n") unless content.empty?

end
end

Expand Down