0

考虑这个例子:

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 :showput :update, {birthday: "2001-01-01"}等?

4

2 回答 2

1

怎么样

def options(*args)
  _options = args.extract_options!
  _options.merge({facebook_id: 1000000000})
end

然后

get :show, options
put :update, options(birthday: "2001-01-01")
于 2012-10-07T05:12:02.973 回答
0

你的控制器用那个 facebook_id 做什么?当你不测试时,我会存根需要 facebook_id 的方法,就像我在这里建议的那样RSpec Request - How to set http authorization header for all requests

于 2012-10-17T00:02:18.147 回答