Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 包含模块,但仍获得未初始化的常量错误_Ruby On Rails_Unit Testing_Rspec_Rspec Rails - Fatal编程技术网

Ruby on rails 包含模块,但仍获得未初始化的常量错误

Ruby on rails 包含模块,但仍获得未初始化的常量错误,ruby-on-rails,unit-testing,rspec,rspec-rails,Ruby On Rails,Unit Testing,Rspec,Rspec Rails,我的助手文件如下所示: /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

我的助手文件如下所示:

/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
/帮助程序/应用程序\u帮助程序\u规范.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 helper。我得到了“未初始化常量ApplicationHelper(NameError)”错误,但我不明白原因。我已经包含了ApplicationHelper文件

有人知道哪里出了问题吗


未初始化的常量ApplicationHelper(NameError)

我恢复到gem'rspec rails',“~>2.14.1”,它再次工作

根据本教程,您应该为gems使用准确的版本号,根据本教程的在线版本,rspec-rails应该是:
gem'rspec-rails','2.13.1'
如果您放弃了这一点,您可能会遇到奇怪的错误。所以我想问题是:“你为什么不按照教程做呢?”你在读这本书吗?这本书使用了比在线教程更新版本的gems吗?我读了这本书,并按照他们告诉我的做了。现在我正在自己创建一个应用程序,我想学习如何使用更新的gems。我现在明白了我最好远离测试版的东西。祝你好运感谢您回来发布您的解决方案。