RSpec:未定义的方法`double'用于#<rspec :: core :: examplegroup :: nested_1:0x007fcc2f626d50> </rspec :: core :: examplegroup :: nested_1:0x007fcc2f626d50>

时间:2012-01-05 01:22:18

标签: rspec rspec2

我写了一个简单的测试,如下:

    require 'spec_helper.rb'

describe Channel do
  before(:each) do
    @channel = Channel.new
  end

  it "should get the true view count" do 
    upload_view_count = double('upload view count')
    upload_view_count.should_receive(:upload_num).and_return(16000666)
    @channel.upload_view_counts << upload_view_count
    @channel.save()
    @channel.true_all_time_views.should equal(16000666)
  end

  it "should get the true view count with multiple upload view counts" do
    upload_vc1 = double('uplaod view count 1')
    upload_vc1.should_receive(:created_at).and_return(Time.now())
    upload_vc1.should_receive(:upload_num).and_return(17666)
    upload_vc1.should_receive(:updated_at).and_return(Time.now())

    upload_vc2 = double('upload view count 2')
    upload_vc2.should_receive(:created_at).and_return(Time.now())
    upload_vc2.should_receive(:upload_num).and_return(17777)
    upload_vc2.should_receive(:updated_at).and_return(Time.now())

    @channel.upload_view_counts << upload_vc1
    @channel.upload_view_counts << upload_vc2
    @channel.save()
    @channel.true_all_time_views.should equal(17777)
  end




end

当我尝试运行此测试时,出现以下错误:

  

故障:

     

1)频道应获得真实的观看次数        失败/错误:upload_view_count = double('upload view count')        NoMethodError:          '

中的未定义方法double' for #<RSpec::Core::ExampleGroup::Nested_1:0x007fcc2f66a8c0> # ./spec/models/channel_spec.rb:9:in块(2级)      

2)频道应该通过多个上传视图获得真实的视图计数   计数        失败/错误:upload_vc1 = double('uplaod view count 1')        NoMethodError:          '

中的未定义方法double' for #<RSpec::Core::ExampleGroup::Nested_1:0x007fcc2f626d50> # ./spec/models/channel_spec.rb:17:in块(2级)      

以37.68秒完成5个示例,2个失败,3个等待

     

失败的例子:

     

rspec ./spec/models/channel_spec.rb:8#Channel应该是真的   查看计数rspec ./spec/models/channel_spec.rb:16#频道应该得到   具有多个上载视图计数的真实视图计数

我不知道为什么double()方法不起作用。我已经搜索了这个特定错误的高低,我看到的最接近的东西是需要'spec_helper.rb',但我有这条线。任何想法,任何人?

1 个答案:

答案 0 :(得分:8)

结果是我的spec_helper.rb文件中错误地包含了config.mock_with:mocha这一行。删除它就行了。