[英]Running rspec from within ruby multiple times within the same process
I am creating a test automation tool that runs a rspec test from within ruby, not from command line. 我正在创建一个测试自动化工具,该工具从ruby而不是从命令行运行rspec测试。
I run my test like this that runs and gives me a output hash with pass / fail etc. 我像这样运行测试,并通过/失败等给我输出哈希值。
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
All is great until i run it again and i get the error 一切都很好,直到我再次运行它并得到错误
> undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_7:0x007ff3d343d978>
how do i reload / make sure all spec_helper and files are loaded before i run it again ? 在重新运行之前,如何重新加载/确保所有spec_helper和文件都已加载?
thanks Rick 谢谢里克
Add 加
require 'spec_helper'
to the top of each spec file. 到每个规格文件的顶部。
I had the same problems, turns out it can be fixed with one line of code only: 我有同样的问题,原来只能用一行代码来解决:
require 'capybara'
include Capybara::DSL # Add this line right after requiring capybara
Source: http://codedecoder.wordpress.com/2013/01/10/undefined-method-visit-for-rspec-capybara/ 资料来源: http : //codedecoder.wordpress.com/2013/01/10/undefined-method-visit-for-rspec-capybara/
I had a similar issue and had to do a RSpec#reset
between runs to make sure everything was cleaned up. 我遇到了类似的问题,必须在两次运行之间进行
RSpec#reset
,以确保一切都已清理干净。
http://www.rubydoc.info/github/rspec/rspec-core/RSpec#reset-class_method http://www.rubydoc.info/github/rspec/rspec-core/RSpec#reset-class_method
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.