simple_assertions 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +5 -0
- data/lib/simple_assertions/assert_errors_on.rb +12 -10
- data/lib/simple_assertions/assert_raises.rb +1 -1
- data/lib/simple_assertions/minitest.rb +1 -1
- data/lib/simple_assertions/testunit.rb +2 -2
- data/lib/simple_assertions/version.rb +1 -1
- data/lib/simple_assertions.rb +5 -0
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
Useful assertions for test/unit
|
4
4
|
|
5
|
+
Gem[https://rubygems.org/gems/simple_assertions] |
|
6
|
+
Source[https://github.com/neopoly/simple_assertions] |
|
7
|
+
RDoc[http://rubydoc.info/github/neopoly/simple_assertions/master/file/README.rdoc]
|
8
|
+
|
5
9
|
== Usage
|
6
10
|
|
7
11
|
=== minitest
|
@@ -23,6 +27,7 @@ Or with more control what to include:
|
|
23
27
|
require 'simple_assertions'
|
24
28
|
|
25
29
|
class MiniTest::TestCase
|
30
|
+
# include *SimpleAssertions.all
|
26
31
|
include SimpleAssertions::AssertErrorsOn
|
27
32
|
include SimpleAssertions::AssertRaises
|
28
33
|
end
|
@@ -5,17 +5,19 @@ module SimpleAssertions
|
|
5
5
|
# Assert errors on given parameters.
|
6
6
|
# It call #valid? on +object+ unless called with a block.
|
7
7
|
#
|
8
|
-
#
|
9
|
-
# assert_errors_on record, :email => 2
|
10
|
-
# assert_errors_on record, :email => "is blank"
|
11
|
-
# assert_errors_on record, :email => /blank/
|
12
|
-
# assert_errors_on record, :email => ["is blank", "is invalid"]
|
13
|
-
# assert_errors_on record, :email, :plz => 2
|
14
|
-
# assert_errors_on record, [:username, :email] => "is blank"
|
8
|
+
# == Example
|
15
9
|
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
10
|
+
# assert_errors_on record, :email
|
11
|
+
# assert_errors_on record, :email => 2
|
12
|
+
# assert_errors_on record, :email => "is blank"
|
13
|
+
# assert_errors_on record, :email => /blank/
|
14
|
+
# assert_errors_on record, :email => ["is blank", "is invalid"]
|
15
|
+
# assert_errors_on record, :email, :plz => 2
|
16
|
+
# assert_errors_on record, [:username, :email] => "is blank"
|
17
|
+
#
|
18
|
+
# assert_errors_on record, :email => 1 do
|
19
|
+
# assert record.save
|
20
|
+
# end
|
19
21
|
def assert_errors_on(object, *attributes_or_hash)
|
20
22
|
if block_given?
|
21
23
|
yield
|
@@ -20,7 +20,7 @@ module SimpleAssertions
|
|
20
20
|
attributes = args.last.is_a?(Hash) ? args.pop : {}
|
21
21
|
exception = super(*args, &block).tap do |exception|
|
22
22
|
attributes.each do |attribute, expected|
|
23
|
-
actual =
|
23
|
+
actual = exception.send(attribute)
|
24
24
|
assert_operator expected, :===, actual
|
25
25
|
end
|
26
26
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
Test::Unit::TestCase
|
2
|
-
include SimpleAssertions
|
1
|
+
class Test::Unit::TestCase do
|
2
|
+
include *SimpleAssertions.all
|
3
3
|
end
|
data/lib/simple_assertions.rb
CHANGED