frck_g
Last Updated: February 25, 2016
·
369
· colinm
C6f8df27d3cb30e02f01ee8b7a6d3449

Set an action for helper specs

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/
Say Thanks
Respond