Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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/9/google-apps-script/6.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 3 意外的rspec行为Ruby on Rails教程第12章_Ruby On Rails 3_Rspec2 - Fatal编程技术网

Ruby on rails 3 意外的rspec行为Ruby on Rails教程第12章

Ruby on rails 3 意外的rspec行为Ruby on Rails教程第12章,ruby-on-rails-3,rspec2,Ruby On Rails 3,Rspec2,我看到的错误仅取决于线路的位置: should change(Relationship, :count).by(-1) 例如,使用以下代码: it "should destroy a relationship using Ajax" do lambda do xhr :delete, :destroy, :id => @relationship response.should be_success end.should change(Relationship, :

我看到的错误仅取决于线路的位置:

should change(Relationship, :count).by(-1)
例如,使用以下代码:

it "should destroy a relationship using Ajax" do
  lambda do
    xhr :delete, :destroy, :id => @relationship
    response.should be_success
  end.should change(Relationship, :count).by(-1) #<<-line is here
it "should destroy a relationship using Ajax" do
  lambda do
    xhr :delete, :destroy, :id => @relationship
    response.should be_success
    should change(Relationship, :count).by(-1) #<<-Line moved to here
  end
我得到rspec错误:

  1) RelationshipsController DELETE 'destroy' should destroy a relationship using Ajax
     Failure/Error: xhr :delete, :destroy, :id => @relationship
     ActionView::MissingTemplate:
       Missing template relationships/destroy with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:js, :html], :locale=>[:en, :en]} in view paths "#<RSpec::Rails::ViewRendering::PathSetDelegatorResolver:0x00000100a5b5f8>"
     # ./app/controllers/relationships_controller.rb:16:in `destroy'
     # ./spec/controllers/relationships_controller_spec.rb:44:in `block (4 levels) in <top (required)>'
     # ./spec/controllers/relationships_controller_spec.rb:43:in `block (3 levels) in <top (required)>'
但对于代码:

it "should destroy a relationship using Ajax" do
  lambda do
    xhr :delete, :destroy, :id => @relationship
    response.should be_success
  end.should change(Relationship, :count).by(-1) #<<-line is here
it "should destroy a relationship using Ajax" do
  lambda do
    xhr :delete, :destroy, :id => @relationship
    response.should be_success
    should change(Relationship, :count).by(-1) #<<-Line moved to here
  end
。。。考试通过了

当我使用web浏览器时,我看到了预期的行为。取消跟踪用户将正确调整总数


那么,这两个rspec测试是否不相等?我被错误地保证第二次测试通过了吗?如果它们在功能上是等价的,为什么第一个会失败呢?

似乎这部分是由于

./app/controllers/relationships_controller.rb

粘贴到错误文件中的代码不会生成语法错误。修复错误会导致通过rspec测试