Sha256: 23e39b6390d4cac73f006a41d559cb3d3aa2dcaa77960e5d8c21a711ccf8fdae

Contents?: true

Size: 1.02 KB

Versions: 12

Compression:

Stored size: 1.02 KB

Contents

module RSpec
  module Rails
    # Builds paths for view specs using a particular route set.
    class ViewPathBuilder
      def initialize(route_set)
        self.class.send(:include, route_set.url_helpers)
      end

      # Given a hash of parameters, build a view path, if possible.
      # Returns nil if no path can be built from the given params.
      #
      # @example
      #     # path can be built because all required params are present in the hash
      #     view_path_builder = ViewPathBuilder.new(::Rails.application.routes)
      #     view_path_builder.path_for({ :controller => 'posts', :action => 'show', :id => '54' })
      #     # => "/post/54"
      #
      # @example
      #     # path cannot be built because the params are missing a required element (:id)
      #     view_path_builder.path_for({ :controller => 'posts', :action => 'delete' })
      #     # => nil
      def path_for(path_params)
        url_for(path_params.merge(:only_path => true))
      rescue => e
        e.message
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
rspec-rails-3.6.1 lib/rspec/rails/view_path_builder.rb
rspec-rails-3.6.0 lib/rspec/rails/view_path_builder.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/rspec-rails-3.5.2/lib/rspec/rails/view_path_builder.rb
rspec-rails-3.6.0.beta2 lib/rspec/rails/view_path_builder.rb
rspec-rails-3.6.0.beta1 lib/rspec/rails/view_path_builder.rb
rspec-rails-3.5.2 lib/rspec/rails/view_path_builder.rb
rspec-rails-3.5.1 lib/rspec/rails/view_path_builder.rb
rspec-rails-3.5.0 lib/rspec/rails/view_path_builder.rb
rspec-rails-3.5.0.beta4 lib/rspec/rails/view_path_builder.rb
rspec-rails-3.5.0.beta3 lib/rspec/rails/view_path_builder.rb
rspec-rails-3.5.0.beta2 lib/rspec/rails/view_path_builder.rb
rspec-rails-3.5.0.beta1 lib/rspec/rails/view_path_builder.rb