Sha256: afaf66dbc7bbfb1fa027628c7eed19247fd9db55440e143d3a852b12a1689a49

Contents?: true

Size: 1.7 KB

Versions: 58

Compression:

Stored size: 1.7 KB

Contents

require "action_dispatch/testing/assertions/routing"

module RSpec
  module Rails
    # @private
    RoutingAssertionDelegator =  RSpec::Rails::AssertionDelegator.new(
      ActionDispatch::Assertions::RoutingAssertions
    )

    # @api public
    # Container module for routing spec functionality.
    module RoutingExampleGroup
      extend ActiveSupport::Concern
      include RSpec::Rails::RailsExampleGroup
      include RSpec::Rails::Matchers::RoutingMatchers
      include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
      include RSpec::Rails::RoutingAssertionDelegator

      # Class-level DSL for route specs.
      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
          before do
            self.routes = yield
          end
        end
      end

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

      # @!attribute [r]
      # @private
      attr_reader :routes

      # @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
end

Version data entries

58 entries across 56 versions & 7 rubygems

Version Path
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/rspec-rails-6.0.4/lib/rspec/rails/example/routing_example_group.rb
rspec-rails-6.1.1 lib/rspec/rails/example/routing_example_group.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rspec-rails-5.1.2/lib/rspec/rails/example/routing_example_group.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rspec-rails-5.1.1/lib/rspec/rails/example/routing_example_group.rb
rspec-rails-6.1.0 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-6.0.4 lib/rspec/rails/example/routing_example_group.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rspec-rails-5.1.2/lib/rspec/rails/example/routing_example_group.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rspec-rails-5.1.1/lib/rspec/rails/example/routing_example_group.rb
rspec-rails-6.0.3 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-6.0.2 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-6.0.1 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-6.0.0 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-5.1.2 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-6.0.0.rc1 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-5.1.1 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-5.1.0 lib/rspec/rails/example/routing_example_group.rb
rspec-rails-5.0.3 lib/rspec/rails/example/routing_example_group.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/rspec-rails-5.0.2/lib/rspec/rails/example/routing_example_group.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/rspec-rails-5.0.2/lib/rspec/rails/example/routing_example_group.rb
rspec-rails-5.0.2 lib/rspec/rails/example/routing_example_group.rb