RSpec

RSpec の expect_any_instance_of でハマった

class Test def say_hoge hoge1 = Hoge.new hoge2 = Hoge.new hoge1.say hoge2.say end end class Hoge def say puts 'hoge' end end こんな感じのクラスがあったとして、 Test#say_hoge で Hoge インスタンスが Hoge#say を1回ずつ実行していることをテスト…

Factory Girl で関連を定義する

1対1の関連を持つ users テーブルと profiles テーブルがあり、User モデルと Profile モデルがそれぞれ以下のように定義されているとします。 users テーブル field type id int プライマリキー name string email string profiles テーブル field type id …