【发布时间】:2020-05-24 01:26:03
【问题描述】:
我需要测试像 "/users.json?search=" + "[params]" 之类的 url:
it "renders a successful response" do
get :show, params: "/users.json?search=c"
expect(response).to have_http_status(200)
expect(response).to be_successful
end
我的控制器喜欢
def index
@users = User.search(params[:search]).limit(10)
respond_to do |f|
f.json { render json: @users }
end
end
当我运行测试时出现这个错误:
Failure/Error: before { get :show, params: "/users.json?search=unk" }
NoMethodError:
undefined method `symbolize_keys' for "/users.json?search=unk":String
```
【问题讨论】:
标签: ruby-on-rails json testing rspec rspec-rails