Skip to content

Loading…

description strings should match MiniTest::Spec and not brake the tests #73

Closed
wants to merge 1 commit into from

2 participants

@agirorn

When the description is a String it results in trying to match it ActiveRecord::Base which results in

gems/minitest-rails-0.1.3/lib/minitest/rails/active_support.rb:30:in `<': comparison of String with Class failed (ArgumentError)
        from gems/minitest-rails-0.1.3/lib/minitest/rails/active_support.rb:30:in `block in <class:TestCase>'
describe 'Some string' do
  it 'routs to ' do
    assert true
  end
end
@blowmage

I don't understand why this was added. MiniTest::Spec is the default spec type. What does this change do for us?

Yes MiniTest::Spec is the default type and it works if ActiveRecord it not defined or if alla your spec describes are Classes or modules

If you have a ActiveRecord in the project and the describe block with a stringlike this

require "minitest_helper"

describe 'Compute some numbers' do
  it "compute 1" do
    1.must_equal 1
  end
end

you get this Exception

/Users/agir/.rvm/gems/ruby-1.9.3-p194@exception_in_rails/gems/minitest-rails-0.1.3/lib/minitest/rails/active_support.rb:30:in `<': comparison of String with Class failed (ArgumentError)
    from /Users/agir/.rvm/gems/ruby-1.9.3-p194@exception_in_rails/gems/minitest-rails-0.1.3/lib/minitest/rails/active_support.rb:30:in `block in <class:TestCase>'
    from /Users/agir/.rvm/gems/ruby-1.9.3-p194@exception_in_rails/gems/minitest-3.4.0/lib/minitest/spec.rb:126:in `call'
    from /Users/agir/.rvm/gems/ruby-1.9.3-p194@exception_in_rails/gems/minitest-3.4.0/lib/minitest/spec.rb:126:in `block in spec_type'
    from /Users/agir/.rvm/gems/ruby-1.9.3-p194@exception_in_rails/gems/minitest-3.4.0/lib/minitest/spec.rb:124:in `each'
    from /Users/agir/.rvm/gems/ruby-1.9.3-p194@exception_in_rails/gems/minitest-3.4.0/lib/minitest/spec.rb:124:in `find'
    from /Users/agir/.rvm/gems/ruby-1.9.3-p194@exception_in_rails/gems/minitest-3.4.0/lib/minitest/spec.rb:124:in `spec_type'
    from /Users/agir/.rvm/gems/ruby-1.9.3-p194@exception_in_rails/gems/minitest-3.4.0/lib/minitest/spec.rb:65:in `describe'
    from /Users/agir/tmp/exception_in_rails/test/unit/senario_one_test.rb:3:in `<top (required)>'
    from /Users/agir/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `require'
    from /Users/agir/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
    from /Users/agir/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `each'
    from /Users/agir/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `block in <main>'
    from /Users/agir/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `select'
    from /Users/agir/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [/Users/agir/.rvm/rubies/ruby-1.9.3-p194/bi...]

Tasks: TOP => test:units
(See full trace by running task with --trace)

I know the exception dose not occur when you run the gems test suite, but if you run just the test i made you can see how this dose not delegate to MiniTest::Spec.

I never got it working for the hole test sute because this test has to load ActiveRecord before it loads the minitest-rails code.

@blowmage
Owner

Gotcha. Thanks for the clarification. Not sure why we didn't catch that before. I pulled your code and modified it a bit. Thanks for the fix!

@blowmage blowmage added a commit that closed this pull request
@agirorn agirorn Fix bug with registering AS:TestCase [closes #73]
Let description Strings match MiniTest::Spec even if ActiveRecord::Base is defined.
Add conditional to the register_spec_type check, like the other checks.
Added tests.
Thanks to @agirorn for the submission!
b4ee8bb
@blowmage blowmage closed this in b4ee8bb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 9, 2012
  1. @agirorn
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 1 deletion.
  1. +1 −1 lib/minitest/rails/active_support.rb
  2. +16 −0 test/rails/test_active_record_spec_type.rb
View
2 lib/minitest/rails/active_support.rb
@@ -27,7 +27,7 @@ def assert_block msg = nil
if defined?(ActiveRecord::Base)
# Use AS::TestCase for the base class when describing a model
register_spec_type(self) do |desc|
- desc < ActiveRecord::Base
+ desc < ActiveRecord::Base unless desc.is_a? String
end
end
View
16 test/rails/test_active_record_spec_type.rb
@@ -0,0 +1,16 @@
+require "minitest/autorun"
+require "active_record"
+require "minitest-rails"
+require "minitest/rails/active_support"
+
+class TestActiveRecordSpecType < MiniTest::Unit::TestCase
+ class AModel < ActiveRecord::Base; end
+
+ def test_spec_type_resolves_for_matching_strings
+ assert_equal MiniTest::Spec.spec_type(AModel), MiniTest::Rails::ActiveSupport::TestCase
+ end
+
+ def test_string_descriptions_continue_to_match_minitest_spec
+ assert_equal MiniTest::Spec.spec_type('some string'), MiniTest::Spec
+ end
+end
Something went wrong with that request. Please try again.