Topic: Creating stubs for any_instance affect other tests


I'm a rails and BDD newbie, while working on some samples I had the following issue using Mocha gem

I had a passing test as follows

  test "should create project" do
    assert_difference('Project.count') do
      post :create, :project => @project.attributes

    assert_redirected_to project_path(assigns(:project))

when I added the following test
  test "fail create gracefully" do
      assert_no_difference('Project.count') do
          post :create, :project => {:name => 'Project Runaway'}     

The first test failed

It looks like that the object stub affected the behavior of other tests
I feel it is a silly question but I really appreciate if someone would help to understand how to overcome this issue

Last edited by jwahba (2010-10-27 07:45:27)

Re: Creating stubs for any_instance affect other tests

That's how it works when using RSpec for mocking. Changing to mocha (in spec_helper) makes it work like you expect, ie pulling down the mocks after each spec.