测试 如何忽略 Fixture 数据

luffycn · May 09, 2012 · Last by heliang7 replied at June 05, 2012 · 2549 hits

cd test 目录下 运行 ruby -Itest functional/post.rb

post.rb assert_difference('Post.count') do post(:create) end

我想在执行这行代码时 post(:create) 可以自己指定数据,比如用 post(:create, :post => {:title => 'title1', :content => 'content1'})

但是一直无法自己指定,默认会调用 Fixture 数据

而且 post 如果有一些 callback,比如 after_save,也无法在测试脚本执行时跟着执行

不知道你们是怎么解决这些问题的?

你必须在 create action 里面接受 params[:post] 参数才可以啊。

You need to Sign in before reply, if you don't have an account, please Sign up first.