Throws error on helper tests for contoller methods

15 views
Skip to first unread message

siva

unread,
Nov 19, 2013, 2:06:43 AM11/19/13
to rs...@googlegroups.com


   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

siva

unread,
Nov 26, 2013, 12:52:36 AM11/26/13
to rs...@googlegroups.com

  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.
Reply all
Reply to author
Forward
0 new messages