私は Web ベースの API 用の Ruby ラッパーを作成しています。各要求には、要求と共に送信される一意のトランザクション ID が必要です。
を使用してテスト シェルを作成しましたがMiniTest::Spec
、各テスト間でトランザクション ID が増加しません。
面倒な詳細を省略したテスト シェルは次のとおりです。
describe "should get the expected responses from the server" do
before :all do
# random number between 1 and maxint - 100
@txid = 1 + SecureRandom.random_number(2 ** ([42].pack('i').size * 8 - 2) - 102)
@username = SecureRandom.urlsafe_base64(20).downcase
end
before :each do
# increment the txid
@txid += 1
puts "new txid is #{@txid}"
end
it "should blah blah" do
# a test that uses @txid
end
it "should blah blah blah" do
# a different test that uses the incremented @txid
end
end
puts
ただし、そこにある行は、が@txid
実際には各テスト間で増加していないことを示しています。
さらにいくつかのテストは、テスト本体内のインスタンス変数への値の割り当てが変数の値に影響を与えないことを示しています。
これは期待されていますか?これを処理する正しい方法は何ですか?