Sha256: 21e8ceea123c67bf4e785d87aeebaddd21bab3f2a438866ad85b850ecf062bb3

Contents?: true

Size: 1.81 KB

Versions: 8

Compression:

Stored size: 1.81 KB

Contents

require 'unit_spec_helper'

describe Shoulda::Matchers::ActionController::RenderWithLayoutMatcher, type: :controller do
  include ActionController::TemplateAssertions

  context 'a controller that renders with a layout' do
    it 'accepts rendering with any layout' do
      expect(controller_with_wide_layout).to render_with_layout
    end

    it 'accepts rendering with that layout' do
      expect(controller_with_wide_layout).to render_with_layout(:wide)
    end

    it 'rejects rendering with another layout' do
      expect(controller_with_wide_layout).not_to render_with_layout(:other)
    end

    def controller_with_wide_layout
      create_view('layouts/wide.html.erb', 'some content, <%= yield %>')
      build_fake_response { render layout: 'wide' }
    end
  end

  context 'a controller that renders without a layout' do

    it 'rejects rendering with a layout' do
      controller_without_layout = build_fake_response { render layout: false }

      expect(controller_without_layout).not_to render_with_layout
    end
  end

  context 'a controller that renders a partial' do
    it 'rejects rendering with a layout' do
      controller_with_partial = build_fake_response { render partial: 'partial' }

      expect(controller_with_partial).not_to render_with_layout
    end
  end

  context 'given a context with layouts' do
    it 'accepts that layout in that context' do
      context = Object.new
      set_layout_in_context(context, 'happy')

      expect(controller_without_layout).
        to render_with_layout('happy').
        in_context(context)
    end

    def set_layout_in_context(context, layout)
      layouts = Hash.new(0)
      layouts[layout] = 1
      context.instance_variable_set('@_layouts', layouts)
    end

    def controller_without_layout
      build_fake_response { render layout: false }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
shoulda-matchers-3.1.3 spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb
shoulda-matchers-4.0.0.rc1 spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb
shoulda-matchers-3.1.2 spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb
shoulda-matchers-3.1.1 spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb
shoulda-matchers-3.1.0 spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb
shoulda-matchers-3.0.1 spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb
shoulda-matchers-3.0.0 spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb
shoulda-matchers-3.0.0.rc1 spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb