Sha256: c199368bb11a0c85ffa20f9d77e4b767882601206cc11dd880af4d26fa3838be

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

module Liquid
  module Rails
    module Rspec
      module ViewControllerContext
        extend ActiveSupport::Concern

        def setup_view_and_controller
          @view                 = ActionView::Base.new
          @controller           = ApplicationController.new
          @request              = ActionController::TestRequest.new('PATH_INFO' => '/')
          @response             = ActionController::TestResponse.new
          @response.request     = @request
          @controller.request   = @request
          @controller.response  = @response
          @controller.params    = {}
          @view.assign_controller(@controller)
          @view.class.send(:include, @controller._helpers)
          @view.class.send(:include, ::Rails.application.routes.url_helpers)
        end

        def view
          @view
        end

        def controller
          @controller
        end

        def context(assigns={})
          @context ||= ::Liquid::Context.new(assigns, {}, { helper: @view, view: @view, controller: @controller })
        end

        def expect_template_result(template, expected, assigns={})
          # make assigns available inside context
          assigns.each do |key, value|
            context[key] = value
          end

          actual = Liquid::Template.parse(template).render!(context)
          expect(actual.to_s.strip).to eq(expected.to_s.strip)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
liquid-rails-0.1.4 lib/liquid-rails/rspec/view_controller_context.rb
liquid4-rails5-0.1.5 lib/liquid-rails/rspec/view_controller_context.rb
liquid4-rails-0.2.0 lib/liquid4-rails/rspec/view_controller_context.rb
liquid-rails-0.1.3 lib/liquid-rails/rspec/view_controller_context.rb
liquid-rails-0.1.2 lib/liquid-rails/rspec/view_controller_context.rb