我试图在 Rails 测试中模仿类似枚举的效果。但是,我似乎无法让它工作。
例子。
我有一个名为 Days 的模块:
module Days
SUNDAY = 0;
MONDAY = 1;
TUESDAY = 2;
WEDNESDAY = 3;
THURSDAY = 4;
FRIDAY = 5;
SATURDAY = 6;
end
在同一目录中,我有一个 scheduler_spec.rb
require 'spec_helper'
describe Scheduler do
include Days
...
但是,Ruby 会抛出以下错误:
in `block in <top (required)>': uninitialized constant Days (NameError)
from /Users/krg07/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.9.0/lib/rspec/core/example_group.rb:201:in `module_eval'
from /Users/krg07/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-2.9.0/lib/rspec/core/example_group.rb:201:in `subclass' ...
知道我怎样才能完成这项工作吗?谢谢!