什么是“应该”?在 Rspec 中?为什么 `should redirect_to` 有效?
Rspec 有很多魔力。我不知道应该
是什么以及如何使用它。
response.should redirect_to(some_path)
Rdoc 说 should
可以是使用 ==
、===
、~=
和匹配器(它是什么?)调用。我猜 redirect_to(some_path)
是匹配器。
但这意味着什么呢?这个redirect_to
和ActionController::Redirecting#redirect_to
一样吗? should
可以知道 Rails 是否调用此方法吗?
还有其他的事情......
should render_template
should have_text
render_template 是 ActionView::LogSubscriber#render_template
吗?那么任何 Rails 方法都可以附加在 should
之后吗?而且,Rails 没有 have_text
方法,那么它是什么呢?为什么应该
知道?
Rspec has a lot of magics. I can't find out what should
is and how to use it.
response.should redirect_to(some_path)
The Rdoc says should
can be called with ==
, ===
, ~=
, and a matcher(what is it?). I guess redirect_to(some_path)
is the matcher.
But what does it mean? This redirect_to
is the same as the ActionController::Redirecting#redirect_to
? Can should
know whether Rails calls this method?
And the other things...
should render_template
should have_text
Is render_template the ActionView::LogSubscriber#render_template
? So any Rails method can be attached after should
? Moreover, Rails doesn't have the method have_text
, so what is it? Why does should
know?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,
redirect_to
是另一回事。您在执行should redirect_to()
时使用的是这个匹配器 - http://relishapp.com/rspec/rspec-rails/v/2-6/dir/matchers/redirect-to-matcher与 < 相同一个href="http://relishapp.com/rspec/rspec-rails/v/2-6/dir/matchers/render-template-matcher" rel="nofollow">render_template
No, that
redirect_to
is a different thing. The one you're using when doingshould redirect_to()
is this matcher - http://relishapp.com/rspec/rspec-rails/v/2-6/dir/matchers/redirect-to-matcherSame with render_template