Module: Liquid::Rails::Rspec::ViewControllerContext
- Extended by:
- ActiveSupport::Concern
- Included in:
- DropExampleGroup, FilterExampleGroup, TagExampleGroup
- Defined in:
- lib/liquid4-rails/rspec/view_controller_context.rb
Instance Method Summary collapse
- #context(assigns = {}) ⇒ Object
- #controller ⇒ Object
- #expect_template_result(template, expected, assigns = {}) ⇒ Object
- #setup_view_and_controller ⇒ Object
- #view ⇒ Object
Instance Method Details
#context(assigns = {}) ⇒ Object
29 30 31 |
# File 'lib/liquid4-rails/rspec/view_controller_context.rb', line 29 def context(assigns={}) @context ||= ::Liquid::Context.new(assigns, {}, { helper: @view, view: @view, controller: @controller }) end |
#controller ⇒ Object
25 26 27 |
# File 'lib/liquid4-rails/rspec/view_controller_context.rb', line 25 def controller @controller end |
#expect_template_result(template, expected, assigns = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/liquid4-rails/rspec/view_controller_context.rb', line 33 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 |
#setup_view_and_controller ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/liquid4-rails/rspec/view_controller_context.rb', line 7 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 |
#view ⇒ Object
21 22 23 |
# File 'lib/liquid4-rails/rspec/view_controller_context.rb', line 21 def view @view end |