[rspec-users] DB-less rspec_on_rails

Tobias Grimm listaccount at e-tobi.net
Fri Dec 29 03:22:22 EST 2006


Hello!

aslak hellesoy wrote:
> How do I reproduce this erratic behaviour? Detailed steps please.
>   

Ok - I figured out, that I even get this problem without using rake:

- Create a new rails app and install the rspec on rails plugin (I used
version 0.7.5)
- Create a new model test.rb, that not derives from AR:

app/models/test.rb:

  class Test
  end

- Create a spec for this model:

  spec/models/test_spec.rb:
  require File.dirname(__FILE__) + '/../spec_helper'

  context "A simple test" do
    specify "should not need a database" do
      1.should.be == 1
    end
  end

Now run `ruby spec/models/test_spec.rb`. At this point I get:

  Mysql::Error in 'A simple test should not need a database'
  Access denied for user 'root'@'localhost' (using password: NO)
  spec/models/test_spec.rb:3:

Now go into spec/models and run `ruby test_spec.rb`. This one seems to
work, which makes it even more strange:

  .
 
  Finished in 0.001245 seconds

  1 specification, 0 failures


Test::Unit works fine, after replacing test_helper with:

   ENV["RAILS_ENV"] = "test"
   require File.expand_path(File.dirname(__FILE__) +
"/../config/environment")
   require 'application'
   require 'test/unit'
   require 'action_controller/test_process'
   require 'action_web_service/test_invoke'
   require 'breakpoint'

I tried the same with spec_helper.rb, but it didn't work.

What is different between running a spec from the application root and
from the spec directory?

For the moment I simply use a sqlite3 memory database to get RSpec
working with my DB-less application. But I would prefer to not have this
additional "build-time" -dependency.

bye,

Tobias



More information about the rspec-users mailing list