RSpecのbeforeはどう書いた方が良いかな?
次のRSpecを使ったテストコードはどちらが良いだろうか?
- Type 1
describe Foo, "hoge" do before do @arg = gen_something() end it "bar" do Foo.new(@arg).should be_an_instance_of(Foo) end # ...略,以降のコードに@argは現れない. end
- Type 2
describe Foo, "hoge" do it "bar" do Foo.new(gen_something()).should be_an_instance_of(Foo) end # ...略. end