mercredi 28 octobre 2015

RSpec matching request to render text

Is it possible to examine if get request rendered text?

I know there are hacks like response.body == 'any string' but it does not interest me. I'm just wondering if there is "RSpec™" way to do it.

Having this rspec:

RSpec.describe MyController, type: :controller do
  controller do
    def index
      render text: 'Hellow'
    end
  end

  describe 'rendering' do
    subject { get :index }
    it { is_expected.to render_template(text: 'Hellow')}
  end
end

I would love to be able to call it { is_expected.to render_template(text: 'Hellow')}. It raises:

 Failure/Error: it { is_expected.to render_template(text: 'Hellow') }
 ArgumentError:
   Unknown key: :text. Valid keys are: :layout, :partial, :locals, :count, :file

or maybe it { is_expected.to render_template('Hellow')}

 Failure/Error: it { is_expected.to render_template('Hellow') }
   expecting <"Hellow"> but rendering with <[]>

Is there any RSpec™ way to accomplish it?

Aucun commentaire:

Enregistrer un commentaire