包含该模块但仍未获得未初始化的常量错误

时间:2014-10-04 11:17:22

标签: ruby-on-rails unit-testing rspec rspec-rails

My Helper文件如下所示:

/helpers/application_helper.rb

module ApplicationHelper

  # Returns the full title on a per-page basis.
  def full_title(page_title)
    base_title = "Ruby on Rails Tutorial Sample App"
    if page_title.empty?
      base_title
    else
      "#{base_title} | #{page_title}"
    end
  end

  # Helper for the sidebar menu highlighting
  def is_active?(page_name)
    if controller_name == "pages"
      "active" if action_name == page_name
    else
      "active" if controller_name == page_name
    end
  end

  # Set correct bootstrap flash messages design
  def bootstrap_class_for flash_type
    case flash_type
      when :success
        "alert-success" # Green
      when :error
        "alert-danger" # Red
      when :alert
        "alert-warning" # Yellow
      when :notice
        "alert-info" # Blue
      else
        flash_type.to_s
    end
  end

end

/support/utilities.rb

include ApplicationHelper

/helpers/application_helper_spec.rb

require 'spec_helper'

describe ApplicationHelper do

  describe "full_title" do

    it "should include the page title" do
      full_title('foo').should =~ /foo/
    end

    it "should include the base title" do
      full_title('foo').should =~ /^Ruby on Rails Tutorial Sample App/
    end

    it "should not include a bar on the home page" do
      full_title('').should_not =~ /\|/
    end
  end
end

我想使用以下规范测试我的应用程序full_title帮助器。我得到"未初始化的常量ApplicationHelper(NameError)" 错误,但我不明白为什么。我已经包含了ApplicationHelper文件。

有人知道哪里出错了吗?

未初始化的常量ApplicationHelper(NameError)

1 个答案:

答案 0 :(得分:1)

我恢复了宝石'rspec-rails','〜> 2.14.1',它再次有效!