Using RSpec with Rails? Confused by trying to test helpers which vary based on the controller action?
It's easier than you think! While older versions of RSpec required stubbing, modern versions provide a
controller object to complement the
helper object you're already using.
Simply set the controller's
action_name in an individual test (or a
before block, depending on your spec structure):
controller.action_name = :new
and you're ready to rock:
expect(helper.my_awesome_helper).to match /Create a new/