我尝试使用存储库中的ruby 2.1.5+deb8u2
和ruby-dev 2.1.5+deb8u2
软件包在新安装的Debian 8.5上设置新的Ruby项目。我想在我的项目中包含变异测试。我将mutant-rspec
添加到Gemfile
:
source 'https://rubygems.org'
gem 'rake'
gem 'rspec', require: 'spec'
gem 'mutant-rspec'
Bundler(1.13.0)似乎安装好了宝石
ytg@debian-vm:~/projects/new_project$ bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/.
Using rake 11.2.2
....
Using rspec-core 3.5.3
Using rspec-expectations 3.5.0
Using rspec-mocks 3.5.0
...
Using rspec 3.5.0
...
Installing mutant 0.8.11
Installing mutant-rspec 0.8.11
Bundle complete! 5 Gemfile dependencies, 34 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
现在,如果我尝试使用rake文件
使用rake mutant --trace
来运行突变体
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'mutant'
RSpec::Core::RakeTask.new :spec
task default: :spec
RuboCop::RakeTask.new
task :mutant do
result = Mutant::CLI.run %w(--since problem9 -Ilib -Ispec
--use rspec MyProject*)
raise 'Mutation testing failed' unless result
end
我收到错误消息:
warning: parser/current is loading parser/ruby21, which recognizes
warning: 2.1.8-compliant syntax, but you are running 2.1.5.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
** Invoke mutant (first_time)
** Execute mutant
Could not load integration "rspec" (you may want to try installing the gem mutant-rspec)
rake aborted!
Mutation testing failed
/home/ytg/projects/new_project/Rakefile:15:in `block in <top (required)>'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:248:in `call'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:248:in `block in execute'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `each'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `execute'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/usr/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/task.rb:173:in `invoke'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/application.rb:152:in `invoke_task'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `each'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `block in top_level'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/application.rb:117:in `run_with_threads'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/application.rb:102:in `top_level'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/application.rb:80:in `block in run'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/application.rb:178:in `standard_exception_handling'
/var/lib/gems/2.1.0/gems/rake-11.2.2/lib/rake/application.rb:77:in `run'
/var/lib/gems/2.1.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'
Tasks: TOP => mutant
如果我尝试直接执行此操作,则会显示相同的消息
ytg@debian-vm:~/projects/new_project$ mutant -I lib/ --use rspec MyProject*
warning: parser/current is loading parser/ruby21, which recognizes
warning: 2.1.8-compliant syntax, but you are running 2.1.5.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
Could not load integration "rspec" (you may want to try installing the gem mutant-rspec)
据我所知,这是因为some loading issue。但究竟是什么装载问题呢?如何在我的项目上运行mutant
?
(我还尝试使用sudo gem install mutant-rspec
安装gem以防万一,但它没有帮助,我收到相同的错误消息。)
答案 0 :(得分:1)
您正在运行的mutant
可能无法在正确的环境中执行。请尝试使用bundle exec mutant
,这样可以确保Gemfile
中指定的那个与正确的宝石一起使用。
为了帮助调试,请使用which mutant
确定要调用的版本。 sudo gem install
不应该是一个解决方案,我建议sudo gem uninstall
恢复原状,否则可能会导致问题。
但我认为所有这些都是红鲱鱼。
对于Rakefile
,它实际上并没有对mutant
脚本进行炮轰。你绕过它并直接转到Mutant::CLI
。这里的问题是没有任何东西正在设置加载路径,因此它将包含mutant-rspec
:
task :mutant do
puts $LOAD_PATH # debug: see it's missing load path for mutant-rspec
require 'bundler/setup' # This line is new
puts $LOAD_PATH # debug: see how it changes
result = Mutant::CLI.run %w(--since problem9 -Ilib -Ispec
--use rspec MyProject*)
raise 'Mutation testing failed' unless result
end
或者,bundle exec rake mutant
也应该做同样的事情。我建议总是使用bundle exec
(或binstubs),而不是路径上恰好有rake
。否则很难推理。