Reputation: 889
I wrote a simple test, as follows:
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
When I try to run this test, I get the following error:
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
I've no idea why the double() method isn't working. I've searched high and low for this specific error and the closest thing I saw to something relevant was that require 'spec_helper.rb' was missing, but I have that line present. Any ideas, anyone?
Upvotes: 1
Views: 2392
Reputation: 889
Ended up being that the line config.mock_with :mocha was erroneously included in my spec_helper.rb file. Removing it did the trick.
Upvotes: 8