Ruby on rails 包含模块,但仍获得未初始化的常量错误
我的助手文件如下所示: /helpers/application_helper.rbRuby 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
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。我现在明白了我最好远离测试版的东西。祝你好运感谢您回来发布您的解决方案。