1. jferris-mocha and Rspec

    1 September 2009

    I ran into a small issue when using Joe Ferris’ fork of Mocha with Rspec. In the spec helper you have “


    config.mock_with :mocha


    I’m on version 0.9.5.0.1241126838 of jferris-mocha and the library load was failing. The reason is because Mocha::Standalone has been changed to Mocha::API.

    To fix this, create the file spec/support/mocha.rb fill it with:

    module Mocha
    module API
    def setup_mocks_for_rspec
    mocha_setup
    end
    def verify_mocks_for_rspec
    mocha_verify
    end
    def teardown_mocks_for_rspec
    mocha_teardown
    end
    end
    end

    Then tell RSpec how to access the mocking API inside the

    Spec::Runner.configure do |config|
    ...
    config.mock_with Mocha::API
    ...
    end

    You should be good.