Testing helper method call in view spec

21 views
Skip to first unread message

siva

unread,
Nov 19, 2013, 1:05:17 AM11/19/13
to rs...@googlegroups.com


  Hi

  First of all thanks everyone for helping.

  I have view partial file

  # app/views/reports/_lead_report_search.html.haml

  - if show_sold_by_options?
       = f.input :resource_key, input_options({label: 'Sold By'})
  - else
      - value = "#{current_resource.id}@@#{current_resource.class.name}"
      = f.input :resource_key, input_html: {value: value}, wrapper_html: {class: :hidden}, selected: param[:resource_key]


   # app/helpers/reports_helper.rb
    def show_sold_by_options?
        if is_lead_report
           is_org_user?
        end
    end

    I want to test whether method method has been called when view has been rendered? How can I test?

siva

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

I found the solution. We can do this using stubs.


it "should render sold by filter if sold by options returns true" do
    view.stub(:show_sold_by_options?).and_return(true)

    render partial: "reports/lead_report_search", handlers: [:haml], locals: { post_url: collection_summary_reports_path }

    expect(view).to have_received(:show_sold_by_options?)
    assert_select "input#search_resource_key[value='#{resource.id}@@#{resource.class.name}']", 0
  end

  Please correct me if I did anything wrong.
Reply all
Reply to author
Forward
0 new messages