Skip to content

Commit c5ec3a6

Browse files
committedNov 4, 2022
Add extra test for file generation, bring up to 2022 standardsish
1 parent d5c46cf commit c5ec3a6

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed
 

‎Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
source "http://rubygems.org"
1+
source "https://rubygems.org"
22

33
# Specify your gem's dependencies in webloc.gemspec
44
gemspec

‎lib/webloc.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ def data
3333
end
3434

3535
def save(filename)
36-
File.open(filename, 'w:binary') { |f| f.print data }
36+
File.open(filename, 'wb') { |f| f.write data }
3737
end
3838
end

‎lib/webloc/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class Webloc
2-
VERSION = "0.0.1"
2+
VERSION = "0.1.0"
33
end

‎test/webloc_test.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'test/unit'
22
require 'webloc'
3+
require 'tempfile'
34

45
class WeblocTest < Test::Unit::TestCase
56
def test_webloc_object_requires_url
@@ -20,7 +21,17 @@ def test_webloc_object_loaded_from_plist_file
2021

2122
def test_webloc_generates_valid_data
2223
data = File.read(File.dirname(__FILE__) + '/oldstyle.webloc')
23-
data = data.force_encoding('binary') rescue data
2424
assert_equal data, Webloc.new('https://github.com/peterc/webloc').data
2525
end
26+
27+
def test_webloc_can_write_file
28+
file = Tempfile.new('test-webloc')
29+
begin
30+
Webloc.new('https://github.com/peterc/webloc').save(file.path)
31+
assert_equal Webloc.new('https://github.com/peterc/webloc').data, File.read(file.path)
32+
ensure
33+
file.close
34+
file.unlink
35+
end
36+
end
2637
end

0 commit comments

Comments
 (0)