ä»æ¥ããã㨠ãã¹ãæ¸ããã諸ã åä½ãã¹ããç²ããã¨ãã«æ¸ãã¨æå¤ã¨è¯ããããããªãã ä»æ¥ã¯å ¶ã®éä¸ã§å¾ãç¥è¦ãæ¸ãã¦ãè¶ãæ¿ãã FileIOãããå¦çãRSpec㧠ãã¹ã対象 def file_write File.open('hoge.txt', 'w') do |f| f.print 'fuga' end end ãããªã³ã¼ãããã¹ãããªãããããªãã¨ãããã¡ã¤ã«ã«è²ã ã¨æ¸ãåºããã¦ãã¾ãã®ã§é¢åãããã ã¾ãæ¸ãåºããããã¡ã¤ã«ã®ä¸èº«ãæ£ããããã§ãã¯ããã®ã«ããã¡ã¤ã«ãèªã¾ãªãã¨è¡ããªãã®ã§å¤§å¤ã ãããªå¦çã®æã¯StringIOã便å©ã ã¾ãRSpecã§ã¯æ¢åã®å¦çãç°¡åã«ç½®ãæããããã file = StringIO.new('', 'w') allow(File).to receive(:open).and_yield(file) file_write excep
{{#tags}}- {{label}}
{{/tags}}