1

我正在编写我的第一个 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

参数按字母顺序返回。如果我将 :search 的名称更改为以 '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"
4

1 回答 1

0

您可以分别比较每个查询参数。

要从 url 获取参数,请执行以下操作:

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"=>["✓"]}
于 2013-06-06T00:49:41.333 回答