我正在编写我的第一个RSpec测试并运行到一点墙。这就是我所拥有的。
require 'spec_helper'
feature "submit a search request" do
scenario "submits a search to the correct path" do
visit root_path
within("#search-form") do
fill_in 'search', :with => 'mysearch'
end
click_button 'search-submit'
current_url.should == search_url(:utf8 => '✓', :search => 'mysearch')
end
end
params按字母顺序返回。如果我更改名称:搜索以'u'之后的任何字母开头,它就会通过。这是错误消息
1) the map search submits a search request to the map controller
Failure/Error: current_url.should == search_url(:utf8=> '✓', :search => 'mysearch')
expected: "http://www.example.com/map?search=mysearch&utf8=%E2%9C%93"
got: "http://www.example.com/map?utf8=%E2%9C%93&search=mysearch"
答案 0 :(得分:0)
您可以单独比较每个查询参数。
要从网址获取参数,请执行以下操作:
url = "http://www.example.com/map?search=mysearch&utf8=%E2%9C%93"
query = URI.parse(url).query # => "search=mysearch&utf8=%E2%9C%93"
CGI::parse query # => {"search"=>["mysearch"], "utf8"=>["✓"]}