2

I have problem with using rspec-mocks.

bundle list shows:

Gems included by the bundle:
  * CFPropertyList (2.2.8)
  * builder (3.2.2)
  * bundler (1.7.12)
  * ci_reporter (1.9.3)
  * diff-lcs (1.2.5)
  * excon (0.44.0)
  * facter (2.4.0)
  * hiera (1.3.4)
  * json_pure (1.8.2)
  * metaclass (0.0.4)
  * mocha (1.1.0)
  * puppet (3.7.4)
  * puppet-lint (1.1.0)
  * puppet-syntax (1.4.1)
  * puppetlabs_spec_helper (0.8.2)
  * rake (10.4.2)
  * rcov (1.0.0)
  * rspec (3.1.0)
  * rspec-core (3.1.7)
  * rspec-expectations (3.1.2)
  * rspec-legacy_formatters (1.0.0)
  * rspec-mocks (3.1.3)
  * rspec-puppet (1.0.1)
  * rspec-support (3.1.2)

My rspec:

require 'spec/spec_helper'

describe 'My behaviour' do

  it 'should do something' do
    t = double()
  end
end

By my best knowledge, I done everything right, however I keep getting this kind of errors during test execution:

1) My behaviour should do something
     Failure/Error: Unable to find matching line from backtrace
     NoMethodError:
       undefined method `double' for #<RSpec::ExampleGroups::MyBehaviour:0x10275f168>
     # ./spec/puppet/util/network_device/netapp_e/my_example_spec.rb:8

And the same goes for every method from rspec-mocks such as: 'allow', 'receive', etc. Does anybody know, why this is happening?

kendriu
  • 565
  • 3
  • 21

1 Answers1

2

Did you declare that you want to use RSpec mocks? Usually this is done in the spec_helper.rb file like this:

RSpec.configure do |config|
  config.mock_framework = :rspec
end
spickermann
  • 100,941
  • 9
  • 101
  • 131
  • Well, it worked for me, but I have additional question. Where is it documented? I can't find that configuration of mocks is required in documentation of rspec-mocks. – kendriu Feb 03 '15 at 06:10
  • Find the documentation here: https://www.relishapp.com/rspec/rspec-core/v/3-1/docs/mock-framework-integration/mock-with-rspec The documentation says `rspec` is the default, but it seems to not be so easy... – spickermann Feb 03 '15 at 06:25