minitest_rails_tools 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +43 -5
- data/lib/validation_matchers.rb +3 -3
- metadata +1 -1
data/README.md
CHANGED
@@ -3,11 +3,36 @@
|
|
3
3
|
|
4
4
|
This is a collection of little helpers to make working with Rails and Minitest a bit easier.
|
5
5
|
|
6
|
-
|
6
|
+
_NOTE: This is definitely a work in progress. I use this gem in two of my applications and will continue to add stuff to it, as well as fixing bugs._
|
7
7
|
|
8
8
|
|
9
|
-
|
9
|
+
## Installation
|
10
10
|
|
11
|
+
To install this gem, just put it in your `Gemfile`:
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem 'minitest', :require => false
|
15
|
+
gem 'minitest_rails_tools', :require => false
|
16
|
+
end
|
17
|
+
|
18
|
+
Afterwards require it in your `test_helper.rb`:
|
19
|
+
|
20
|
+
require 'minitest/autorun'
|
21
|
+
require 'minitest_rails_tools'
|
22
|
+
|
23
|
+
Alternatively, you could also just require certain parts of the tools:
|
24
|
+
|
25
|
+
require 'minitest/autorun'
|
26
|
+
require 'association_matchers'
|
27
|
+
require 'validation_matchers'
|
28
|
+
require 'helper_extension'
|
29
|
+
|
30
|
+
|
31
|
+
## Tools
|
32
|
+
|
33
|
+
### Association Matchers
|
34
|
+
|
35
|
+
This allows you to test standard Rails associations in your tests:
|
11
36
|
|
12
37
|
subject { FactoryGirl.create :foo }
|
13
38
|
|
@@ -16,13 +41,26 @@ It allows you to write stuff like this in your Minitest Spec:
|
|
16
41
|
must_have_many :bams
|
17
42
|
must_have_many_through :bars, :bams
|
18
43
|
must_have_and_belong_to_many :berks
|
44
|
+
|
45
|
+
|
46
|
+
### Validation Matchers
|
47
|
+
|
48
|
+
You may use this to test a couple of Rails' validations in your tests:
|
49
|
+
|
50
|
+
subject { FactoryGirl.create :foo }
|
19
51
|
|
20
|
-
must_validate_presence_of :
|
21
|
-
must_validate_uniqueness_of :
|
52
|
+
must_validate_presence_of :bar
|
53
|
+
must_validate_uniqueness_of :baz
|
22
54
|
|
23
|
-
|
55
|
+
|
56
|
+
### Helper Extension
|
57
|
+
|
58
|
+
This allows you to define a helper as your subject (and then call your helper methods on it):
|
24
59
|
|
25
60
|
subject { helper :foo_helper }
|
61
|
+
|
62
|
+
subject.do_my_stuff.must_equal 'OK'
|
63
|
+
|
26
64
|
|
27
65
|
|
28
66
|
Copyright © 2013 SUSE released under the MIT license. For full details see LICENSE included in this distribution.
|
data/lib/validation_matchers.rb
CHANGED
@@ -13,8 +13,8 @@ end
|
|
13
13
|
def must_validate_uniqueness_of(attribute_name)
|
14
14
|
it "validates_uniqueness_of :#{attribute_name.to_s.parameterize.underscore}" do
|
15
15
|
other = subject.class.new
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
other.send "#{attribute_name}=".to_sym, subject.send(attribute_name)
|
17
|
+
other.valid?.must_equal false
|
18
|
+
other.errors.messages[attribute_name.to_sym].must_include "has already been taken"
|
19
19
|
end
|
20
20
|
end
|