如何获得自动测试以正确地改变单个模型和多个控制器

时间:2022-04-11 10:16:32

Just as an example, if I have a Book model and a BooksController, autotest, part of the ZenTest suite will pick up the association between the two and load test/unit/book_test.rb and test/functional/books_controller_test.rb into the test suite. On the other hand, if I have a Story model and a StoriesController, autotest refuse to "notice" the test/functional/stories_controller_test.rb

举个例子,如果我有Book模型和BooksController,自动测试,ZenTest套件的一部分将获取两者之间的关联并将test / unit / book_test.rb和test / functional / books_controller_test.rb加载到测试中套房。另一方面,如果我有一个Story模型和一个StoriesController,自动测试拒绝“注意”test / functional / stories_controller_test.rb

3 个解决方案

#1


0  

Unfortunately ZenTest isn't a rails plugin, so it doesn't benefit from ActiveSupport's pluralize method. Therefore it uses simple regular expressions to match the filenames. Have a look at ZenTest/autotest/rails.rb to see a list of the existing mappings for Rails.

不幸的是,ZenTest不是rails插件,所以它不会受益于ActiveSupport的复数方法。因此,它使用简单的正则表达式来匹配文件名。查看ZenTest / autotest / rails.rb以查看Rails现有映射的列表。

At the end you have two options:

最后,您有两个选择:

  • (monkey) patch your own mapping rule
  • (猴子)修补你自己的映射规则

  • forget about pluralization
  • 忘记多元化

Hope this helps!

希望这可以帮助!

#2


0  

You can override the mappings in your .autotest file. Either in your home directory or at the root of the project. You could require 'active_support' there to get String#pluralize and String#singularize.

您可以覆盖.autotest文件中的映射。在您的主目录或项目的根目录中。您可以在那里要求'active_support'来获取String#pluralize和String #singleularize。

Borrow the code from the rspec-rails plugin in lib/autotest/rails_rspec.rb, it already seems to do the singular/plural magic with ActiveSupport. You'll probably need to yank out the RSpec specific assumptions from there, though.

借用lib / autotest / rails_rspec.rb中的rspec-rails插件中的代码,它似乎已经使用ActiveSupport进行单数/复数魔术。但是,您可能需要从那里拉出RSpec特定的假设。

#3


0  

I finally figured out what was going on, and it had nothing to do with pluralization after all.

我终于弄清楚发生了什么,毕竟它与多元化无关。

It had everything to do with the word "stories" which can be a special directory for one of the testing libraries (RSpec? Cucumber? I forget) So it was listed in my ~/.autotest config file as an exception! I'm not sure when I cut and pasted the snippet into the file, probably when I was first getting starting with ZenTest and didn't know what I was really doing.

它与“故事”这个词有关,它可以作为其中一个测试库的特殊目录(RSpec?Cucumber?我忘记了)所以它被列在我的〜/ .autotest配置文件中作为例外!我不确定何时剪切并将片段粘贴到文件中,可能是在我第一次开始使用ZenTest并且不知道我在做什么的时候。

Autotest.add_hook :initialize do |at|
  %w{... stories ...}.each {|exception|at.add_exception(exception)}
end

Adding a trailing slash ("stories/") restored the test and removed the brick marks from my forehead.

添加尾部斜杠(“stories /”)恢复了测试并从我的额头上移除了砖痕。

So I guess the lesson learned is: check for stray configuration files when debugging.

所以我想从中吸取的教训是:在调试时检查杂散配置文件。

#1


0  

Unfortunately ZenTest isn't a rails plugin, so it doesn't benefit from ActiveSupport's pluralize method. Therefore it uses simple regular expressions to match the filenames. Have a look at ZenTest/autotest/rails.rb to see a list of the existing mappings for Rails.

不幸的是,ZenTest不是rails插件,所以它不会受益于ActiveSupport的复数方法。因此,它使用简单的正则表达式来匹配文件名。查看ZenTest / autotest / rails.rb以查看Rails现有映射的列表。

At the end you have two options:

最后,您有两个选择:

  • (monkey) patch your own mapping rule
  • (猴子)修补你自己的映射规则

  • forget about pluralization
  • 忘记多元化

Hope this helps!

希望这可以帮助!

#2


0  

You can override the mappings in your .autotest file. Either in your home directory or at the root of the project. You could require 'active_support' there to get String#pluralize and String#singularize.

您可以覆盖.autotest文件中的映射。在您的主目录或项目的根目录中。您可以在那里要求'active_support'来获取String#pluralize和String #singleularize。

Borrow the code from the rspec-rails plugin in lib/autotest/rails_rspec.rb, it already seems to do the singular/plural magic with ActiveSupport. You'll probably need to yank out the RSpec specific assumptions from there, though.

借用lib / autotest / rails_rspec.rb中的rspec-rails插件中的代码,它似乎已经使用ActiveSupport进行单数/复数魔术。但是,您可能需要从那里拉出RSpec特定的假设。

#3


0  

I finally figured out what was going on, and it had nothing to do with pluralization after all.

我终于弄清楚发生了什么,毕竟它与多元化无关。

It had everything to do with the word "stories" which can be a special directory for one of the testing libraries (RSpec? Cucumber? I forget) So it was listed in my ~/.autotest config file as an exception! I'm not sure when I cut and pasted the snippet into the file, probably when I was first getting starting with ZenTest and didn't know what I was really doing.

它与“故事”这个词有关,它可以作为其中一个测试库的特殊目录(RSpec?Cucumber?我忘记了)所以它被列在我的〜/ .autotest配置文件中作为例外!我不确定何时剪切并将片段粘贴到文件中,可能是在我第一次开始使用ZenTest并且不知道我在做什么的时候。

Autotest.add_hook :initialize do |at|
  %w{... stories ...}.each {|exception|at.add_exception(exception)}
end

Adding a trailing slash ("stories/") restored the test and removed the brick marks from my forehead.

添加尾部斜杠(“stories /”)恢复了测试并从我的额头上移除了砖痕。

So I guess the lesson learned is: check for stray configuration files when debugging.

所以我想从中吸取的教训是:在调试时检查杂散配置文件。