代码之家  ›  专栏  ›  技术社区  ›  Joe Arasin

我应该用Rspec测试控制器助手还是控制器本身?

  •  1
  • Joe Arasin  · 技术社区  · 14 年前

    我有一个 PathsHelper 覆盖 foo_url foo_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
    

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

    2 回复  |  直到 14 年前
        1
  •  2
  •   David Chelimsky    14 年前

    虽然RSpec的目标是关注行为,但我仍然在helper规范中指定复杂的helper。这就是为什么在RSpec中首先存在helper规范:)

        2
  •  2
  •   SLaks    14 年前

    控制器

    请记住,在RSpec中,您要指定行为,并确保这些行为按照您希望的方式发生。这些行为是通过与控制器的交互来实现的。因此,为控制器编写规范,并确保测试helper显示的行为。