Forum: RSpec App can't start on production server due to RSpec missing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fernando P. (Guest)
on 2009-01-16 21:38
Hi,

I just run in the following problem when starting a Rails app on my
production server:

  You have rspec rake tasks installed in
  /home/thomas/rails_apps/video_on_demand/lib/tasks/rspec.rake,
  but rspec can not be found in vendor/gems, vendor/plugins or on the
system.


Obviously I don't want Rails to load anything related to rspec, how can
I tell Rails that it should not care about RSpec on the production
environment?

A quick fix is to install rspec and rspec-rails gems on production
server, but I don't get why the app wants them installed.
Scott T. (Guest)
on 2009-01-16 23:04
(Received via mailing list)
On Jan 16, 2009, at 2:38 PM, Fernando P. wrote:

>
> Obviously I don't want Rails to load anything related to rspec, how
> can
> I tell Rails that it should not care about RSpec on the production
> environment?
>
> A quick fix is to install rspec and rspec-rails gems on production
> server, but I don't get why the app wants them installed.

I would delete that rake task file (lib/rspec.rake) if you don't have
rspec installed.

Scott
Fernando P. (Guest)
on 2009-01-16 23:15
>
> I would delete that rake task file (lib/rspec.rake) if you don't have
> rspec installed.
>
> Scott

I run rspec on my dev machine, but obviously not on my production
machine, what would be the nicest way to handle such scenario? At the
top of rspec.rake I could add a check on the environment, I could also
not add this file to my repository but I could forget about this file in
future clones of my repo, etc.

How did you solve this problem?
David C. (Guest)
on 2009-01-17 00:05
(Received via mailing list)
On Fri, Jan 16, 2009 at 1:38 PM, Fernando P. 
<removed_email_address@domain.invalid>
wrote:
>
> Obviously I don't want Rails to load anything related to rspec, how can
> I tell Rails that it should not care about RSpec on the production
> environment?
>
> A quick fix is to install rspec and rspec-rails gems on production
> server, but I don't get why the app wants them installed.

This is a tricky business.

We put that in there in response to a user who works on a team. One
team member had pulled code and tried t run specs and got an error he
didn't understand, so this is intended to help that developer know he
needs to install rspec.

So now this creates a new problem for you, which is that this means
you have to have rspec installed everywhere you want to run rake
tasks.

I'm open to suggestions for how to best solve for both cases if you have
any.

Cheers,
David
Aslak H. (Guest)
on 2009-01-17 00:17
(Received via mailing list)
On Fri, Jan 16, 2009 at 10:05 PM, David C.
<removed_email_address@domain.invalid>wrote:

> > system.
>
> any.
>

Make it print the message to STDERR instead of raising an error? Plus
add a
blurb like "You can ignore this warning if you didn't intend to run
specs"

Aslak
Stephen E. (Guest)
on 2009-01-17 00:45
(Received via mailing list)
On Fri, Jan 16, 2009 at 2:38 PM, Fernando P. 
<removed_email_address@domain.invalid>
wrote:
>
> A quick fix is to install rspec and rspec-rails gems on production
> server, but I don't get why the app wants them installed.

Because every Rake file in /lib gets loaded when you run Rake.  That's
your dependency problem; not the app itself.


--
Have Fun,
   Steve E. (removed_email_address@domain.invalid)
   ESCAPE POD - The Science Fiction Podcast Magazine
   http://www.escapepod.org
Mark W. (Guest)
on 2009-01-17 01:19
(Received via mailing list)
On Fri, Jan 16, 2009 at 1:15 PM, Fernando P.
<removed_email_address@domain.invalid>wrote:

>
> I run rspec on my dev machine, but obviously not on my production
> machine, what would be the nicest way to handle such scenario? At the
> top of rspec.rake I could add a check on the environment


That would get my vote.

///ark
David C. (Guest)
on 2009-01-17 01:43
(Received via mailing list)
On Fri, Jan 16, 2009 at 5:06 PM, Mark W. <removed_email_address@domain.invalid> 
wrote:
> On Fri, Jan 16, 2009 at 1:15 PM, Fernando P. <removed_email_address@domain.invalid>
> wrote:
>>
>> I run rspec on my dev machine, but obviously not on my production
>> machine, what would be the nicest way to handle such scenario? At the
>> top of rspec.rake I could add a check on the environment
>
> That would get my vote.

Unless I"m missing something, that would require this on the CLI:

  RAILS_ENV=test rake spec

Therefore, this would not get my vote :)
David C. (Guest)
on 2009-01-17 01:52
(Received via mailing list)
On Fri, Jan 16, 2009 at 4:15 PM, aslak hellesoy
<removed_email_address@domain.invalid> wrote:
>> > production server:
>> >
>> So now this creates a new problem for you, which is that this means
>> you have to have rspec installed everywhere you want to run rake
>> tasks.
>>
>> I'm open to suggestions for how to best solve for both cases if you have
>> any.
>
> Make it print the message to STDERR instead of raising an error? Plus add a
> blurb like "You can ignore this warning if you didn't intend to run specs"

Sounds good- any objections?
Pat M. (Guest)
on 2009-01-17 02:32
(Received via mailing list)
On Fri, Jan 16, 2009 at 2:58 PM, David C. <removed_email_address@domain.invalid>
wrote:
>>> >
>>> > I tell Rails that it should not care about RSpec on the production
>>> needs to install rspec.
>
> Sounds good- any objections?

That's what I do in all of my projects...require 'spec', rescue
LoadError and print a helpful message.

Pat
Mark W. (Guest)
on 2009-01-17 02:54
(Received via mailing list)
On Fri, Jan 16, 2009 at 3:19 PM, David C.
<removed_email_address@domain.invalid>wrote:

>
> Therefore, this would not get my vote :)
>

Because the rake tasks get loaded before the spec task has a chance to
set
RAILS_ENV. But the rakefile wouldn't check RAILS_ENV=test, but
RAILS_ENV=production (or staging). And wouldn't it be set that way
before
rake loads its files? (I'm gonna learn something here, whether I want to
or
not!)

///ark
Scott T. (Guest)
on 2009-01-17 03:04
(Received via mailing list)
On Jan 16, 2009, at 4:15 PM, Fernando P. wrote:

> file in
> future clones of my repo, etc.

I'd most certainly add it to the repos in the form of a plugin.

What exactly are you worried about?  The memory overhead of loading
the rspec code? (I'm not sure exactly how rails works here - does it
simply rspec/lib/ to the $LOAD_PATH?  Does it require lib/spec.rb?)

Obviously if your production code is explicitly calling rspec, you've
got bigger problems.

Scott
Andrew P. (Guest)
on 2009-01-17 07:53
(Received via mailing list)
If your using capistrano you could delete this file when deploying.

2009/1/16 Scott T. <removed_email_address@domain.invalid>
Fernando P. (Guest)
on 2009-01-17 12:22
> Make it print the message to STDERR instead of raising an error? Plus
> add a
> blurb like "You can ignore this warning if you didn't intend to run
> specs"
>
> Aslak

I like that too, +1 for me.

> Obviously if your production code is explicitly calling rspec, you've
> got bigger problems.
As Stephen said, it's because rspec.rake located under the lib folder is
trying to load rspec (gem or plugin) without looking at the rails
environment.
Jonathan L. (Guest)
on 2009-01-17 16:40
(Received via mailing list)
On Jan 16, 2009, at 4:15 PM, Fernando P. wrote:

> I run rspec on my dev machine, but obviously not on my production
> machine, what would be the nicest way to handle such scenario? At the

Actually, I run specs on my production machine,
   cap deploy:spec
:)
since its a different platform from my development,
especially on point releases of the app
Mark W. (Guest)
on 2009-01-17 22:00
(Received via mailing list)
On Sat, Jan 17, 2009 at 5:42 AM, Jonathan L.
<removed_email_address@domain.invalid>wrote:

> since its a different platform from my development,
> especially on point releases of the app


Umm, how do you handle that whole rake db:test:prepare thing?

///ark
Jonathan L. (Guest)
on 2009-01-18 17:26
(Received via mailing list)
On Jan 17, 2009, at 2:14 PM, Mark W. wrote:

> :)
> since its a different platform from my development,
> especially on point releases of the app
>
> Umm, how do you handle that whole rake db:test:prepare thing?
>
> ///ark
> _______________________________________________
> rspec-users mailing list
> removed_email_address@domain.invalid
> http://rubyforge.org/mailman/listinfo/rspec-users

I copy the schema from production, the server doesnt have a
development database.
also, my opts default to --format html so i can browse to the results
 From my Capfile

   task :spec, :roles => :app do
     run "cd #{current_path} && rake db:test:prepare
RAILS_ENV=production" # copy schema from production rather than
development
     run "cd #{current_path} && rake spec RAILS_ENV=production
 >public/private/specs.html"
   end
Scott T. (Guest)
on 2009-01-19 02:11
(Received via mailing list)
Andrew P. wrote:
> If your using capistrano you could delete this file when deploying.

Or just not version control it:

git rm -rf --cached lib/tasks/rspec.rake
echo "lib/tasks/rspec.rake" >> .gitignore

Scott
Fernando P. (Guest)
on 2009-04-13 20:33
>> A quick fix is to install rspec and rspec-rails gems on production
>> server, but I don't get why the app wants them installed.
>
> This is a tricky business.
>
> We put that in there in response to a user who works on a team. One
> team member had pulled code and tried t run specs and got an error he
> didn't understand, so this is intended to help that developer know he
> needs to install rspec.
>
> So now this creates a new problem for you, which is that this means
> you have to have rspec installed everywhere you want to run rake
> tasks.

I haven't followed the ML latety, but it seems that now I don't have to
install rspec and its friends on the production server anymore.
This topic is locked and can not be replied to.