RSpec:未定义的方法'double';对于#<;RSpec::Core::ExampleGroup::嵌套的\u 1:0x007fcc2f626d50>;
我编写了一个简单的测试,如下所示:RSpec:未定义的方法'double';对于#<;RSpec::Core::ExampleGroup::嵌套的\u 1:0x007fcc2f626d50>;,rspec,rspec2,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_receiv
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
需要“spec\u helper.rb”
描述频道做什么
在…之前做
@channel=channel.new
终止
它“应该获得真实的视图计数”这样做
上传查看次数=双倍(“上传查看次数”)
上传\查看\计数。应\接收(:上传\数量)。并\返回(16000666)
@channel.upload_view_counts的结果是:mocha的config.mock_行错误地包含在我的spec_helper.rb文件中。删除它就成功了。最终导致config.mock_with:mocha一行错误地包含在我的spec_helper.rb文件中。移除它成功了