Re: How do you specify a rubygem is being required?

RubyGems does indeed muck with the “require” method.

I believe the current version uses the “gem” method and deprecates the
“require” method. Rails warns me about something to that effect
whenever I run script/server, anyway.

Not that I seem to have given you any real help with your spec
question…

Al

----- Original Message ----
From: Ashley M. [email protected]
To: rspec-users [email protected]
Sent: Wednesday, October 24, 2007 3:49:22 PM
Subject: [rspec-users] How do you specify a rubygem is being required?

Hi

I’m loading a gem on demand but can’t find a way to spec it.

Assuming rubygems is already loaded, I assumed the following would
work:

describe SqliteConnection, " class" do
it “should require ‘sqlite3’” do
Kernel.should_receive(:require).with(“sqlite3”)
SqliteConnection.new
end
end

Unfortunately it seems that rubygems does something funky to
“require” because it works as a standalone method, but not as a
Kernel.require call (ie Kernel.require ‘sqlite3’ => “LoadError: no
such file to load – sqlite3”). Do I need to set the expectation on
the “main” object? I have also tried this:

main_object = self

describe SqliteConnection, " class" do
it “should require ‘sqlite3’” do
main_object.should_receive(:require).with(“sqlite3”)
SqliteConnection.new
end
end

but fails with this:

Mock ‘Object’ expected :require with (“sqlite3”) but received it
with (“sqlite3/database”)

(!!!)

I’m at a loss, I hope someone can help

Thanks
Ashley


blog @ http://aviewfromafar.net/
linked-in @ http://www.linkedin.com/in/ashleymoran
currently @ home


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

On Oct 25, 2007, at 3:08 am, Al Chou wrote:

I believe the current version uses the “gem” method and deprecates
the “require” method. Rails warns me about something to that
effect whenever I run script/server, anyway.

Not that I seem to have given you any real help with your spec
question…

Actually no, you were spot on! Using gem allows me to write
Kernel.gem / Kernel.should_receive(:gem) etc.

Thanks!
Ashley


blog @ http://aviewfromafar.net/
linked-in @ http://www.linkedin.com/in/ashleymoran
currently @ home

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs