Sha256: a13015dc7f5eded83802ea1e24b8b889c2867612b69f715930584fc9022a58f3

Contents?: true

Size: 1.41 KB

Versions: 12

Compression:

Stored size: 1.41 KB

Contents

require "action_dispatch/testing/assertions/routing"

module RSpec::Rails
  module RoutingExampleGroup
    extend ActiveSupport::Concern
    include RSpec::Rails::RailsExampleGroup
    include RSpec::Rails::Matchers::RoutingMatchers
    include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
    include RSpec::Rails::AssertionDelegator.new(ActionDispatch::Assertions::RoutingAssertions)

    module ClassMethods
      # Specifies the routeset that will be used for the example group. This
      # is most useful when testing Rails engines.
      #
      # @example
      #
      #     describe MyEngine::PostsController do
      #       routes { MyEngine::Engine.routes }
      #
      #       it "routes posts#index" do
      #         expect(:get => "/posts").to
      #           route_to(:controller => "my_engine/posts", :action => "index")
      #       end
      #     end
      def routes(&blk)
        before do
          self.routes = blk.call
        end
      end
    end

    included do
      metadata[:type] = :routing

      before do
        self.routes = ::Rails.application.routes
      end
    end

    attr_reader :routes

    # @api private
    def routes=(routes)
      @routes = routes
      assertion_instance.instance_variable_set(:@routes, routes)
    end

    private

    def method_missing(m, *args, &block)
      routes.url_helpers.respond_to?(m) ? routes.url_helpers.send(m, *args) : super
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rspec-rails-2.99.0 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-2.99.0.rc1 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-2.14.2 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-3.0.0.beta2 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-2.99.0.beta2 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-2.14.1 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-3.0.0.beta1 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-2.99.0.beta1 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-2.14.0 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-2.14.0.rc1 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-2.13.2 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-2.13.1 lib/rspec/rails/example/routing_example_group.rb