我有一个rspec模拟对象,给它的属性赋了一个值。我正在努力让我的rspec测试达到预期。想知道语法是什么?代码如下:
def create
@new_campaign = AdCampaign.new(params[:new_campaign])
@new_campaign.creationDate = "#{Time.now.year}/#{Time.now.mon}/#{Time.now.day}"
if @new_campaign.save
flash[:status] = "Success"
else
flash[:status] = "Failed"
end end
这是一个测试
it "should able to create new campaign when form is submitted" do
campaign_model = mock_model(AdCampaign)
AdCampaign.should_receive(:new).with(params[:new_campaign]).and_return(campaign_model)
campaign_model.should_receive(:creationDate).with("#{Time.now.year}/#{Time.now.mon}/#{Time.now.day}")campaign_model.should_receive(:save).and_return(true)
post :create
flash[:status].should == 'Success'
response.should render_template('create') end
问题在于我遇到了这个错误:
Spec::Mocks::MockExpectationError in 'CampaignController new campaigns should able to create new campaign when form is submitted' Mock "AdCampaign_1002" received unexpected message :creationDate= with ("2010/5/7")
那么我怎样才能设置对象属性分配的期望呢?谢谢。