title: Mocking all Rails routes in a view_context
body: <p>The Rails controller and views provide a <code>view_context</code> (usually an <code>ActionView::Base</code> object) that provides context for generating the views. </p>
  
  <p>A common pattern is to wrap model instances in a Presenter class, in which case the <code>view_context</code> is usually also passed as an argument so the Presenter can call view methods (e.g. <code>I8n.t()</code>, Rails path helpers, etc...) as needed.</p>
  
  <p>In my RSpec tests I use a mock to test the <code>view_context</code> behavior within the Presenter. For the path helpers specifically, I have to mock each path individually:</p>
  
  <pre><code>view_context = ActionView::Base.new
  user = UserPresenter.new(FactoryBot.create(:user), view: view_context)
  
  allow(view_context).to receive(:some_custom_path) do |opts|
    some_custom_path(opts)
  end
  </code></pre>
  
  <p><strong>Is there an easy way to programmatically mock all paths at once?</strong></p>
  
  <p>I suppose I could loop through the list of paths (not sure how to do that) and mock each one by one, but it feels like not the right approach. </p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT:</strong> Actually the above snippet isn't even correct. It throws an error because the <code>view_context</code> (<code>ActionView::Base</code>) doesn't even implement <code>:some_custom_path</code> in the first place. I'm guessing it's a protection measure against stubbing something that doesn't exist. </p>