ruby-on-rails - 我应该用 Rspec 测试 Controller 助手还是 Controller 本身?

标签 ruby-on-rails testing rspec

我有一个 PathsHelper,它通过处理附加参数以及当前 url 的上下文来覆盖 foo_urlfoo_path。这包含在 ApplicationController 中。

现在,我有:

describe ApplicationController do
  describe "#foo_url" do
     ...
  end
  describe "#foo_path" do
     ...
  end
end

我想知道按照以下方式做某事是否更好:

describe PathsHelper do
  describe "#foo_url" do
     ...
  end
  describe "#foo_path" do
     ...
  end
end

如果是这样,是否有任何合理的方法可以在帮助测试中设置一些实例变量,因为有基于当前 url 的条件。

最佳答案

虽然 RSpec 确实旨在关注行为,但我仍然在帮助程序规范中指定复杂的帮助程序。这就是为什么首先在 RSpec 中存在 helper specs 的原因:)

关于ruby-on-rails - 我应该用 Rspec 测试 Controller 助手还是 Controller 本身?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3972011/

相关文章:

ruby-on-rails - RSpec 查看规范 : accessing view helpers

ruby-on-rails - ActiveRecord:where 语句中关联模型的引用属性

ruby-on-rails - Rails 表单在验证错误后呈现错误的 URL(不保留传递的参数)

ruby-on-rails - 使用 Squeel 时参数数量错误

java - 安卓 UIAutomator : setAsHorizontalList() throws noSuchMethodError

testing - 使用 Theories JUnit4 运行的测试类中可以放置多少测试方法

ruby-on-rails - 如果我在不同的子目录中有多个 Controller ,我该如何使用 redirect_to?

ruby-on-rails - 向现有 Rails 项目添加测试的最佳方式?

ruby - 是否有 rspec 匹配器来确认一个类是否包含库、模块或 gem?

rspec helper.stub 不起作用