Skip to content

Instantly share code, notes, and snippets.

@yhara
Last active June 20, 2019 13:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhara/7bbdff3f48f3bd0cfcf8e783e46ffc70 to your computer and use it in GitHub Desktop.
Save yhara/7bbdff3f48f3bd0cfcf8e783e46ffc70 to your computer and use it in GitHub Desktop.
require 'tempfile'
# File.openを使う処理
def write_hello(path)
File.open(path, "a") do |file|
file.write "hello"
end
end
# テスト
def test_write_msg
tempfile = Tempfile.new
tempfile.close
write_hello(tempfile.path)
raise "テスト失敗" if File.read(tempfile.path) != "hello"
end
test_write_msg
require 'tempfile'
class A
attr_accessor :file_path
# File.openを使う処理
def write_hello
File.open(@file_path, "a") do |file|
file.write "hello"
end
end
end
# テスト
def test_write_msg
a = A.new
tempfile = Tempfile.new
tempfile.close
a.file_path = tempfile.path
a.write_hello
raise "テスト失敗" if File.read(tempfile.path) != "hello"
end
test_write_msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment