public
Fork of pelargir/rspec_validation_expectations
Description: Adds several handy expectations for testing ActiveRecord model validations.
Homepage:
Clone URL: git://github.com/jwhitmire/rspec_validation_expectations.git
100644 70 lines (48 sloc) 2.017 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
= rspec_validation_expectations
 
Adds several handy expectations for testing ActiveRecord model validations.
 
== Dependencies
 
Requires the validation_reflection plugin:
 
  script/plugin install git://github.com/redinger/validation_reflection.git
 
== Installation
 
Install the gem directly:
 
  gem sources -a http://gems.github.com (you only have to do this once)
  sudo gem install pelargir-rspec_validation_expectations
  
Or install the gem in your Rails project:
  
  gem sources -a http://gems.github.com
  script/plugin install pelargir-rspec_validation_expectations
 
Or clone the project:
 
  git clone git://github.com/pelargir/rspec_validation_expectations.git
 
== Usage
 
Ensure that validations and assocations are properly defined in your models:
 
  describe User do
    it_should_validate_presence_of :first_name, :last_name, :email
    it_should_validate_numericality_of :zip
    it_should_validate_uniqueness_of :email
    it_should_validate_inclusion_of :gender, :in => %w(Male Female)
    
    # tests that User.count increases by 1
    it_should_be_createable :with => {:first_name => 'Ed', :last_name => 'The Duck', :email => 'a@b.com'}
    
    it_should_belong_to :employer
    it_should_have_many :friends, :romans, :countrymen
    it_should_have_one :account
    it_should_have_and_belong_to_many :comments
  end
  
Which gives you:
 
ruby script/spec --format s spec/models/user_spec.rb:
 
User
- should validate presence of first name
- should validate presence of last name
- should validate presence of email
- should validate numericality of zip
- should validate uniqueness of email
- should validate inclusion of gender as one of Male or Female
- should be creatable
- should belong to employer
- should have many friends
- should have many romans
- should have many countrymen
- should have one account
- should have and belong to many comments
 
== Resources
 
Repository: http://github.com/pelargir/rspec_validation_expectations/
Blog: http://matthewbass.com
Author: Matthew Bass