I found the solution. We could do this using stubs

    it "should return true for lead_reports if user is organization user" do
        helper.stub(:params).and_return({action: 'lead_source'})
        helper.stub(:is_org_user?).and_return(true)
        
        expect(helper.show_sold_by_options?).to eq(true)
        expect(helper).to have_received(:is_org_user?)
      end 


  Please correct me if I did anything wrong.

On Tuesday, 19 November 2013 12:36:43 UTC+5:30, siva wrote:
>
>
>
>    Hi 
>
>    First of all thanks everyone for helping.
>
>    # app/helpers/reports_helper.rb
>     def show_sold_by_options?
>         if is_lead_report
>            is_org_user?
>         end
>     end
>
>    where is_org_user? is a method which is defined in 
> application_controller.rb file. When I write specs for this method as below 
>
>   #spec/helpers/reports_helper.rb
>
>    it "should returns true for lead_reports if user is organization user" 
> do
>         helper.stub(:params).and_return({action: 'lead_source'})
>         
>         expect(helper.show_sold_by_options?).to eq(true)
>         expect(helper).to have_received(:is_org_user?)
>       end 
>
>   output: 
>
>   Failure/Error: expect(helper.show_sold_by_options?).to eq(true)
>      NoMethodError:
>        undefined method `is_org_user?' for 
> #<#<Class:0x0000000b463470>:0x0000000b66d6f8>
>
>   Thank You
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/7c55d7ab-ebf6-4605-876d-c3bcae3a63ba%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to