Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set RAILS_ENV=test/RACK_ENV=test in Queue Mode #199

Merged
merged 4 commits into from
Jun 6, 2023
Merged

Set RAILS_ENV=test/RACK_ENV=test in Queue Mode #199

merged 4 commits into from
Jun 6, 2023

Conversation

3v0k4
Copy link
Contributor

@3v0k4 3v0k4 commented May 25, 2023

We want to make Queue Mode as easy as changing

bundle exec knapsack_pro:RUNNER

to

bundle exec knapsack_pro:queue:RUNNER

This PR removes the need to set RAILS_ENV=test like

RAILS_ENV=test bundle exec knapsack_pro:queue:RUNNER

I tried to set RAILS_ENV=test and RACK_ENV=test in two different places

  • right before calling the runner in the rake file
  • in the runner

but I got some (strange) errors when running bin/knapsack_pro_all.

In particular, the following error popped out to me (to reproduce remove RAILS_ENV=test \ from bin/knapsack_pro_queue_minitest and run bin/knapsack_pro_queue_minitest):

Error:
ArticlesControllerTest#test_should_get_index:
RuntimeError: Neutered Exception NoMethodError: assigns has been extracted to a gem. To continue using it,
        add `gem 'rails-controller-testing'` to your Gemfile.
    test/controllers/articles_controller_test.rb:11:in `block in <class:ArticlesControllerTest>'

The rails-controller-testing gem is in the test group, which made me think the app needs to be loaded WITH RAILS_ENV=test. So I decided to try by shelling out to a separate process by using sh. That did the trick and bin/knapsack_pro_all passes.

@@ -0,0 +1,106 @@
---
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe no cassettes at all should be recorded when the domain is fake. You could kill your http server running on 3000 port before you run tests.

@3v0k4 3v0k4 force-pushed the rails-env branch 2 times, most recently from 6e59811 to beb6966 Compare May 25, 2023 14:09
@3v0k4 3v0k4 self-assigned this May 25, 2023
@3v0k4
Copy link
Contributor Author

3v0k4 commented May 26, 2023

I researched more why

The rails-controller-testing gem is in the test group, which made me think the app needs to be loaded WITH RAILS_ENV=test. So I decided to try by shelling out to a separate process by using sh. That did the trick and bin/knapsack_pro_all passes.

When invoking bundle exec rake knapsack_pro:... this is the call order:

  • rake (in application.rb) loads the Rakefile
  • the Rakefile requires config/application.rb
  • config/application.rb calls Bundler.require(*Rails.groups)
  • Rails.groups returns [:default, :development] so the the test gems are not required

@@ -3,6 +3,8 @@ module Runners
module Queue
class CucumberRunner < BaseRunner
def self.run(args)
# ENV['RAILS_ENV'] = ENV['RACK_ENV'] = 'test'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are good to remove comments now since we establish solution with $PROGRAM_NAME.

Copy link
Member

@ArturT ArturT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are good to release it.

@3v0k4 3v0k4 marked this pull request as ready for review June 6, 2023 07:27
@3v0k4 3v0k4 changed the title feat: set RAILS_ENV/RACK_ENV to test in queue mode Set RAILS_ENV/RACK_ENV to test in Queue Mode Jun 6, 2023
@3v0k4 3v0k4 changed the title Set RAILS_ENV/RACK_ENV to test in Queue Mode Set RAILS_ENV=test/RACK_ENV=test in Queue Mode Jun 6, 2023
@3v0k4 3v0k4 merged commit 3ce7830 into master Jun 6, 2023
@3v0k4 3v0k4 deleted the rails-env branch June 6, 2023 07:40
emrojo added a commit to sanger/sequencescape that referenced this pull request Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants