我将问题解决了RSpec本身.问题是,当通过RSpec :: Core :: Runner.run运行RSpec几次时它工作正常,直到使用load重新加载spec文件.然后RSpecs开始运行两次规格.
我已创建示例项目,显示此问题:https://github.com/mostr/rspec_double_run_issue
以下是示例输出:
ruby run_spec_in_loop.rb Running spec from within ruby runtime.Finished in 0.00047 seconds1 example,0 failuresloading spec file via 'load' as if it was changed and we wanted changes to be picked upRunning spec from within ruby runtime..Finished in 0.001 seconds2 examples,0 failures
有没有办法告诉RSpec在从现有ruby运行时内部运行时清除其后续运行之间的上下文?我还提出了这个问题作为RSpec Core项目的#826问题.
解决方法 总结这里的答案,以便从“未答复”过滤器中删除此问题…根据RJHunter的观察,GitHub RSpec核心项目的解释已在此处记录:
https://github.com/rspec/rspec-core/issues/826#issuecomment-15089030
对于后代(如果以上链接死亡),以下是详细信息:
The RSpec runner is already calling load internally,your second load is what’s causing the double run issue.
I quickly knocked up a script based off your example which reruns a single spec file,changes the specs to something else,then reruns them,work’s correctly without the second load
See: 07002
上述要点包含:
require 'rspec'spec_file = 'spec/sample_spec.rb'file.open(spec_file,'w') { |file| file.write 'describe { specify { expect(true).to eq false } }' }1.upto(5) do |i| puts "Running spec from within ruby runtime" ::RSpec::Core::Runner.run([spec_file],STDERR,STDOUT) #rewriting the spec file file.open(spec_file,'w') { |file| file.write "describe { specify { expect(#{i}).to eq false } }" }end总结
以上是内存溢出为你收集整理的为什么RSpec在从ruby内部运行时运行规范两次并重新加载spec文件?全部内容,希望文章能够帮你解决为什么RSpec在从ruby内部运行时运行规范两次并重新加载spec文件?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)