Rake spec loads development environment

Hi,

I am new to rspec and started implementing it on my project yesterday.
I have followed the instructions and installed rspec gem and rspec
plugin into my project. I created couple of sample stories and tried
running the specs using spec command which worked fine, but when I
started using rake spec command it is loading development environment
instead of test environment. I tried to putting some STDOUT’s in
spec_helper.rb but it seems that this file is never interpreted. Am I
missing something? Please help, Thanks in advance.

-SatishG

On Aug 19, 2008, at 1:05 PM, Satish G. [email protected] wrote:

Hi,

I am new to rspec and started implementing it on my project
yesterday.
I have followed the instructions

What instructions?

and installed rspec gem and rspec
plugin into my project. I created couple of sample stories and tried
running the specs using spec command which worked fine, but when I
started using rake spec command it is loading development environment
instead of test environment. I tried to putting some STDOUT’s in
spec_helper.rb but it seems that this file is never interpreted.

Are you including it from your spec files?

Hi David,

Most of my knowledge came from peepcode rspec screencast and the
following link.
http://rspec.rubyforge.org/documentation/rails/install.html

Here are the steps I have done to get going.

  1. Installed rspec gem
  2. Installed rspec plugin in my project
  3. created a test_spec.rb file which have sample stories
  4. ruby script/generate rspec
  5. rake spec

I have one initializer file for oracle_driver in initializers
directory which is set to not load in test environment. when I run rake
spec command this initializer is invoked and I see that the environment
is set to development but not test.

To answer your second questions, I am not including it from my spec
files.

BTW I am using rpsec 1.1.4 and rails 2.1.0. Sorry for not being
elaborate in my prev post.

Thanks,
SatishG.

David C. wrote:

On Aug 19, 2008, at 1:05 PM, Satish G. [email protected] wrote:

Hi,

I am new to rspec and started implementing it on my project
yesterday.
I have followed the instructions

What instructions?

and installed rspec gem and rspec
plugin into my project. I created couple of sample stories and tried
running the specs using spec command which worked fine, but when I
started using rake spec command it is loading development environment
instead of test environment. I tried to putting some STDOUT’s in
spec_helper.rb but it seems that this file is never interpreted.

Are you including it from your spec files?

On Aug 19, 2008, at 2:05 PM, Satish G. wrote:

missing something? Please help, Thanks in advance.

-SatishG

Posted via http://www.ruby-forum.com/.


rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

iirc, it looks at the development environment to prepare the db
schema, but still runs the specs in test. Is that what you’re seeing?

Yes I think that is what’s happening in my case. is this how it is
supposed to work? or can we have rspec ignore the step to look at
development environment. thanks so much for all your help.

iirc, it looks at the development environment to prepare the db
schema, but still runs the specs in test. Is that what you’re seeing?

On Aug 19, 2008, at 4:32 PM, Satish G. wrote:

Yes I think that is what’s happening in my case. is this how it is
supposed to work? or can we have rspec ignore the step to look at
development environment. thanks so much for all your help.

you’ll notice that vendor/plugins/rspec-rails/rspec.rake contains the
line

spec_prereq = File.exist?(File.join(RAILS_ROOT, ‘config’,
‘database.yml’)) ? “db:test:prepare” : :noop

which you could change or comment out

On Tue, Aug 19, 2008 at 3:08 PM, Satish G. [email protected]
wrote:

  1. created a test_spec.rb file which have sample stories
  2. ruby script/generate rspec
  3. rake spec

I have one initializer file for oracle_driver in initializers
directory which is set to not load in test environment. when I run rake
spec command this initializer is invoked and I see that the environment
is set to development but not test.

To answer your second questions, I am not including it from my spec
files.

I’d recommend doing so if you want the spec_helper.rb file to be
loaded. It will set the environment for you correctly.

On Tue, Aug 19, 2008 at 2:08 PM, Jonathan L.
[email protected]wrote:

you’ll notice that vendor/plugins/rspec-rails/rspec.rake contains the line

spec_prereq = File.exist?(File.join(RAILS_ROOT, ‘config’, ‘database.yml’))
? “db:test:prepare” : :noop

which you could change or comment out

You’d have to remember to run your migrations against the test db as
well as
the dev db.

///ark

Awesome. Thanks guys. Appreciate your help.

Mark W. wrote:

On Tue, Aug 19, 2008 at 2:08 PM, Jonathan L.
[email protected]wrote:

you’ll notice that vendor/plugins/rspec-rails/rspec.rake contains the line

spec_prereq = File.exist?(File.join(RAILS_ROOT, ‘config’, ‘database.yml’))
? “db:test:prepare” : :noop

which you could change or comment out

You’d have to remember to run your migrations against the test db as
well as
the dev db.

///ark

http://rspec.rubyforge.org/documentation/rails/install.html

I sure wish someone would take that page down - it’s caused me more than
my
share of grief.

///ark

Done

I know this thread is long dead, but I’m finding that I have the same
problem. ‘rake spec:modles’ loads the development environment and
clobbers my development database. I have to run set RAILS_ENV=test in
order for the tests to run correctly.

Commenting out that rake task line does not solve the problem. WHat’s
going on? Do I really have to remember to always set the environment to
test? Shouldn’t that be the default?

On Aug 19, 2008, at 5:08 PM, Jonathan L. wrote:

spec_prereq = File.exist?(File.join(RAILS_ROOT, ‘config’,
‘database.yml’)) ? “db:test:prepare” : :noop

which you could change or comment out

note, I ran into this wanting to run through my specs on my
production server, which doesnt have a development environment but
does have a production one. So instead I run (via a cap deploy:spec
task i wrote)

 rake spec RAILS_ENV=production

that way the db:test:prepare uses the production db rather than the
development one

On Tue, Aug 19, 2008 at 2:35 PM, Jonathan L.
[email protected]wrote:

rake spec RAILS_ENV=production

that way the db:test:prepare uses the production db rather than the
development one

I know this thread is long dead but … you must be joking.

///ark

On Wed, May 13, 2009 at 9:59 PM, Matthew I. [email protected]
wrote:

I know this thread is long dead, but I’m finding that I have the same
problem. ‘rake spec:modles’ loads the development environment and
clobbers my development database. I have to run set RAILS_ENV=test in
order for the tests to run correctly.

Commenting out that rake task line does not solve the problem.

What rake task line in what file?

Mark W. wrote in post #816031:

On Tue, Aug 19, 2008 at 2:35 PM, Jonathan L.
[email protected]wrote:

rake spec RAILS_ENV=production

that way the db:test:prepare uses the production db rather than the
development one

I know this thread is long dead but … you must be joking.

///ark

I went though same experience today with my recently setup ruby 1.9,
rails 3.0, and rspec 2. “$ rake spec” loaded development environment,
hitting development db and pumping logs at log/development.log. This
caused lot of confusion in my testing (As I run spec within RubyMine at
the same time).

I found that there is “RAILS_ENV=development” in my bash environment.
Once I remove that, everything works as expected. rspec loads test
environment, test db, and logging at log/test.log.

One thing I noticed is when I have RAILS_ENV=development, even if I
tried “$ rake spec RAILS_ENV=test”, it actually hit development
environment. I thought argument override shell env setting. Am I wrong
or is it rspec issue?

This thread has been dead for awhile, but I’m having the same issue. I
don’t have a bash variable set. I’m also having this issue with
Cucumber. It always runs in development mode.

If I put “p Rails.env” in spec_helper.rb:8 (after spec_helper already
declares ENV[“RAILS_ENV”] ||= “test”) and run “rake spec” it outputs
“development” every time. If I run “spec spec/*/**” it outputs “test”
like it should.

My setup:

Rails 2.3.9
Rake 0.8.7
Bundler 1.0.10
Rspec-rails 1.3.3
Rspec 1.3.1