开发者

Rspec testing complex code with undefined variables

Just need alittle bit of help with rspec testing... very new to it and dont quite know how to test this piece of code

# Get a list of tasks recently used by the user
    recent_task_ids = Effort.all( :select => "projec开发者_Python百科t_task_id",
                                  :conditions => { :user_id => @user_id },
                                  :group => "project_task_id",
                                  :order => "MAX( week_commencing )" )


    # For each of the task ids, get the actual project task records
    @recent_tasks = []
    recent_task_ids.each do |effort|
      if ProjectTask.find_by_id( effort.project_task_id ) != nil
        @recent_tasks.push( ProjectTask.find( effort.project_task_id ) )
      end
    end

Not sure if your even supposed to test undefined variables this way but any help would be great


You can stub out the Effort.all method.

it "tests with nil values" do
  Effort.stub(:all).and_return(nil)
end

Source: http://rspec.info/documentation/mocks/stubs.html and http://rspec.info/documentation/mocks/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜