我刚刚升级到 RSpec 2.13,在运行我的规范时看到了两个不同的警告:
/Users/peterbrown/.rvm/gems/ruby-2.0.0-p0/gems/rspec-core-2.13.0/lib/rspec/core/memoized_helpers.rb:120: warning: method redefined; discarding old subject
/Users/peterbrown/code/classy_enum/spec/classy_enum/active_record_spec.rb:63: warning: previous definition of subject was here
我怀疑这与我如何循环遍历数组并每次定义一个新主题有关:
describe DefaultDog do
context "with valid breed options" do
[:golden_retriever, 'golden_retriever', Breed::GoldenRetriever.new, Breed::GoldenRetriever].each do |option|
subject { DefaultDog.new(:breed => option) }
it { should be_valid }
its(:breed) { should be_a(Breed::GoldenRetriever) }
end
end
end
在这样的循环中定义主题有问题吗?
更新:
我还应该注意,我正在使用以下-w
选项运行我的规范:
RSpec::Core::RakeTask.new(:spec) do |t|
t.ruby_opts = "-w"
end