开发者

Webmock gem in rails 3 and properly including it

开发者 https://www.devze.com 2023-02-12 11:28 出处:网络
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.

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.


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

group :test do
  gem "webmock"
end


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号