繁体   English   中英

在同一进程中从ruby内多次运行rspec

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM