Closed jimmykarily closed 10 years ago
Are you on latest Rails? It could be related to the new Minitest.
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 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.
can you try master branch?
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 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 sheds some light on what's going on
According to the docs, the class of model tests in rails are ActiveSupport::TestCase. ::ValidAttribute::Method is not automatically included 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.