small medium large xlarge

06 Oct 2010, 05:44
Andrew Porter (1 post)

I’m following along in the book (great stuff, by the way). In section 7.2 on page 117 (B7.0), once I add the @lets stub a class@ test in test/unit/project_test.rb, it breaks the first test, @should be able to retrieve projects based on day@. The error message is as follows:

  1) Failure:
test_should_be_able_to_retrieve_projects_based_on_day(ProjectTest) [test/unit/project_test.rb:8]:
<["2009-01-06", "2009-01-07"]> expected but was

If I remove the @lets stub a class@ test, none of the other tests fail. I think it may have something to do with overriding the find method, but I didn’t think stubbing a method in one test would affect other tests.

I posted a gist of my project_test.rb file here. My environment includes the following:

  • rvm 1.0.11
  • ruby 1.9.2-p0
  • rails 3.0.0
  • factory_girl 1.3.2
  • mocha 0.9.8
  • sqlite3-ruby 1.3.1

I placed @require ‘mocha’@ in test/test_helper.rb.

Has anyone else experienced this problem?

26 Dec 2010, 00:16
Artin Safari (1 post)

Yes, I am experiencing the same problem. Were you able to resolve this? It seems to me like stubs or mocks are global when declared in an individual test.

28 Dec 2010, 17:18
Enrique Temes (1 post)

You need to update your Gemfile so that mocha is not required automatically. Update the mocha gem declaration so that it looks like this:

gem ‘mocha’, :require => false