bcardarella / valid_attribute

Minimalist validation BDD for ActiveModel specs
178 stars 18 forks source link

minitest-rails 0.9 issue? #29

Closed tklenke closed 11 years ago

tklenke commented 11 years ago

I am having trouble getting this to work with minitest 4.7.5, minitest-rails 0.9.2 and minitest-matchers 1.3.0, rails 3.2.15

If I replace for example MiniTest::Rails::ActiveSupport::TestCase with ActiveSupport::TestCase per https://github.com/blowmage/minitest-rails/wiki/Upgrading-to-0.9 Then I get a 'have_valid' method does not exist.

Is this gem still supported? If not what is the new preferred method for testing attribute validation.

bcardarella commented 11 years ago

@tklenke could you put together an example app for me to work with? That will be this fixed the quickest

tklenke commented 11 years ago

Thank you for looking at this. https://github.com/tklenke/valid_attribute_test FYI, I use JRuby, so you may need to change the GEMFILE a bit. Perhaps JRuby is the issue, but should not be.

bcardarella commented 11 years ago

I apologize for taking a few days to get back to you. The state of Minitest with the migration from Minitest 4.x to Minitest 5.x has created some issues with what we can and cannot reasonably support in the same gem. To that end, there is a work around to get what you want:

In your tests/test_helper.rb

class ActiveSupport::TestCase
  include ::ValidAttribute::Method
end

and in your unit test you will need to use subject.wont and subject.must

it { subject.wont have_valid(:name).when(nil, '') }
tklenke commented 11 years ago

thank you. Works as advertised. Perhaps an update to the readme file is in order?