タグ

rspecとStringIOに関するishideoのブックマーク (2)

  • rspec test result from csv.read mocking file

    I'm using ruby 1.9 and I'm trying to do BDD. My first test 'should read in the csv' works, but the second where I require a file object to be mocked doesn't. Here is my model spec: require 'spec_helper' describe Person do describe "Importing data" do let(:person) { Person.new } let(:data) { "title\tsurname\tfirstname\t\rtitle2\tsurname2\tfirstname2\t\r"} let(:result) {[["title","surname","firstnam

    rspec test result from csv.read mocking file
  • rspec でファイル読み書きテスト - LIFULL Creators Blog

    ネクストでレコメンドエンジン開発をしてる古川です。 rubyで、ファイルを読み込んで加工して別のファイルに出力というプログラムをよく書きます。 最近、rspec でテストを書くようになったのですが、beforeでテスト入力ファイルを作成し、 after で作成したテスト入力ファイル、テスト出力ファイルを削除、ということをしていました。 とりあえずは、これで問題なかったのですが、同時実行時や、実行時パス、パーミッションなど、 今後いろいろ問題になりそうで、いやだなと思っていたところ、Stack Overflowに、 まさに、それがやりたかったんだよ!という記事を見つけました。 StringIOを使えばよかったのですね。 記事は、読み込みテストだけでしたので、書き込みテストも追加してみました。 テスト対象クラス my_file_io.rb class MyFileIo def run(path

    rspec でファイル読み書きテスト - LIFULL Creators Blog
  • 1