Giter VIP home page Giter VIP logo

Comments (10)

sj26 avatar sj26 commented on June 5, 2024 1

bundle exec rake is roughly the same as bin/rake, and has the same error:

RAILS_ENV=test KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES=true bundle exec rake knapsack_pro:rspec                       
rake aborted!
NameError: uninitialized constant RSpec::Core::Version
/opt/rbenv/versions/2.7.2/bin/bundle:23:in `load'
/opt/rbenv/versions/2.7.2/bin/bundle:23:in `<main>'
Tasks: TOP => knapsack_pro:rspec
(See full trace by running task with --trace)

The rake loading stuff faster is a carefully designed bit of rails. :-)

This particular knapsack rake task gear would be loading in a parent process of the rspec spec_helper or rails_helper so those probably wouldn't have any effect either.

Maybe adding require 'rspec/core/version' inside of the method fast_and_slow_test_files_to_run right before RSpec::Core::Version::STRING check would be enough to fix the issue.

Yeah, that's what I was thinking! 👍

from knapsack_pro-ruby.

sj26 avatar sj26 commented on June 5, 2024 1

Another alternative which avoids requiring the file would be to look at the loaded spec version, which bundle exec ... (or require "bundler/setup") sets up long before anything within the gem is required:

      if adapter_class == KnapsackPro::Adapters::RSpecAdapter && KnapsackPro::Config::Env.rspec_split_by_test_examples?
        unless Gem.loaded_specs["rspec-core"].version >= Gem::Version.new('3.3.0')

from knapsack_pro-ruby.

sj26 avatar sj26 commented on June 5, 2024 1

Thanks @ArturT!

from knapsack_pro-ruby.

sj26 avatar sj26 commented on June 5, 2024

A workaround is to insert a rake task dependency which requires the file:
sj26/knapsack-test@rspec-core-version-error...rspec-core-version-workaround

A fix is probably to add the require immediately before the usage within lib/knapsack_pro/base_allocator_builder.rb

from knapsack_pro-ruby.

ArturT avatar ArturT commented on June 5, 2024

Most likely you have not set RAILS_ENV=test and rspec is not loaded.

from knapsack_pro-ruby.

ArturT avatar ArturT commented on June 5, 2024

You can also ensure RSpec is in the test and development group in your Gemfile.

from knapsack_pro-ruby.

sj26 avatar sj26 commented on June 5, 2024

RAILS_ENV is set to test:
https://github.com/sj26/knapsack-test/blob/rspec-core-version-error/.buildkite/pipeline.yml#L16

rspec is in the test and development groups:
https://github.com/sj26/knapsack-test/blob/rspec-core-version-error/Gemfile#L8-L14

Are you expecting rails rake to have called Bundler.require? It doesn't, on purpose, so that invoking rake is quick. If you want to load all gems and the rails environment then your take rask needs to depend on the environment task. (In this case I don't think it should, the rspec child process should do that.)

from knapsack_pro-ruby.

ArturT avatar ArturT commented on June 5, 2024

That's interesting. You basically use knapsack_pro in a way that's not the default approach documented in README. Most people just use bundler:

bundle exec rake knapsack_pro:rspec

You use bin/rake to load stuff faster and load Rails environment only if RSpec config (like spec_helper.rb or rails_helper.rb) decides to do it. I could imagine someone could have tests that don't depend on Rails environment and then the user doesn't have to load Rails environment so using bin/rake makes more sense than bundle exec because bin/rake is faster.

Anyway. I didn't think about it before so I never covered the bin/rake approach in the documentation that's why you encounter the issue.

from knapsack_pro-ruby.

ArturT avatar ArturT commented on June 5, 2024

Maybe adding require 'rspec/core/version' inside of the method fast_and_slow_test_files_to_run right before RSpec::Core::Version::STRING check would be enough to fix the issue. I need to ensure we load rspec only when someone is running RSpec test runner.

unless Gem::Version.new(::RSpec::Core::Version::STRING) >= Gem::Version.new('3.3.0')

from knapsack_pro-ruby.

ArturT avatar ArturT commented on June 5, 2024

I've released knapsack_pro 2.18.1 with a fix.
PR: #151

from knapsack_pro-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.