Sha256: ac321c0e4d7c9cea72488389316a4b58ed8b3a6243791e1c2877836036a21318

Contents?: true

Size: 856 Bytes

Versions: 1

Compression:

Stored size: 856 Bytes

Contents

module RSpec::Rails::Matchers
  module RedirectTo
    class RedirectTo < RSpec::Matchers::BuiltIn::BaseMatcher

      def initialize(scope, expected)
        @expected = expected
        @scope = scope
      end

      # @api private
      def matches?(_)
        match_unless_raises ActiveSupport::TestCase::Assertion do
          @scope.assert_redirected_to(@expected)
        end
      end

      # @api private
      def failure_message_for_should
        rescued_exception.message
      end

      # @api private
      def failure_message_for_should_not
        "expected not to redirect to #{@expected.inspect}, but did"
      end
    end

    # Delegates to `assert_redirected_to`
    #
    # @example
    #
    #     expect(response).to redirect_to(:action => "new")
    def redirect_to(target)
      RedirectTo.new(self, target)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-rails-3.0.0.beta1 lib/rspec/rails/matchers/redirect_to.rb