If you are using spork with rspec, you should add the url_helper method to your rspec config -
Anywhere inside '/spec/spec_helper' file:
# spec/spec_helper.rb
RSpec.configure do |config|
...
config.include Rails.application.routes.url_helpers
...
end
this loads a built-in ApplicationHelper called "Routes" and calls the '#url_helpers' method into RSpec. There is no need to add it to the ApplicationHelper in '/app/helpers/application_helper.rb' for two reasons:
You are just copying 'routes' functionality into a place that doesn't need it, essentially the controller, which already inherits it from ActionController::Base (I think. maybe ::Metal. not important now). so you are not being DRY - Don't Repeat Yourself
This error is specific to RSpec configuration, fix it where it's broke (My own little aphorism)
Next, I'd recommend fixing your test a little. Try this:
require "spec_helper"
describe ApplicationHelper do
describe "#link_to_cart" do
it 'should be a link to the cart' do
visit cart_path
expect(page).to match(/.*href="\/cart".*/)
end
end
end
I hope that this is helpful to someone!