0
在我的Ruby on Rails應用程序中,我有一個動作copy
,它複製invoice
並將其值顯示到new
操作中的前端。如何用RSpec測試新動作的初始化值?
它的工作原理,但我很難發現它的測試:
describe 'GET #copy' do
before :each do
@invoice = FactoryGirl.create(:invoice, :date => Date.yesterday)
end
it "renders the :new template" do # this works
get :copy, :id => @invoice
expect(response).to render_template :new
end
it "sets the correct date" do
get :copy, :id => @invoice
expect(new_invoice.date).to eql(@invoice.date) # what I had in mind...
end
end
我只是想測試是否date
被正確地複製和形式顯示。我需要先保存新發票才能測試嗎?
感謝您的任何幫助。
就是這樣,非常感謝安裝
gem 'rails-controller-testing'
! – Tintin81