Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.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跟不上应用程序it';什么是测试?_Ruby On Rails_Rspec_Pry - Fatal编程技术网

Ruby on rails 为什么Rspec跟不上应用程序it';什么是测试?

Ruby on rails 为什么Rspec跟不上应用程序it';什么是测试?,ruby-on-rails,rspec,pry,Ruby On Rails,Rspec,Pry,我有: 我所要做的就是键入pry remote,然后在Rspec进入binding.pry_remote时退出 看起来它所做的只是让我的应用程序慢下来,让Rspec赶上 但是如果没有绑定.pry_remote,规范将失败。没有它,@competitor.inputs就是[],就像@competitor.reload.inputs和@competitor.inputs(true)和@competitor.reload.inputs(true)一样 如何解决此问题?在您的示例中何时调用update\

我有:

我所要做的就是键入
pry remote
,然后在Rspec进入
binding.pry_remote
时退出

看起来它所做的只是让我的应用程序慢下来,让Rspec赶上

但是如果没有绑定.pry_remote,规范将失败。没有它,
@competitor.inputs
就是
[]
,就像
@competitor.reload.inputs
@competitor.inputs(true)
@competitor.reload.inputs(true)
一样


如何解决此问题?

在您的示例中何时调用
update\u inputs
?在测试中没有明显的地方调用该方法。在不知道何时调用的情况下,我不知道任何人如何调试计时或排序问题。很抱歉,我现在将更新以显示信息--
在更新之后:更新输入
class Competitor < ActiveRecord::Base
  after_commit :delayed_create_matching_surveys
end

class Survey < ActiveRecord::Base
  after_create :create_matching_results, :touch_review
end

class Result < ActiveRecord::Base
  after_update :update_inputs
  def update_inputs
    if input_id.present?
      @input = Input.find(input_id)
      if survey.reload.results.sort_by{|r| r.points}.last.selected
        competitor.inputs << @input unless competitor.inputs.include?(@input)
      else
        competitor.inputs.delete(@input) if competitor.inputs.include?(@input)
      end
    end
    binding.pry_remote ## << which exists purely to slow down the app
  end
end
describe "update_inputs" do

  before :each do
    @product = create(:product)
    @question = create(:question, :product => @product)
    @review = create(:review, :product => @product)
    @client = @review.competitors.first
    @competitor = create(:competitor, :review => @review)
    @category = create(:category)
    @input1 = create(:input)
    @input2 = create(:input)
    @competitor.categories << @category
    @input1.categories << @category
    @input2.categories << @category
  end
  it "assigns one input to a competitor when one is selected" do
    @survey = @competitor.reload.surveys.select{|s| s.input_id == @input1.id}.first
    @survey.results.select{|r| r.name.include?("sells this product")}.first.update_attributes :selected => true
    @competitor.inputs.should == [@input1]
  end
end