Rails by Example 教程请求示例和 Capybara
在 Michael Hartl 的 Rails on Rails 教程中,请求示例对响应进行断言。我安装了 cabybara 和牛排 gem 来创建验收测试。安装 capybara 后,请求示例配置为使用 capybara。水豚示例具有不同的语法,并且无法识别响应。
如何重置请求示例以作为 RSpec 示例运行?
测试错误:
4) Users signup failure should not make a new user
Failure/Error: click_button
wrong number of arguments (0 for 1)
# ./spec/requests/users_spec.rb:13
# ./spec/requests/users_spec.rb:7
请求示例
describe "failure" do
it "should not make a new user" do
lambda do
visit signup_path
fill_in "Name", :with => ""
fill_in "Email", :with => ""
fill_in "Password", :with => ""
fill_in "Confirmation", :with => ""
click_button
response.should render_template('users/new')
end.should_not change(User, :count)
end
end
In the Rails on Rails Tutorial by Michael Hartl, the Request Examples make assertions on the response. I installed the cabybara and steak gem to create acceptance tests. After installing capybara, the requests examples are configured to use capybara. capybara examples have a different syntax and don't recognize the response.
How do I reset the Request Examples to run as RSpec example?
Test Error:
4) Users signup failure should not make a new user
Failure/Error: click_button
wrong number of arguments (0 for 1)
# ./spec/requests/users_spec.rb:13
# ./spec/requests/users_spec.rb:7
Request Example
describe "failure" do
it "should not make a new user" do
lambda do
visit signup_path
fill_in "Name", :with => ""
fill_in "Email", :with => ""
fill_in "Password", :with => ""
fill_in "Confirmation", :with => ""
click_button
response.should render_template('users/new')
end.should_not change(User, :count)
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能与 rspec-rails request_example_group.rb 有关。
request_example_group.rb
如果水豚行被注释掉,那么请求示例不会默认为水豚。
在验收示例中,包括水豚。
我最终分叉了 rspec-rails 并注释掉了水豚行。
在 Gemfile 中,从 fork 安装的 gem。
何苦呢?我们想要白盒和黑盒测试。
This might have something to do with rspec-rails request_example_group.rb.
request_example_group.rb
If the capybara lines are commented out, then the Request Examples are not defaulted to capybara.
In the Acceptance examples, include capybara.
I ended up forking rspec-rails and commenting out the capybara lines.
In the Gemfile, the gem installed from the fork.
Why bother? We want both white box and black box testing.
正如您在答案中正确指出的那样,如果安装了 rspec-rails,它将
包含 Capybara
。我认为他们假设包含
Capybara 不会有什么坏处,以防万一你需要它。这对你来说是个问题吗?换句话说,Capybara DSL 具体与什么冲突?RSpec 邮件列表 上提出。)
(这可能也值得在 您发布的错误,似乎您只是缺少
click_button
方法。As you correctly point out in your answer, rspec-rails will
include Capybara
if it is installed. I think they're assuming that it never hurts toinclude
Capybara, just in case you need it. Is that a problem for you? In other words, what specifically is the Capybara DSL conflicting with?(This might be also be worth bringing up on the RSpec mailing list.)
As for the error you posted, it seems that you are simply missing an argument to the
click_button
method.