Ashley Moran
2007-Oct-24 22:49 UTC
[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
Al Chou
2007-Oct-25 02:08 UTC
[rspec-users] 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 Moran <work at ashleymoran.me.uk> To: rspec-users <rspec-users at rubyforge.org> 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 rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071024/96badb8e/attachment.html
Ashley Moran
2007-Oct-25 19:01 UTC
[rspec-users] How do you specify a rubygem is being required?
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
Al Chou
2007-Oct-25 19:13 UTC
[rspec-users] How do you specify a rubygem is being required?
Glad that was helpful! Al ----- Original Message ---- From: Ashley Moran <work at ashleymoran.me.uk> To: rspec-users <rspec-users at rubyforge.org> Sent: Thursday, October 25, 2007 12:01:11 PM Subject: Re: [rspec-users] How do you specify a rubygem is being required? 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 _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071025/12bc30b2/attachment.html