her*_*hey 4 ruby testing rspec ruby-on-rails constants
使用Rails 3.2我在子目录中有一个控制器(例如/controllers/data_feeds/acme_feed_controller.rb)
该控制器有一些常数如下
class DataFeeds::AcmeFeedController < ApplicationController
MY_CONSTANT = "hi
def do_something do
...
end
end
Run Code Online (Sandbox Code Playgroud)
在我的rspec控制器规范(在/spec/controllers/data_feeds/acme_feed_controller_spec.rb中)我想访问该常量,以下是我尝试过的两种方法(两种方式都在下面的代码中注释掉)
describe AcmeFeedController do
if "tests something" do
#c = AcmeFeedController.MY_CONSTANT
#c = DataFeeds::AcmeFeedController.MY_CONSTANT
end
end
Run Code Online (Sandbox Code Playgroud)
我显然不了解规范测试的运行范围.我需要做什么,同样重要的原因(即范围内发生了什么).
谢谢你的帮助.