Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I access Application Helper methods in a RSpec request?

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?

like image 651
rohitmishra Avatar asked Sep 20 '12 11:09

rohitmishra


1 Answers

Another option is to include it directly in the spec_helper

RSpec.configure do |config|
  ...
  config.include ApplicationHelper
end
like image 62
iNulty Avatar answered Oct 05 '22 22:10

iNulty