干燥轨道模型代码成为问题

时间:2015-07-30 18:46:24

标签: ruby-on-rails ruby rspec

我有两个范围,我可以在3个不同的模型中重复使用,现在我在所有模型中都有相同的范围测试,所以我想做一些像共享测试的事情:

RSpec.shared_examples 'build_info' do |clazz|
  describe 'scopes' do
    context 'buildable' do
        it '0 builds' do
          expect(clazz.builds.count(:all)).to eq(0)
        end

         it '3 builds' do
          expect(clazz.builds(:even).count(:all)).to eq(3)
        end
    end
  end
end 

然后在MyModel规范中的一部分:

describe MyModel do
  include MyModule
  RSpec.include_example 'build_info', MyModel

  #relevant test
  describe 'scopes' do
    it_behaves_like 'build_info'
  end
end

我现在收到此错误:

my_model_spec.rb:5:in `block in <top (required)>': undefined method `include_example' for RSpec:Module (NoMethodError)

我做错了什么?

当我从RSpec

中删除include_example前缀时出现错误
gems/rspec-core-3.3.2/lib/rspec/core/example_group.rb:656:in 
`method_missing': undefined method `include_example' for 

RSpec::ExampleGroups::MyModel:Class (NoMethodError)

这是我在Gemfile.lock中的rspec信息:

rspec-collection_matchers (1.1.2)
      rspec-expectations (>= 2.99.0.beta1)
    rspec-core (3.3.2)
      rspec-support (~> 3.3.0)
    rspec-expectations (3.3.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.3.0)
    rspec-mocks (3.3.2)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.3.0)
    rspec-rails (3.3.3)
      actionpack (>= 3.0, < 4.3)
      activesupport (>= 3.0, < 4.3)
      railties (>= 3.0, < 4.3)
      rspec-core (~> 3.3.0)
      rspec-expectations (~> 3.3.0)
      rspec-mocks (~> 3.3.0)
      rspec-support (~> 3.3.0)
    rspec-support (3.3.0)

为什么我会收到undefined method include_example',我是否需要在测试配置文件中加入内容?

0 个答案:

没有答案