Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.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 Rspec最佳实践:为什么应该;它";只期待一件事?_Ruby On Rails_Rspec_Bdd - Fatal编程技术网

Ruby on rails Rspec最佳实践:为什么应该;它";只期待一件事?

Ruby on rails Rspec最佳实践:为什么应该;它";只期待一件事?,ruby-on-rails,rspec,bdd,Ruby On Rails,Rspec,Bdd,我在这张幻灯片上读到了关于RSpec最佳实践()和许多其他地方的内容,其中一个“it”只有一个期望是最佳实践。例如: describe UsersController, '#create' do # setup spec... it 'creates a new user' do should assign_to(:user).with(user) should set_the_flash should respond_with(:redirect) sh

我在这张幻灯片上读到了关于RSpec最佳实践()和许多其他地方的内容,其中一个“it”只有一个期望是最佳实践。例如:

describe UsersController, '#create' do
  # setup spec...
  it 'creates a new user' do
    should assign_to(:user).with(user)
    should set_the_flash
    should respond_with(:redirect)
    should redirect_to(admin_user_path(user))
  end
end
vs。
为什么最好的做法是只对一个“it”有一个期望值?因为这种方法更适合于文档编制。尝试
rspec——格式化文档
。另一个原因是,有一个
应该
每个
,您总是可以看到哪个测试失败。

好的,“单元测试”是一种自解释的表达方式。我没有考虑文档输出。非常感谢。
describe UsersController, '#create' do
  # setup spec...
  it { should assign_to(:user).with(user) }
  it { should set_the_flash }
  it { should respond_with(:redirect) }
  it { should redirect_to(admin_user_path(user)) }
end