Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 断言Rails 3中的差异_Ruby On Rails_Ruby_Unit Testing - Fatal编程技术网

Ruby on rails 断言Rails 3中的差异

Ruby on rails 断言Rails 3中的差异,ruby-on-rails,ruby,unit-testing,Ruby On Rails,Ruby,Unit Testing,这真的是最好的方法吗 assert_difference('u.point', 10) do assert_difference('u.point_logs.count') do assert_difference('a.point', 5) do assert_difference('a.point_logs.count') do u.give_points(:description => 'Test', :points => 10.0)

这真的是最好的方法吗

assert_difference('u.point', 10) do
  assert_difference('u.point_logs.count') do
    assert_difference('a.point', 5) do
      assert_difference('a.point_logs.count') do
        u.give_points(:description => 'Test', :points => 10.0)
      end
    end
  end
end
问候,


Jacob

我强烈建议您编写更多测试来强调特定功能。在我看来,您可以编写一个测试来断言
a
上的差异,也可以编写一个测试来断言
u
上的差异,如果想要避免将其分成两个区块,这是最好的方法。

您知道,在u上调用“给点”会同时改变u和a吗?好的-这会改变您的建议吗?不太可能。这个测试对我来说太复杂了。我需要更多的背景,但主要思想不会改变。RSpec有一个规则:每个测试一个断言。这通常是不可能的,但请尽量在1:1和4:1之间保持平衡。事实上,一个断言规则在现实中很难应用(尤其是在集成测试中),而且它也可能非常低效,因为测试需要反复初始化。或者有人知道重用以前测试中初始化的模型的方法吗?我想这很难,因为测试会变得依赖顺序。也许需要一块宝石?;-)和/或单独的SO问题。;-)