简体   繁体   中英

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.

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 ?

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/

I had a similar issue and had to do a RSpec#reset between runs to make sure everything was cleaned up.

http://www.rubydoc.info/github/rspec/rspec-core/RSpec#reset-class_method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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