This is a rehash of a question I posed at: http://stackoverflow.com/questions/9952317/isolati... The basic question: If I have a FoosController and a Foo model, can I run FoosController rspec tests without creating the foos database table? I haven't found a good way to avoid it. Consider this simple controller: # file: app/controllers/foos_controller.rb class FoosController < ApplicationController respond_to :json def create @foo = Foo.create(params[:foo]) respond_with @foo end end In my RSpec tests, I can do @foo = mock_model("Foo") Foo.stub(:create) { @foo } post :create, :format => :json ... but that fails in the call to respond_with @foo, because ActionController calls @foo.has_errors? which in turn hits the database to look up column names. I could stub out has_errors?, but that means that I'm reaching into the internals of the system -- probably not a good idea for a test suite. If the answer to my question "can I do controller testing without creating the underlying database tables?" is 'no', then I'll accept that (with regret). But I'd rather hear that it is somehow possible. - ff
on 2012-03-31 07:11
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.