Comments (8)
我能想到最简单的方法就是 before(:each) 的时候 chdir 到测试的目录,after(:each)的时候 chdir 回来,但是不知道有没有其他的副作用
from kano.
Taxon model 中的一些 validation,会用到 Taxon::Config 提供的方法,但是这里用 Rspec 提供的 Mock 机制我实验了一下并不起作用,因为 Rspec mock 都是在测试代码中显示调用才会起作用,而对于代码内部(例如 Taxon 的 methods 内部去调用 Taxon::Config)调用时,mock 机制并不起作用。
@hymRedemption 应该不是 mock 不起作用的原因吧,在一个 test case 中应用 allow
/ receive
/ and_return
以后,所有相关的调用应该都会生效,不论是否在测试代码中,比如你说的 Taxon
的类方法,内部调用了 Taxon::Config
,只要在当前 test case 中调用之前有过 mock,就会生效。
from kano.
当 Taxon.update(certified_statuses: :a) 的时候,会抛出异常(因为 validates :certified_statuses :inclusion { in: Taxon::Config.certified_statuses }),其说明 certified_statuses 只能是在 config/taxon.yml 中我们定义的文件中的那些取值。
关于你后面举得的这个例子,应该还是提前调用的问题,validations 已经把 mock 之前的状态读入进去了。
from kano.
解决这个 validations 的问题我倒是没有遇到过,可能需要禁用原有的 validations,然后再重新创建你需要的。
不过我觉得关于测试 Taxon Config 方面,应该还是不需要专门创建相关的文件,因为文件读取这个系统调用本身是没有任何问题,并不需要测试。mock 也仅仅需要一行代码,并不复杂,甚至要更简单一些,而且不借助外界系统调用运行效率也会高很多。
from kano.
另外想到:关于你提到的
代码内部(例如 Taxon 的 methods 内部去调用 Taxon::Config)调用时,mock 机制并不起作用。
会不会是因为没有考虑 reset 相关的类变量?因为在 taxons_config
以外的方法都使用了 ||=
操作符,所以可以在原来的类中建立一个 .reset_taxons_config
的方法,把所有的 @@variable
设置为 nil
。
from kano.
from kano.
@nobrick 我试试看看
from kano.
OK~
On Feb 1, 2016, at 7:27 PM, HS [email protected] wrote:
@nobrick
我试试看看—
Reply to this email directly or view it on GitHub
.
from kano.
Related Issues (20)
- 后台的订单详情未显示维修内容 HOT 1
- 重发订单
- 下单页面增加物件数量和对应名称(件) HOT 2
- 下单页面输入框改进 HOT 2
- 下单页面错误提示改进 HOT 1
- 订单流转功能 HOT 1
- 下单页面支持上传图片 HOT 1
- 师傅头像支持 HOT 1
- 后台订单详情页面的师傅链接指向错误 HOT 1
- 前端并发问题 HOT 1
- 简化下单界面
- 提现申请限制问题 HOT 10
- Rename .css.scss to .scss
- 财会信息管理的链接跳转 HOT 1
- 师傅端提现历史记录
- 取消现金支付,增加师傅代用户微信支付
- 15分钟无人接单slack反馈
- 后台支持取消订单
- 订单两周后自动作废
- 170防隐私电话
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kano.