class RSpec::Rails::Matchers::RenderTemplate::RenderTemplateMatcher

@private

Public Class Methods

new(scope, expected, message = nil) click to toggle source
# File lib/rspec/rails/matchers/have_rendered.rb, line 8
def initialize(scope, expected, message = nil)
  @expected = Symbol === expected ? expected.to_s : expected
  @message = message
  @scope = scope
  @redirect_is = nil
end

Public Instance Methods

check_redirect() click to toggle source

Uses normalize_argument_to_redirection to find and format the redirect location. normalize_argument_to_redirection is private in ActionDispatch::Assertions::ResponseAssertions so we call it here using send. This will keep the error message format consistent @api private

# File lib/rspec/rails/matchers/have_rendered.rb, line 29
def check_redirect
  response = @scope.response
  return unless response.respond_to?(:redirect?) && response.redirect?

  @redirect_is = @scope.send(:normalize_argument_to_redirection, response.location)
end
failure_message() click to toggle source

@api private

# File lib/rspec/rails/matchers/have_rendered.rb, line 37
def failure_message
  if @redirect_is
    rescued_exception.message[/(.*?)( but|$)/, 1] +
      " but was a redirect to <#{@redirect_is}>"
  else
    rescued_exception.message
  end
end
failure_message_when_negated() click to toggle source

@api private

# File lib/rspec/rails/matchers/have_rendered.rb, line 47
def failure_message_when_negated
  "expected not to render #{expected.inspect}, but did"
end
matches?(*) click to toggle source

@api private

# File lib/rspec/rails/matchers/have_rendered.rb, line 16
def matches?(*)
  match_check = match_unless_raises ActiveSupport::TestCase::Assertion do
    @scope.assert_template expected, @message
  end
  check_redirect unless match_check
  match_check
end