Given I have a full_title
method in ApplicationHelper module, how can I access it in a RSpec request spec?
I have the following code now:
app/helpers/application_helper.rb
module ApplicationHelper
# Returns the full title on a per-page basis.
def full_title(page_title)
base_title = "My Site title"
logger.debug "page_title: #{page_title}"
if page_title.empty?
base_title
else
"#{page_title} - #{base_title}"
end
end
spec/requests/user_pages_spec.rb
require 'spec_helper'
describe "User Pages" do
subject { page }
describe "signup page" do
before { visit signup_path }
it { should have_selector('h2', text: 'Sign up') }
it { should have_selector('title', text: full_title('Sign Up')) }
end
end
On running this spec, I get this error message:
NoMethodError:
undefined method full_title' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x00000003d43138>
As per the tests in Michael Hartl's Rails Tutorial, I should be able to access the application helper methods in my user spec. What mistake am I making here?
Another option is to include it directly in the spec_helper
RSpec.configure do |config|
...
config.include ApplicationHelper
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