<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>David Chelimsky: rspec 0.9 - plug in any mock framework</title>
    <link>http://blog.davidchelimsky.net/articles/2007/04/27/rspec-0-9-plug-in-any-mock-framework</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>on software in process and practice</description>
    <item>
      <title>rspec 0.9 - plug in any mock framework</title>
      <description>&lt;p&gt;RSpec-0.9 lets you work with the mock framework of your choice. It not only ships with adapters for mocha and flexmock, but it also provides you an easy entry point to plug in another framework of your choosing &amp;#8211; or even your creation.&lt;/p&gt;


	&lt;h3&gt;rspec, mocha or flexmock&lt;/h3&gt;


	&lt;p&gt;RSpec is the default mock framework, so if you want to use RSpec&amp;#8217;s mock framework you need not set anything up. If you want to use mocha or flexmock, just say&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;Spec::Runner.configure do |config|
  config.mock_with :mocha
end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;or&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;Spec::Runner.configure do |config|
  config.mock_with :flexmock
end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Of course, if you&amp;#8217;re using mocha or flexmock you have to install those gems, but you don&amp;#8217;t need to require them because that is taken care of for you implicitly.&lt;/p&gt;


	&lt;h3&gt;Other mocking frameworks&lt;/h3&gt;


	&lt;p&gt;If you have another mocking framework that you like to use, or one that you are developing yourself, you&amp;#8217;ll need to create an adapter for it like this:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;module MyMockFrameworkAdapter
  def setup_mocks_for_rspec
    # Called before any #before(:each) blocks - use
    # this to set up any necessary hooks to your system.
  end
  def verify_mocks_for_rspec
    # Called after any #after(:each) blocks.
    # NOTE - your mocks should fail by raising an error.
  end
  def teardown_mocks_for_rspec
    # Called after verify_mocks_for_rspec. This
    # is guaranteed to run, even if there
    # are failures.
  end
end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;And then include it using the new configuration system:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;Spec::Runner.configure do |config|
  config.mock_with MyMockFrameworkAdapter
end
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Fri, 27 Apr 2007 00:31:24 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:cf8d65d8-faf5-4cc0-9221-e142bc134688</guid>
      <author>David</author>
      <link>http://blog.davidchelimsky.net/articles/2007/04/27/rspec-0-9-plug-in-any-mock-framework</link>
      <category>rspec</category>
      <category>mocks</category>
      <category>mocha</category>
      <category>flexmock</category>
    </item>
  </channel>
</rss>
