Forum: RSpec [RSpec] Setting a gem dep on rspec-rails

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.
49de4cd2f26705785cbef2b15a9df7aa?d=identicon&s=25 Nick Hoffman (nickh)
on 2009-02-07 18:32
(Received via mailing list)
For a while now, I've had the following in config/environment.rb :

config.gem 'haml'
config.gem 'rspec', :lib => 'spec'
config.gem 'rspec-rails', :lib => 'spec/rails'

I just tried running the Rails console in production mode, and this
warning occured:

irb: warn: can't alias context from irb_context.

After some googling, I learned that the gem deps on rspec and rspec-
rails are causing that warning. When I remove those two gem deps from
environment.rb , the warning disappears.

With that said, I'm wondering what the accepted way to setup gem
dependencies on rspec and rspec-rails is. Should one not bother?
Should the "config.gem" lines go in config/environments/test.rb ?

Thanks,
Nick
49de4cd2f26705785cbef2b15a9df7aa?d=identicon&s=25 Nick Hoffman (nickh)
on 2009-02-07 19:42
(Received via mailing list)
On 07/02/2009, at 12:30 PM, Nick Hoffman wrote:
>
> After some googling, I learned that the gem deps on rspec and rspec-
> rails are causing that warning. When I remove those two gem deps
> from environment.rb , the warning disappears.
>
> With that said, I'm wondering what the accepted way to setup gem
> dependencies on rspec and rspec-rails is. Should one not bother?
> Should the "config.gem" lines go in config/environments/test.rb ?
>
> Thanks,
> Nick

I should've tried the second solution I proposed before sending that
email. If you put the gem dependencies in config/environments/test.rb
and then enter the Rails console in test mode (script/console test),
the warning occurs.
-Nick
F86901feca747abbb5c6c020362ef2e7?d=identicon&s=25 Zach Dennis (zdennis)
on 2009-02-07 19:43
(Received via mailing list)
On Sat, Feb 7, 2009 at 12:30 PM, Nick Hoffman <nick@deadorange.com>
wrote:
>
> After some googling, I learned that the gem deps on rspec and rspec-rails
> are causing that warning. When I remove those two gem deps from
> environment.rb , the warning disappears.
>
> With that said, I'm wondering what the accepted way to setup gem
> dependencies on rspec and rspec-rails is. Should one not bother? Should the
> "config.gem" lines go in config/environments/test.rb ?

Rails config.gem has never seemed to work 100% with libraries that
shouldn't be loaded in all environments. With that said, I point you
to the wiki:

   http://wiki.github.com/dchelimsky/rspec/rails-with...

If you try to use the rake tasks to find gem dependencies for your
app, it will not list them by default unless you set RAILS_ENV=test.

ie: RAILS_ENV=test rake gems

IMO, running "rake gems" should tell you the configured gems for
*everything*, and it should say what environments a particular gem is
required. It kind of defeats the purpose if I have to be so specific
when asking the "rake gems" task what gems the application relies on.

I've haven't successfully gotten all of the rake tasks for gems to
work 100% in the test environment. For the most part the "gems" and
"gems:unpack" do function.

You can successfully bypass cofnig.gem and the associated rake tasks
by using "gem unpack".

ie: cd vendor/gems ; gem unpack rspec ; gem unpack rspec-rails

Personally, I put rspec and rspec-rails in vendor/plugins, even if
it's just using "gem unpack" to put them there. It makes easier to
upgrade to recent changes in rspec/rspec-rails in order to try out bug
fixes, or take advantage of new features.

Basically you've got options. I'd recommend gem unpacking into
vendor/gems or vendor/plugins. I don't see an advantage at this point
of using config.gem since it doesn't work 100% of the time, and it
doesn't work necessarily as it should (of course IMO),
--
Zach Dennis
http://www.continuousthinking.com
http://www.mutuallyhuman.com
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2009-02-07 20:02
(Received via mailing list)
On Sat, Feb 7, 2009 at 9:30 AM, Nick Hoffman <nick@deadorange.com>
wrote:
> With that said, I'm wondering what the accepted way to setup gem
> dependencies on rspec and rspec-rails is. Should one not bother? Should the
> "config.gem" lines go in config/environments/test.rb ?

I don't bother to use config.gem with rspec, but if you do then yes it
should go in test.rb

Pat
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-02-07 20:18
(Received via mailing list)
On Sat, Feb 7, 2009 at 12:27 PM, Pat Maddox <pergesu@gmail.com> wrote:
> On Sat, Feb 7, 2009 at 9:30 AM, Nick Hoffman <nick@deadorange.com> wrote:
>> With that said, I'm wondering what the accepted way to setup gem
>> dependencies on rspec and rspec-rails is. Should one not bother? Should the
>> "config.gem" lines go in config/environments/test.rb ?
>
> I don't bother to use config.gem with rspec, but if you do then yes it
> should go in test.rb

I don't either, but I'd like to get it working for ppl who want to do
it.

If anybody w/ config.gem fu wants to help, that'd be awesome.
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2009-02-08 23:42
(Received via mailing list)
On 7 Feb 2009, at 19:02, David Chelimsky wrote:

>> should go in test.rb
>
> I don't either, but I'd like to get it working for ppl who want to
> do it.
>
> If anybody w/ config.gem fu wants to help, that'd be awesome.

I think this kinda works for us, but I had a couple of issues. One is
the problem with rake files, which will depend on RSpec being visible
to rake when it loads (which will ignore your vendor/gems folder). I
fixed that by putting the rake file in a huge begin / rescue / end
block so when the require 'spec' fails it doesn't load the rest of the
rake tasks. Ugly but functional.

The other issue was to do with a line in spec/rails which clobbers the
value of RAILS_ENV to be 'test' whatever it was previously set to. We
use an unconventional 'features' environment for running features
(means I can run cukes at the same time as specs) but this was going
hay-wire. I think David has put a patch for this into rspec-rails'
head but I don't know if it's made it's way into a gem yet.

So yeah, executive summary: What Pat said.


Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com
49de4cd2f26705785cbef2b15a9df7aa?d=identicon&s=25 Nick Hoffman (nickh)
on 2009-02-09 15:44
(Received via mailing list)
On 08/02/2009, at 4:39 PM, Matt Wynne wrote:
>>>
> is the problem with rake files, which will depend on RSpec being
> rspec-rails' head but I don't know if it's made it's way into a gem
> yet.
>
> So yeah, executive summary: What Pat said.
>
>
> Matt Wynne

I've decided to just freeze the rspec and rspec-rails gems into vendor/
gems/ . It makes life easy when moving the app between hosts, and
means that I don't have to worry about config.gem shenanigans.

Thanks for all of your suggestions, guys. Much appreciated!
This topic is locked and can not be replied to.