如何编写规范来验证部分的渲染?

发布于 2024-09-02 05:03:58 字数 471 浏览 1 评论 0原文

我正在使用 rr (模拟框架)和 rspec 以及 ruby​​-on-rails。另外,我使用集合速记进行部分渲染。我的问题:如何正确填写以下视图规范?

describe 'my_view' do
  before(:each) do
    assigns[:models] = Array.new(10, stub(Model))
  end

  it "should render the 'listing' partial for each model" do
    # help me write something that actually verifies this
  end
end

我尝试了 rspec 书籍、rspec 文档和 rr 文档中的一些示例。我尝试的所有操作似乎都会在测试中留下运行时错误 - 而不是失败的断言。我没有展示我尝试过的所有转变,而是想如果有人向我展示一种真正有效的转变,我所需要的一切。我很乐意从那里出发。

I'm using rr (the mocking framework) and rspec with ruby-on-rails. Also, I'm using the collection short hand for partial rendering. My question: How do I correctly fill out the the following view spec?

describe 'my_view' do
  before(:each) do
    assigns[:models] = Array.new(10, stub(Model))
  end

  it "should render the 'listing' partial for each model" do
    # help me write something that actually verifies this
  end
end

I've tried a few examples from the rspec book, rspec docs, and rr docs. Everything I try seems to leave me with runtime errors in the test - not failed assertions. Rather than show all the transformations I've tried, I figured all I'd need if someone showed me one that actually worked. I'd be good to go from there.

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

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

发布评论

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

评论(1

兔姬 2024-09-09 05:03:58

我建议断言“列表”部分应该生成的一些 HTML 的存在。否则,听起来您试图断言 Rails 在技术上正在调用局部渲染? Rails 核心测试的工作就是证明此类功能。

I would suggest asserting the presence of some HTML that the "listing" partial should generate. Otherwise, it sounds like you're trying to assert that Rails is technically calling render on the partial? That's the job of the Rails core tests to prove such functionality.

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