私はRuby/Railsを勉強しています。私の作品のコードベースを理解し、テストに追加することから始めます。私は、共有の例を設定する方法を理解することにいくつかの問題を抱えています。異なるコンテキストを持つ記述ブロックで、私は1つのコンテキスト内で作業したいので、その内部に変数を変更する2つのネストされたコンテキストを入れます。 context 'and the attachment is a zipfile' do
以下のコードでRSpecテストの共有サンプル内で共有サンプルを作成するために、コンテキスト内にコンテキストをネストする方法(すでに別のコンテキストにある)
は私が仕事をしたい記述ブロックのコンテキストである。私は'application/x-zip-compressed'
と'application/octet-stream'
ための2つの異なるコンテキストを有することによって可変contentType
を変更します。
let(:contentType)
でcontentType変数を変更するために2つの内部内部コンテキストを設定することはできますか、それは変更できない定数として理解できるシンボルなので動作しませんか?
元々、type
がのハッシュを"applicatoin/x-zip-compressed"
に設定しています。私は、共有の例を使用する方法を模索しています。タイプをコンテキストに応じて変えることができる変数にします。
context 'and the attachment is zipfile' do
let(:encoded) { true }
let(:data) { File.read(Rails.root + 'spec/fixtures/test_files/test.zip') }
let(:expected_status) { 'new' }
let(:attachments){{
"file1" => {
name: "test.zip",
type: contentType,
content: payload,
base64: encoded
}
}}
context 'and the attachment type is zip' do
let(:contentType) { 'application/x-zip-compressed' }
end
context 'and the attachment type is octet-stream' do
let(:contentType) { 'application/octet-stream' }
end
it 'saves each zipped file as a separate payload' do
expect(TransactionPayload.all.size).to eq 2
はい、あなたはセットアップ変数は、様々な動作を得るために、様々なコンテキスト内でletで定義されることができます。 –