Capybara 发送的 Formtastic 复选框参数与实际应用程序发送的格式不同

发布于 2024-10-24 03:38:37 字数 1087 浏览 2 评论 0原文

以下格式表单复选框字段集:

<%= semantic_form_for @store do |f| %>
  <%= f.inputs do %>
    <%= f.input :services, :as => :check_boxes, :collection => Service.all %>  
  <% end -%>
<% end -%>

在使用 Capybara 的 Cucumber 测试上为 :services 发送错误参数,导致测试失败,而实际应用程序发送正确的参数,处理得很好:

#cucumber steps using the boiler_plate capybara web_steps.rb:
Given a "Mail Order" service
...(steps for rest of the form)...
When I check "Mail Order" 
And I press "Create Store"
Then I should see "Store was successfully created."
And I should see "Mail Order"

#params sent by cucumber
"store"=>{"services"=>["[\"4d8247ed7f5bfd2275000004\"]"]

#params sent by app on manual test
"store"=>{"services"=>["4d8247ed7f5bfd2275000004"]}

尽管 html 表单本身呈现相同这两种情况下的方式:

<input id="store_services_4d8247ed7f5bfd2275000004" name="store[services][]" type="checkbox" value="4d8247ed7f5bfd2275000004" />

似乎在请求参数构建期间的某个地方,当 Cucumber/Capybara 提交时,该字段的表单键/值对的解析方式有所不同。

还有其他人遇到过这个吗?

The following formtastic form checkbox field set:

<%= semantic_form_for @store do |f| %>
  <%= f.inputs do %>
    <%= f.input :services, :as => :check_boxes, :collection => Service.all %>  
  <% end -%>
<% end -%>

is sending bad params for :services on a Cucumber test using Capybara, making the test fail, while the actual app sends the correct ones, which gets processed fine:

#cucumber steps using the boiler_plate capybara web_steps.rb:
Given a "Mail Order" service
...(steps for rest of the form)...
When I check "Mail Order" 
And I press "Create Store"
Then I should see "Store was successfully created."
And I should see "Mail Order"

#params sent by cucumber
"store"=>{"services"=>["[\"4d8247ed7f5bfd2275000004\"]"]

#params sent by app on manual test
"store"=>{"services"=>["4d8247ed7f5bfd2275000004"]}

Though the html form itself is rendered the same way in both cases:

<input id="store_services_4d8247ed7f5bfd2275000004" name="store[services][]" type="checkbox" value="4d8247ed7f5bfd2275000004" />

Seems like somewhere during the request params-building, the form key/value pairs for that field get parsed differently when submitted by Cucumber/Capybara.

Anyone else come across this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弱骨蛰伏 2024-10-31 03:38:37

回答我自己的问题:

从 Capybara 的作者 Jonas Nicklas 那里得到了一个指针,它引导我到 这个机架- 尚未提交的测试补丁

现在我只是使用补丁所在的分支和分支:

gem 'rack-test', :git => 'https://github.com/econsultancy/rack-test.git', :branch => 'econsultancy-20110119'

这就可以了。我想这个补丁很快就会被合并,因为它是几个月前提交的。

Answering my own question:

Got a pointer from Capybara's author, Jonas Nicklas, that led me to this rack-test patch which hasn't been committed yet

For now I'm just using the fork and branch where the patch lives:

gem 'rack-test', :git => 'https://github.com/econsultancy/rack-test.git', :branch => 'econsultancy-20110119'

And that does the trick. I imagine this patch will be merged in very soon though, as it was submitted a couple of months ago.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文