Webmock pearls on rails 3 and its correct inclusion

I'm probably doing something very simply wrong, but I'm not quite sure what it is. I am porting a rails 2 application to rails 3. This application uses webmock for a bunch of tests.

If i turn on

gem 'webmock' 

In my Gemfile, the tests pass, but when I start the server and run the application locally, clicking on the controller that should make the web call causes an error:

 WebMock::NetConnectNotAllowedError 

If I DO NOT include the line in my Gemfile, then when I run the application locally, it works fine, but the test fails:

 `require': no such file to load -- webmock (LoadError) 

When this line gets into my test_helper.rb

 require 'webmock' 

I assume that something is wrong with me, but I didn’t hit the right Google spell to shed light on it. Where did I do, am I lost my way?

Thanks.

+7
source share
2 answers

Try telling the Gemfile to only load the web layout when you are in a test environment:

 group :test do gem "webmock" end 
+11
source

In my Ruby 1.9 Rails 3 instance, I have something like the following:

 group :test do gem "mocha" gem "webmock" end group :development do gem 'ruby-debug19', :require => 'ruby-debug' end 
+1
source

All Articles