-
-
Save yhara/7bbdff3f48f3bd0cfcf8e783e46ffc70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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