On Nov 24, 2010, at 1:07 AM, Arun Sharma wrote:
> hii
>
> I am initial level of rspec. I am getting a error nil class.
>
> My Controller code is as follows
>
> class UsersController < ApplicationController
> before_filter :have_hard_drive?
> # # filter check for authorized user to access current server
> before_filter :authorized_user_to_server?
> # # Will check that the cpanel id is belongs to current server or not
> before_filter :is_cpanel_belongs_to_current_server?
> def automatic_partitions
> @prev_values = Cpanel.find(:all,:conditions => ["harddrive_id = ?
> and server_id
> =?",HARDDRIVE_SLOTS[params[:harddrive_id].to_i],params[:server_id]])
> @prev_values.each do |value|
> value.destroy
> end
> @ignored_harddisk = IgnoredHarddrive.find(:first,:conditions =>
> ["server_id = ? and harddrive_id =
> ?",params[:server_id],HARDDRIVE_SLOTS[params[:harddrive_id].to_i]])
> if @ignored_harddisk
> @ignored_harddisk.destroy
> end
> end
> end
>
> and My Spec code is
>
> require 'spec_helper'
> describe CpanelsController do
>
> describe "role_as_superadmin" do
> before(:each) do
> user=User.authenticate('superadmin','carmatec')
> user.is_superadmin
> session[:user_id]=user.id
> controller.stub(:have_hard_drive?)
> controller.stub(:is_cpanel_belongs_to_current_server?)
> controller.stub(:authorized_user_to_server?)
>
> end
> it "should_test_automatic_partions" do
>
> @prev_values=mock_model(Cpanel)
> Cpanel.should_receive(:find).and_return(@prev_values)
> @ignored_harddisk=mock_model(IgnoredHarddrive)
> IgnoredHarddrive.should_receive(:find).and_return(@ignored_harddisk)
>
> get :automatic_partitions,{:harddrive_id=>'sda',:server_id=>1938}
> assigns[:prev_values].should==''
>
> end
> end
>
> and I am getting an error
>
> Spec::Mocks::MockExpectationError in 'CpanelsController
> should_test_automatic_partions'
> <Cpanel(id: integer, server_id: integer, mount_point: string,
> file_system: string, size: string, grow: string, bad_sector: string,
> raid_level: string, raid_device: string, harddrive_id: string) (class)>
> expected :find with (any args) once, but received it 0 times
>
> please anyone post the solution
My guess is one of the before filters is preventing the automatic_partitions
action from being invoked.
Cheers,
David
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users