I have been writing specs for controllers and models, but I have never written a helper spec. I have no idea where I start.
I have the following snippet in application_helper.rb
def title(page_title) content_for(:title) { page_title } end
From the rspec-rails docs on Helper Specs:
Helper specs live in spec/helpers, and mix in ActionView::TestCase::Behavior.
Provides a helper object which mixes in the helper module being spec'd, along with ApplicationHelper (if present).
require 'spec_helper' describe ApplicationHelper do describe "#title" do it "displays the title" do # helper is an instance of ActionView::Base configured with the # ApplicationHelper and all of Rails' built-in helpers expect(helper.title).to match /Some Title/ end end end
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