什么是“应该”?在 Rspec 中?为什么 `should redirect_to` 有效?

发布于 2024-11-27 20:52:07 字数 787 浏览 0 评论 0原文

Rspec 有很多魔力。我不知道应该是什么以及如何使用它。

response.should redirect_to(some_path)

Rdocshould 可以是使用 =====~= 和匹配器(它是什么?)调用。我猜 redirect_to(some_path) 是匹配器。

但这意味着什么呢?这个redirect_toActionController::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 技术交流群。

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

发布评论

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

评论(1

甜`诱少女 2024-12-04 20:52:07

不,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 doing should redirect_to() is this matcher - http://relishapp.com/rspec/rspec-rails/v/2-6/dir/matchers/redirect-to-matcher

Same with render_template

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