Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add minitest support #13

Merged
merged 1 commit into from Sep 5, 2011
Jump to file or symbol
Failed to load files and symbols.
+48 −0
Split
View
@@ -36,6 +36,17 @@ require 'shoulda-context'
require 'valid_attribute'
```
+If you want to you use it with `MiniTest::Spec` you can use either `shoulda-context` (see above) or [minitest-matchers](https://github.com/zenspider/minitest-matchers):
+
+```ruby
+# Gemfile
+gem 'minitest-matchers'
+
+# test_helper.rb
+require 'minitest/matchers'
+require 'valid_attribute'
+```
+
## Usage ##
Instead of having validation specific matchers `ValidAttribute` only cares if the attribute is valid under certain circumstances
@@ -89,6 +100,27 @@ class UserTest < Test::Unit::TestCase
# Using .when is optional. Without it, the existing value is examined.
should_not have_valid(:email)
end
+
+# Minitest::Matchers
+require 'minitest/matchers'
+describe User do
+ subject { User.new }
+
+ # The .when method can take any number of values that you want to pass
+ must { have_valid(:email).when('test@test.com', 'test+spam@gmail.com') }
+ wont { have_valid(:email).when('fail', 123) }
+ must { have_valid(:name).when('TestName') }
+ wont { have_valid(:name).when('Test') }
+
+ describe 'password' do
+ subject { User.new(:password_confirmation => 'password') }
+ must { have_valid(:password).when('password') }
+ wont { have_valid(:password).when(nil) }
+ end
+
+ # Using .when is optional. Without it, the existing value is examined.
+ wont have_valid(:email)
+end
```
## Custom Models ##
View
@@ -7,6 +7,8 @@ class NoValues < StandardError; end
if defined?(RSpec)
require 'valid_attribute/rspec'
+elsif defined?(MiniTest::Matchers)
+ require 'valid_attribute/minitest'
else
require 'valid_attribute/test_unit'
end
@@ -0,0 +1,3 @@
+class MiniTest::Spec
+ extend ::ValidAttribute::Method
+end
View
@@ -0,0 +1,10 @@
+require 'spec_helper'
+require 'minitest/spec'
+require 'valid_attribute/minitest'
+
+describe 'MiniTest::Spec' do
+ it '.have_valid' do
+ MiniTest::Spec.have_valid(:name).should be_instance_of(ValidAttribute::Matcher)
+ end
+end
+
View
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rspec'
s.add_development_dependency 'bourne'
+ s.add_development_dependency 'minitest-matchers'
if RUBY_VERSION >= '1.9'
if RUBY_VERSION <= '1.9.2'
s.add_development_dependency 'ruby-debug19'