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

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