Runnin rspec from IntelliJ

I'm usally running my specs from inside IntelliJ. I've deleted my gems and reinstalled them using bundle install (due to another error) and now I'm getting an error when trying to run the specs.

I've noticed that running the specs from intelliJ it uses:

    from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

which isn't the case when running from the shell (I placed a print inside the kernel_require script check it).

Also I've see that the ruby version from intelliJ is:

"ruby 2.2.4: 230"

and from shell:

ruby -e 'print "ruby #{ RUBY_VERSION }p#{ RUBY_PATCHLEVEL }"'
ruby 2.2.6p396%    

The error:

    /home/user/.rvm/rubies/ruby-2.2.4/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /home/user/.rvm/gems/ruby-2.2.4/bin/rspec /home/user/workspace/auto-test/spec/pools/pool_cg_view_spec.rb --require teamcity/spec/runner/formatter/teamcity/formatter --format Spec::Runner::Formatter::TeamcityFormatter
    Testing started at 10:21 ...
    /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': incompatible library version - /home/user/.rvm/gems/ruby-2.2.4/gems/nokogiri-1.6.8/lib/nokogiri/nokogiri.so (LoadError)
        from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/nokogiri-1.6.8/lib/nokogiri.rb:32:in `rescue in <top (required)>'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/nokogiri-1.6.8/lib/nokogiri.rb:28:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/capybara-2.7.1/lib/capybara.rb:3:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/capybara-2.7.1/lib/capybara/dsl.rb:2:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/capybara-2.7.1/lib/capybara/rspec.rb:2:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require'
        from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
        from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
        from /home/user/workspace/auto-test/spec/support/capybara.rb:3:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /home/user/workspace/auto-test/spec/spec_helper.rb:6:in `block in <top (required)>'
        from /home/user/workspace/auto-test/spec/spec_helper.rb:6:in `each'
        from /home/user/workspace/auto-test/spec/spec_helper.rb:6:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1295:in `block in requires='
        from /home/user/.rvm/gems/ruby-2.2.4/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1295:in `each'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1295:in `requires='
        from /home/user/.rvm/gems/ruby-2.2.4/gems/rspec-core-3.4.1/lib/rspec/core/configuration_options.rb:109:in `block in process_options_into'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/rspec-core-3.4.1/lib/rspec/core/configuration_options.rb:108:in `each'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/rspec-core-3.4.1/lib/rspec/core/configuration_options.rb:108:in `process_options_into'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/rspec-core-3.4.1/lib/rspec/core/configuration_options.rb:21:in `configure'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:101:in `setup'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:88:in `run'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:73:in `run'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:41:in `invoke'
        from /home/user/.rvm/gems/ruby-2.2.4/gems/rspec-core-3.4.1/exe/rspec:4:in `<top (required)>'
        from /home/user/.rvm/gems/ruby-2.2.4/bin/rspec:23:in `load'
        from /home/user/.rvm/gems/ruby-2.2.4/bin/rspec:23:in `<top (required)>'
        from -e:1:in `load'
        from -e:1:in `<main>'

    Process finished with exit code 1

If I try to run the specs from shell it will work, no errors, so I guess the problem is related to the configuration of the run but not sure what.

The run configuration which worked until now:

在这里输入图像描述

I've tried to remove the nokogiri gem and reinstall it, but still the same.

Any ideas?

project structure: 在这里输入图像描述


You are pointing out that you are in ruby 2.2.6 when using the console. IntelliJ is complaining about missing the nokogiri gem.

I can imagine that probably your last bundle install did not use ruby 2.2.4 (as used by IntelliJ) but ruby 2.2.6 to install the gems.

I recommend the following steps to narrow this down:

  • verify and ensure that you are using ruby 2.2.4 on the shell (this is very important!)
  • run bundle install to ensure all gems of your project are installed for ruby 2.2.4
  • run your specs in the shell
  • If this succeeds then try running specs with IntelliJ. This should work in case the steps described above went fine.

    A personal note (not knowing if it's already the case): In my projects I always have a .ruby-version file in the root of my project to ensure the correct ruby version for the current project. You may even go a step further and add a .ruby-gemset file.

    More information can be found in the rvm docs

    链接地址: http://www.djcxy.com/p/96336.html

    上一篇: Websocket获得升级,但没有客户端的框架

    下一篇: IntelliJ的Runnin rspec