In Ruby on Rails 4, with RSpec 3.1, how do I set the values of the params
hash when testing a Rails helper method?
I want to set params[:search] = 'my keyword search'
for use in my helper method and then call it from within the it
example block.
spec/helpers/books_helper_spec.rb:
require 'rails_helper'
describe BooksHelper do
describe "#page_title_helper" do
let(:params) { {search: 'my keyword search'} }
it "should read the params hash" do
expect(helper.params[:search]).to eq "my keyword search"
end
end
end
app/helpers/books_helper.rb:
BooksHelper
def title_helper
if params[:search]
"Books related to #{params[:search]}"
else
"All Books"
end
end
end