Sha256: be8f0d4e6aa42dfc56b8dce76f613062e5a99b0c650c86465f89373759ad17ae

Contents?: true

Size: 1.26 KB

Versions: 6

Compression:

Stored size: 1.26 KB

Contents

module RSpec::Rails::Matchers
  module RoutingMatchers
    extend RSpec::Matchers::DSL

    matcher :route_to do |*route_options|
      match_unless_raises ActiveSupport::TestCase::Assertion do |path|
        assertion_path = { :method => path.keys.first, :path => path.values.first }

        path, options = *route_options

        if path.is_a?(String)
          controller, action = path.split("#")
          options ||= {}
          options.merge!(:controller => controller, :action => action)
        else
          options = path
        end

        assert_recognizes(options, assertion_path)
      end

      failure_message_for_should do
        rescued_exception.message
      end
    end

    matcher :be_routable do
      match_unless_raises ActionController::RoutingError do |path|
        @routing_options = routes.recognize_path(
          path.values.first, :method => path.keys.first
        )
      end

      failure_message_for_should_not do |path|
        "expected #{path.inspect} not to be routable, but it routes to #{@routing_options.inspect}"
      end
    end

    module RouteHelpers

      %w(get post put delete options head).each do |method|
        define_method method do |path|
          { method.to_sym => path }
        end
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rspec-rails-2.6.1 lib/rspec/rails/matchers/routing_matchers.rb
rspec-rails-2.6.1.beta1 lib/rspec/rails/matchers/routing_matchers.rb
rspec-rails-2.6.0 lib/rspec/rails/matchers/routing_matchers.rb
rspec-rails-2.6.0.rc6 lib/rspec/rails/matchers/routing_matchers.rb
rspec-rails-2.6.0.rc4 lib/rspec/rails/matchers/routing_matchers.rb
rspec-rails-2.6.0.rc2 lib/rspec/rails/matchers/routing_matchers.rb