ruby-on-rails - Geocoder 的手动模拟

标签 ruby-on-rails ruby testing mocking rails-geocoder

如何在不使用任何 gem 的情况下模拟任何方法?

假设我可以访问像request这样的复杂对象

我该怎么做

request.location.country

返回模拟值。

我读到我可以用 gems 模拟 geocoder 结果,但我想知道一种通用的方法。

最佳答案

我是这样做的

foo = Geocoder.search('Paris, TX')
foo.first.county

我正在使用 BingAPI,为了弄清楚我可以在 foo.first 对象上访问哪些选项,我查看了 Geocoder 文档:

http://rdoc.info/github/alexreisner/geocoder/master/Geocoder/Result/Bing

关于ruby-on-rails - Geocoder 的手动模拟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16696770/

相关文章:

javascript - Uncaught ReferenceError : saveData is not defined in Google Maps

ruby-on-rails - 如何在没有 pgbackups 插件的情况下在 heroku 上进行数据库备份?

ruby-on-rails - 如何检查通过 Ruby 脚本传递的参数数量

php - Sublime Text 3 PHP 单元

testing - .NET Standard 库的单元测试项目是否应该针对 .NET Core 以外的框架?

eclipse - 在 Eclipse 中测量测试用例中的 Scala 代码覆盖率

ruby-on-rails - Ruby:为什么 'and not' 有效而 '&& !(expr)' 无效?

ruby-on-rails - 编写更简洁的 Ruby

ruby-on-rails - 自定义 Rails 中的每个循环

ruby-on-rails - Net HTTP Persistent/Keep Alive with Ruby OAuth2 gem