ValidAttribute not included in ActiveSupport::TestCase

#35 · closed · 4 comments

View on GitHub ↗

jimmykarily

According to the [docs](http://edgeguides.rubyonrails.org/testing.html#unit-testing-your-models), the class of model tests in rails are ActiveSupport::TestCase. ::ValidAttribute::Method [is not automatically included](https://github.com/bcardarella/valid_attribute/blob/master/lib/valid_attribute/minitest.rb) in this class. I can do this in the test_helper of course. I'm only wondering if that is the right way to go or my setup is wrong somehow.

Comments

bcardarella

Are you on latest Rails? It could be related to the new Minitest.

jimmykarily

Yes I'm trying to migrate from 4.0.10 to 4.1.7 rails-4.1.7 minitest-5.4.2 valid_attribute-2.0.0 I added this in test_helper ``` class ActiveSupport::TestCase ... include ::ValidAttribute::Method ... end ``` and has_valid is no longer undefined but still it does not work with implicit subject as: ``` describe User do subject { User.new } describe "attributes" do it { must have_valid(:first_name).when("John") } end end ``` It seem that the subject passed [here](https://github.com/bcardarella/valid_attribute/blob/master/lib/valid_attribute/matcher.rb#L35) is not the subject but the test class itself. This seems like a minitest-matchers issue that's why I only referred to the include issue above.

bcardarella

can you try master branch?

jimmykarily

I'm still getting the same error. This is the test I run (pry is there on purpose, see next code snippet): ``` require 'minitest_helper' describe User do subject { User.new } it { binding.pry;subject.must have_valid(:first_name).when("John") } end ``` and this is form the pry console: ``` [6] pry(#<User>)> self.class.ancestors => [#<Class:0x0000000cada708>, ActiveSupport::TestCase, CustomRoutesHelpers, Minitest::Rails::ConstantLookup, Minitest::Spec::DSL::InstanceMethods, ActiveSupport::Testing::TimeHelpers, ActiveSupport::Testing::Deprecation, ActiveSupport::Testing::Assertions, ActiveSupport::Callbacks, ActiveSupport::Testing::SetupAndTeardown, ActiveSupport::Testing::TaggedLogging, Minitest::Test, Mocha::Integration::MiniTest::Adapter, Mocha::API, Mocha::Hooks, Mocha::ParameterMatchers, Minitest::Guard, Minitest::Test::LifecycleHooks, Minitest::Assertions, Minitest::Runnable, Object, Minitest::Rails::Expectations, Metaclass::ObjectMethods, Mocha::ObjectMethods, Minitest::Expectations, PP::ObjectMixin, Delayed::MessageSending, RequireAll, Nori::CoreExt::Object, ActiveSupport::Dependencies::Loadable, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject] ``` You can see that [Minitest::Spec](https://github.com/bcardarella/valid_attribute/commit/cf424fcf0e660bbb115f0eef8383a87b90f5aa86#diff-4c2b1b50b4a695731322f8ad63b4c0cbR1) is not in the ancestors of this class. To be totally clear, I also have minitest-rails in my Gemfile (version 2.1.1). Although minitest is there anyway, I need this line to enable the spec DSL. Maybe this is changing the ancestors in some way, I don't know just thinking out loud. Update: Maybe [this](http://blowmage.com/2013/03/18/minitest-rails-roadmap) sheds some light on what's going on