Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webmock gem in rails 3 and properly including it

I'm likely 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 it's tests.

If I include

gem 'webmock'

In my Gemfile, the tests pass, but when I start the server and run the app locally, hitting a controller that should make a web call throws an error:

WebMock::NetConnectNotAllowedError

If I do NOT include the line in my Gemfile, then when I run the app locally, it works fine, but the tests error out with:

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

When this line is hit in my test_helper.rb

require 'webmock'

I'm guessing I've got something configured wrong, but I haven't hit the right google incantation to shed any light on it yet. Where I did I go astray?

Thank you.

like image 517
bikesandcode Avatar asked Feb 22 '11 18:02

bikesandcode


2 Answers

Try telling your Gemfile to only load webmock when you're in a test environment:

group :test do
  gem "webmock"
end
like image 96
Dylan Markow Avatar answered Sep 21 '22 10:09

Dylan Markow


On 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
like image 23
superluminary Avatar answered Sep 23 '22 10:09

superluminary