我想發佈到我的控制器在RSPEC,看到有什麼不對?它的失敗W/O錯誤:RSPEC如何發佈到控制器?這有什麼問題?
it "should store create an IncomingMail record" do
lambda {
post 'create', {
"from" => 'XXX',
"to" => 'XXX',
"cc" => 'XXX',
"subject" => 'XXX',
"message_text" => 'XXX',
"message_html" => 'XXX' }
}.should change { IncomingMail.count }.by(1)
end
更新時間:
it "should store create an IncomingMail record" do
post :create,
:from => 'xx',
:to => 'xx',
:cc => 'xx',
:subject => 'xx',
:message_text => 'xx',
:message_html => 'xx'
mail = IncomingMail.last(:order => 'created_at desc')
mail.from.should == 'xx'
end
控制器
class IncomingMailsController < ApplicationController
require 'iconv'
#make sure that rails doesn't raise an exception because we have no way of knowing the token
skip_before_filter :verify_authenticity_token
def create
begin
@incoming_mail = IncomingMail.create(
:from => params[:from],
:to => params[:to],
:cc => params[:cc],
:subject => params[:subject],
:message_text => message_text_utf8,
:message_html => message_html_utf8
)
.....
添加了一個更新的方法。它仍然失敗。在test.log文件中,我看到正在創建的記錄,但隨後顯示:SQL(0.1ms)RELEASE SAVEPOINT active_record_1 SQL(0.3ms)SELECT COUNT(*)FROM「incoming_mails」 SQL(0.1ms)ROLLBACK – AnApprentice 2011-03-19 20:44:02
錯誤與失敗/錯誤:mail.from =='xx' NoMethodError: 你有沒有對象,當你沒有想到它! 您可能預期了Array的一個實例。 評估nil時發生錯誤 – AnApprentice 2011-03-19 20:47:39
也嘗試將它包裝在一個lambda,lambda {....}。應該改變(IncomingMail,:count).by(1)同樣的問題,沒有更新計數。這是否與控制器創建記錄和記錄不是在rspec內創建的事實有關? – AnApprentice 2011-03-19 21:01:56