2012-01-05 75 views
1

我寫了一個簡單的測試,如下:RSpec的:未定義的方法`雙」爲#<:: RSpec的核心:: ExampleGroup :: Nested_1:0x007fcc2f626d50>

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 

當我嘗試運行這個測試,我得到以下錯誤:

Failures:

1) Channel should get the true view count Failure/Error: upload_view_count = double('upload view count') NoMethodError: undefined method double' for #<RSpec::Core::ExampleGroup::Nested_1:0x007fcc2f66a8c0> # ./spec/models/channel_spec.rb:9:in block (2 levels) in '

2) Channel should get the true view count with multiple upload view counts Failure/Error: upload_vc1 = double('uplaod view count 1') NoMethodError: undefined method double' for #<RSpec::Core::ExampleGroup::Nested_1:0x007fcc2f626d50> # ./spec/models/channel_spec.rb:17:in block (2 levels) in '

Finished in 37.68 seconds 5 examples, 2 failures, 3 pending

Failed examples:

rspec ./spec/models/channel_spec.rb:8 # Channel should get the true view count rspec ./spec/models/channel_spec.rb:16 # Channel should get the true view count with multiple upload view counts

我不知道爲什麼double()方法不工作。我已經搜索了這個特定的錯誤的最高和最低的東西,我看到有關的最接近的東西是需要'spec_helper.rb'丟失,但我有該行目前。任何想法,任何人?

回答

8

結論是行config.mock_with:mocha被錯誤地包含在我的spec_helper.rb文件中。刪除它做了伎倆。

相關問題