0
我試着去改善我的Rspec的測試,並寫更多的人,在這個例子中,我可以創造一個圖像細膩測試通過了,但我對刪除該圖像的問題..Rspec的測試錯誤 - 未定義的方法創建
這裏是我的測試,到目前爲止
describe TimeTable do
before(:each) do
Paperclip::Attachment.any_instance.stub(
:post_process
).and_return(true)
Paperclip::Attachment.any_instance.stub(
:save
).and_return(true)
# This was a little harder - had to check the stack trace for errors.
Paperclip::Attachment.any_instance.stub(
:queue_all_for_delete
).and_return([])
end
it 'should save a image for TimeTable' do
image = Rack::Test::UploadedFile.new(
'spec/fixtures/rails.png', 'image/png'
)
@timetable = TimeTable.new(
photo: image
)
@timetable.save.should eq(true)
@timetable.photo_file_name.should eq('rails.png')
end
it 'should delete an image for TimeTable' do
image = Rack::Test::UploadedFile.new(
'spec/fixtures/rails.png', 'image/png'
)
@timetable.create!(
photo: image
)
expect { @timetable.destroy }.to change { TimeTable.count }.by(-1)
end
end
錯誤/失敗我得到的是
TimeTable should delete an image for TimeTable
Failure/Error: @timetable.create!(
NoMethodError:
undefined method `create!' for nil:NilClass
# ./spec/models/timetable_spec.rb:33:in `block (2 levels) in <top (required)>'
怎樣運用這個測試來刪除圖像
任何幫助表示讚賞