I'm writing a view spec, and it renders a view that contains the line (in haml):
=link_to new_post_path
but the spec fails with:
ActionController::RoutingError: No route matches {:action=>"new", :controller=>"post"}
I'm trying to stub the new_post_path
method, as it's not actually important to the view spec, but haven't had any luck.
I've tried, within my spec, the following two variations without any luck:
stub!(:new_post_path).and_return("this path isn't important")
controller.stub!(:new_post_path).and_return("this path isn't important")
If you're not in a view spec, but find yourself needing to stub a path helpers, the following syntax works as of Rails 4.2.5; you'll need to receive_message_chain
instead as described here:
https://github.com/rspec/rspec-mocks/issues/1038
To wit:
allow(Rails.application).to receive_message_chain(:routes, :url_helpers, :new_post_path).and_return("this path isn't important")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With