user_spec.rb ファイルには、これらと同じコンテキストがあり、ドライメソッドで再コーディングしたいと考えています。
context 'when website adress starts with ' do
it 'http://, it should validate length of website' do
@profile.website = "x" * 393 # with appending http to website url its length will be 400.
assert @profile.save
end
it 'http://, it should not validate length of website' do
@profile.website = "x" * 394 # with appending http to website url its length will be 401.It should be failed.
assert !@profile.save
end
it 'https://, it should validate length of website' do
@profile.website = "https://" + "x" * 392 # with appending http to website url its length will be 400.
assert @profile.save
end
it 'https://, it should not validate length of website' do
@profile.website = "https://" + "x" * 393 # with appending http to website url its length will be 401.It should be failed.
assert !@profile.save
end
end
context 'when blog adress starts with ' do
it 'http://, it should validate length of blog' do
@profile.blog = "x" * 393 # with appending http to blog url its length will be 400.
assert @profile.save
end
it 'http://, it should not validate length of blog' do
@profile.blog = "x" * 394 # with appending http to blog url its length will be 401.It should be failed.
assert !@profile.save
end
it 'https://, it should validate length of blog' do
@profile.blog = "https://" + "x" * 392 # with appending http to blog url its length will be 400.
assert @profile.save
end
it 'https://, it should not validate length of blog' do
@profile.blog = "https://" + "x" * 393 # with appending http to blog url its length will be 401.It should be failed.
assert !@profile.save
end
end
このように書く方法はありますか? 2つの方法で同時に使いたいです。以下のコードを記述して呼び出すshould_validate_length_of('website')
と、 undefined local variable or method
should_validate_length_of '` エラーが発生します
def should_validate_length_of(dummy)
context 'when website adress starts with ' do
it 'http://, it should validate length of website' do
@profile.dummy = "x" * 393 # with appending http to website url its length will be 400.
assert @profile.save
end
it 'http://, it should not validate length of website' do
@profile.dummy = "x" * 394 # with appending http to website url its length will be 401.It should be failed.
assert !@profile.save
end
it 'https://, it should validate length of website' do
@profile.dummy = "https://" + "x" * 392 # with appending http to website url its length will be 400.
assert @profile.save
end
it 'https://, it should not validate length of website' do
@profile.dummy = "https://" + "x" * 393 # with appending http to website url its length will be 401.It should be failed.
assert !@profile.save
end
end
end