考虑这个例子:
describe UsersController do
it "works for something" do
# some other code
get :show, {facebook_id: 1000000000}
# some other code
put :update, {facebook_id: 1000000000, birthday: "2001-01-01"}
# some other code
get :show, {facebook_id: 1000000000}
# some other code
end
it "works for another thing" do
# some other code
get :show, {facebook_id: 1000000000}
# some other code
end
end
如何干掉{facebook_id: 1000000000}
以便我可以简单地写get :show
,put :update, {birthday: "2001-01-01"}
等?
答案 0 :(得分:1)
怎么样
def options(*args)
_options = args.extract_options!
_options.merge({facebook_id: 1000000000})
end
然后
get :show, options
put :update, options(birthday: "2001-01-01")
答案 1 :(得分:0)
你的控制器对facebook_id做了什么?当你没有测试时,我会存在需要facebook_id的方法,就像我在这里建议RSpec Request - How to set http authorization header for all requests