![](/img/trans.png)
[英]Why RSpec runs specs twice when running from within ruby and spec file is reloaded?
[英]Running rspec from within ruby multiple times within the same process
我正在創建一個測試自動化工具,該工具從ruby而不是從命令行運行rspec測試。
我像這樣運行測試,並通過/失敗等給我輸出哈希值。
config = RSpec.configuration
json_formatter = RSpec::Core::Formatters::JsonFormatter.new(config.out)
reporter = RSpec::Core::Reporter.new(json_formatter)
config.instance_variable_set(:@reporter, reporter)
RSpec::Core::Runner.run(["#{Rails.root}/spec/test1_spec.rb"])
puts json_formatter.output_hash
一切都很好,直到我再次運行它並得到錯誤
> undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_7:0x007ff3d343d978>
在重新運行之前,如何重新加載/確保所有spec_helper和文件都已加載?
謝謝里克
加
require 'spec_helper'
到每個規格文件的頂部。
我有同樣的問題,原來只能用一行代碼來解決:
require 'capybara'
include Capybara::DSL # Add this line right after requiring capybara
資料來源: http : //codedecoder.wordpress.com/2013/01/10/undefined-method-visit-for-rspec-capybara/
我遇到了類似的問題,必須在兩次運行之間進行RSpec#reset
,以確保一切都已清理干凈。
http://www.rubydoc.info/github/rspec/rspec-core/RSpec#reset-class_method
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.