Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

rails console should not require minitest/unit #6907

Closed
mlartz opened this Issue · 16 comments

5 participants

@mlartz

rails/railties/lib/rails/console/app.rb, lines 2 and 6 require and use Test::Unit, respectively. This prevents me from running rails console in production (fails requiring 'minitest/unit'), which is useful for debugging our live deployment databases. Is there a problem with either removing this dependency or checking for RAILS_ENV before requiring/using Test::Unit?

require 'active_support/all'
require 'active_support/test_case'
require 'action_controller'

# work around the at_exit hook in test/unit, which kills IRB
Test::Unit.run = true if Test::Unit.respond_to?(:run=)
@rafaelfranca

I didn't get. Is Rails console requiring minitest/unit in 3.2.x? Or are you using master?

@steveklabnik
Collaborator

Yeah, minitest is included with Ruby 1.9, so require 'minitest/unit' shouldn't ever fail. If you're on master, then 1.8 isn't supported, so this isn't a bug. If you're on 3.2, then we support 1.8, so this would be a bug.

@mlartz

I'm on Rails 3.2.2 using Ruby 1.9.3, but I'm trying to use the new Fedora 17 Ruby RPM spec files (thanks @voxik, @bkabrda), which extract the stdlib "gems" (i.e. the "gems" included with Ruby such as minitest, json, and a bunch of others) from the base install, treating them similar to real gems. Unfortunately, because they are bundled with Ruby, there are some assumptions about their availability as part of the stdlib, even though they are treated as some odd hybird of stdlib and gems. See the following for more explanation:

http://bugs.ruby-lang.org/issues/6123
http://bugs.ruby-lang.org/issues/6124
http://bugs.ruby-lang.org/issues/5481

So it is partially a Ruby problem that looks like its on track to be partially fixed in 1.9.3 and correctly fixed in 2.

But my Rails question remains ... why is 'rails console' dependent on a test framework? Can it be removed?

@steveklabnik
Collaborator

which extract the stdlib "gems" from the base install, treating them similar to real gems.

And people wonder why nobody uses the system package managers when installing Ruby...

Can it be removed?

Still a totally valid question. I bet the answer is "because it's always available so why not".

The test_case line was added by @jeremy here.

@voxik

@steveklabnik Sorry, but that is not very constructive answer :/ StdLib contains plenty of other libraries which are not required. I hope you are not going to require all the libraries to solve this issue, since they are also always available.

BTW, there is available never minitest version at rubygems.org, have you tried to used them in your project? Are you sure that the correct (newest) version of minitest is always used for your testing?

@steveklabnik
Collaborator

@voxlk what I mean is that, as a Rubyist, I expect the full standard library to be available for any given copy of Ruby. A Ruby 1.9 without minitest is just broken.

correct (newest)

The newest isn't correct unless I explicitly require it.

@voxik

@steveklabnik the question was "why is 'rails console' dependent on a test framework? Can it be removed?" and your answer was "because it's always available so why not". The question and answer are not aligned IMO. The question was definitely not if Ruby without minitest is broken or not. There are different threads to discuss this topic an I can assure you that I will persuade the correct solution.

@steveklabnik
Collaborator

Oh. I'm not saying that it's right, I'm just speculating. I didn't introduce this behavior. Sorry, I thought you were talking about the assumption that it'd be available.

What I was trying to say was "I have no idea, but it looks like @jeremy may have been the one that did it, let's see what he says."

@voxik

ping ... any news about this matter?

@rafaelfranca

I'm not sure if this was the reason to add the test framework in the rails console but for me it make sense. With that line you can you assertion and some test helpers in your console.

@robin850
Collaborator

Maybe I can reopen my pull request and put in the Gemfile template (temporary ; till a solution will be found) a condition with a Regexp on the RUBY_PLATFORM constant ; if it contains "linux", then add an entry to Gemfile containing the minitest gem ?

@steveklabnik
Collaborator

Putting a gem in the gemfile is far, far more drastic than removing those lines or including them only if Minitest exists.

@steveklabnik
Collaborator

a condition with a Regexp on the RUBY_PLATFORM constant ; if it contains "linux", then add an entry to Gemfile containing the minitest gem ?

Not at all, only Fedora is stupid....errr, 'unique' enough to do this. (I shouldn't speak so quickly, Debian probably does too. rimshot)

Do something like this:

if defined?(MiniTest)
...
@robin850
Collaborator

@steveklabnik : Does I reopen my pull request adding this ?

@steveklabnik steveklabnik referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@steveklabnik
Collaborator

@robin850 I just did it.

@steveklabnik steveklabnik referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@rafaelfranca

We decided to not defensive programming in this case. The require is needed because Test::Unit kills IRB.

If you are using a broken Ruby, you'll need to add the missing gems in your Gemfile,

@smarterclayton smarterclayton referenced this issue in discourse/discourse
Merged

Add minitest to gemfile #238

@jacargentina jacargentina referenced this issue in gitlabhq/gitlabhq
Closed

For running tests i have to edit Gemfile #3826

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.