Sha256: 960bfbddf3d21e6f6e09ccf7e0968bd1e049b5bbdb85bbe6731afbea26e97077

Contents?: true

Size: 843 Bytes

Versions: 2

Compression:

Stored size: 843 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
        rescued_exception.message
      end

      # @api private
      def failure_message_when_negated
        "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

2 entries across 2 versions & 1 rubygems

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