0

I have a helper that looks like so:

module ActivityFeedHelper
  def render_activity_feed(activities)
    render partial: 'activities/activity_feed', locals: { activities: activities }
  end
end

I'm writing a spec for the helper that looks like:

describe ActivityFeedHelper do
  describe '.render_activity_feed' do
    let(:activities) { FactoryGirl.create_list(:activity, 3) }

    it 'should render activity feed' do
      expect(render_activity_feed(activities)).to render_template(partial: 'activities/activity_feed')
    end
  end
end

But this is giving me the error:

Failure/Error: expect(render_activity_feed(activities)).to render_template(partial: 'activities/activity_feed')                                                                                                                          
       expecting partial <activities/activity_feed> but action rendered <["activities/_activity", "_activity", "activities/_activities", "_activities", "activities/_activity_feed", "_activity_feed"]>.                                      
       Expected {"activities/_activity"=>3, "_activity"=>3, "activities/_activities"=>1, "_activities"=>1, "activities/_activity_feed"=>1, "_activity_feed"=>1} to include "activities/activity_feed".

Presumably this is happening because the partial renders multiple sub-partials.

That said, how should I be testing this?

1 Answer 1

2

I think that I have felt into this trap too once. Your error means that you have to render template in this way:

expect(render_activity_feed(activities)).to render_template(partial: 'activities/_activity_feed')

Note the leading underscore in _activity_feed.

Sign up to request clarification or add additional context in comments.

2 Comments

Yup - just discovered that before your post. Annoying! But thanks for your contribution.
It was all in your error message. Probably, majority of Rails errors can be solved by looking into the logs or other error output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.