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/
Written by Colin Mattson
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#