Lazarus Lazaridis
Lazarus Lazaridis

Reputation: 6029

RSpec view specs - Check that layout yields

I want to check that my layout yields (either with no args or for specific content):

<%= yield %>
<%= yield :something %>

I've got something like this in my view spec:

let(:page) { Capybara::Node::Simple.new(rendered) }

before do
  # I want to stub the 'yield' stuff here

  render
end

it { should have_css 'my yielded stuff' }

but I can't find a way to to stub the yield execution.

I prefer to avoid using a sample view with the given layout to simulate the rendering.

Upvotes: 0

Views: 534

Answers (1)

Leonhardt Koepsell
Leonhardt Koepsell

Reputation: 379

I'm using this view spec to test that my layout yields:

describe 'layouts/application.html.slim' do
  it 'yields a subview' do
    render text: 'a subview', layout: 'layouts/application'
    expect(rendered).to have_text('a subview')
  end
end

Upvotes: 1

Related Questions