Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use "rake spec" or "rspec" (can't get "rake spec" to work)?

I am on Rails 3.2 and I am using rspec (2.11.1). When I run my test suite with "rake spec" I get failures. When I run it with "rspec" everything passes. I've seen other mentions of this problem but nothing definitive that explains what is going on and what best practices are.

If I do "rake spec" or "rake tmp:clear && rake spec" my tests fail.

If I do "rspec" or "rspec spec" or "rake db:test:prepare && rspec" my tests pass.

I thought the only difference was that rake did "db:test:prepare" but if I do that manually before running rspec my tests pass so that can't be all of the story.

After doing a bit of reading I changed my Gemfile. Previously I had it set up as per "The RSpec Book" (p328) where it described putting the rspec gem inside a "group :development, :test" block. Having read some other SO posts I removed ":development" and did a bundle. Now "rake spec" does nothing. "rspec" still works as before.

Very confused...

like image 551
starfry Avatar asked Aug 28 '12 12:08

starfry


2 Answers

Try running RAILS_ENV=test rake spec

like image 127
Mike Avatar answered Nov 03 '22 01:11

Mike


Here's what fixed it for me. I too was able to run rake spec RAILS_ENV=test I had my Gemfile like this

group :developmet do
    gem 'rspec-rails','2.9.0'
...
end
group :test do
    gem 'rspec-rails','2.9.0'
...
end

I changed it to this, making a block for test and development and putting it before the development state. I also made sure my db migrations had all made it into the test db. db:migrate RAILS_ENV=test

group :development,:test do
    gem 'rspec-rails','2.9.0'
        ...
end
group :development do
     ...
end
like image 33
Rokujolady Avatar answered Nov 03 '22 00:11

Rokujolady