Rspec と Selenium を使用していくつかの自動テストをセットアップしていますが、プログラムでサンプルを作成しようとするといくつかの問題が発生します。
データの変更に基づいて複数回テストする必要がある複数の項目を含む配列があります。
配列:
def get_array
@stuff = { thing1, thing2, thing3 }
end
テストの簡易版:
describe "My tests" do
context "First round" do
before { #do some stuff }
@my_array = get_array
@my_array.each do |k|
it "should pass the test" do
k.should pass_the_test
end
end
end
context "Second round" do
before { #do some other stuff }
@my_array = get_array
@my_array.each do |k|
it "should pass the test" do
k.should pass_the_test
end
end
end
end
この例ではそれほど悪くはありませんが、毎回 @my_array = get_array を呼び出さなければならないことは、明らかに DRY ではありません。より多くのテストと複雑さを追加しているので、これはすぐに手に負えなくなります。そのため、これを行うためのより簡単でより良い方法は何か疑問に思っています。
共有コンテキストなどを試してみましたが、何もうまくいかないようです。