Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在一个应用程序中从另一个应用程序执行RSpec测试套件';s测试套件?_Ruby On Rails_Testing_Rspec - Fatal编程技术网

Ruby on rails 如何在一个应用程序中从另一个应用程序执行RSpec测试套件';s测试套件?

Ruby on rails 如何在一个应用程序中从另一个应用程序执行RSpec测试套件';s测试套件?,ruby-on-rails,testing,rspec,Ruby On Rails,Testing,Rspec,我正在编写一个与测试过程集成的RubyGem,我想编写一个集成测试来证明它能够像我期望的那样端到端地工作。我包括一个使用Gem的简单应用程序(TestApp) 我的gem包括一个spec文件夹和根目录中的测试应用程序。测试应用程序将其测试包含在功能文件夹中。(当然还有其他东西在里面) 在添加新测试之前,如果我在my_gem目录中并执行bundle exec rspec,则我对my_gem的测试将按预期执行。如果我执行: cd test_app bundle exec features 我对te

我正在编写一个与测试过程集成的RubyGem,我想编写一个集成测试来证明它能够像我期望的那样端到端地工作。我包括一个使用Gem的简单应用程序(TestApp)

我的gem包括一个
spec
文件夹和根目录中的测试应用程序。测试应用程序将其测试包含在
功能
文件夹中。(当然还有其他东西在里面)

在添加新测试之前,如果我在
my_gem
目录中并执行
bundle exec rspec
,则我对
my_gem
的测试将按预期执行。如果我执行:

cd test_app
bundle exec features
我对
test\u app
的测试按预期执行。现在,如果我添加到我的
my_gem
测试中:

describe "Test test suite"
    it "executes as expected"
        `bundle exec test_app/features`
    end
end
并在
my_gem
中执行测试,我得到以下结果:

C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.2/lib/tzinfo/data_source.rb:182:in `rescue in create_default_data_source': No source of timezone data could be found. (TZInfo::DataSourceNotFound)
Please refer to http://tzinfo.github.io/datasourcenotfound for help resolving this error.
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/tzinfo-1.2.2/lib/tzinfo/data_source.rb:179:in `create_default_data_source'
...
按照建议的URL上的说明,我陷入了一个兔子洞,向我的gem添加依赖项,否则我不会要求,也不想强迫gem的最终用户依赖这些依赖项

除上述内容外,我还尝试了:

exec('bundle exec rspec test_app/features')

但每次我都会犯同样的错误。有趣的是,当我从控制台中的
my_gem
目录执行
bundle exec rspec test\u app/features
时,我在没有额外测试的情况下得到了相同的错误,但当我在没有
bundle exec
的情况下执行命令时却没有得到。在测试中删除
bundle exec
,没有任何区别

是什么导致了这些错误?有没有一种方法可以从我的
my\u gem
测试中执行我的
test\u app
测试套件,使它们不会导致错误?

我在这里找到了一个解决方案:

事实证明,这些测试是在我当前的环境下执行的(其他人可能能够更好地解释这一点)。解决方案是使用
捆绑机。使用\u clean\u env

Bundler.with_clean_env do
    Dir.chdir('test_app') do
        `bundle exec rspec features`
    end
end
Dir.chdir('test_app') do
    `bundle exec rspec features`
end
Bundler.with_clean_env do
    Dir.chdir('test_app') do
        `bundle exec rspec features`
    end
end