simple_assertions 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in test-unit-assertions.gemspec
4
+ gemspec
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = Assertions for test/unit
2
+
3
+ Useful assertions for test/unit
4
+
5
+ == Usage
6
+
7
+ To include all assertions for test/unit do:
8
+
9
+ require 'simple_assertions/testunit'
10
+
11
+
12
+ Or with more control what to include:
13
+
14
+ require 'simple_assertions'
15
+
16
+ class Test::Unit::TestCase
17
+ include SimpleAssertions::AssertErrorsOn
18
+ end
19
+
20
+
21
+ == Assertions
22
+
23
+ * assert_errors_on
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,53 @@
1
+ module SimpleAssertions
2
+ module AssertErrorsOn
3
+ # http://gist.github.com/49013
4
+ #
5
+ # Assert errors on given parameters.
6
+ # It call #valid? on +object+ unless called with a block.
7
+ #
8
+ # assert_errors_on record, :email
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"
15
+ #
16
+ # assert_errors_on record, :email => 1 do
17
+ # assert record.save
18
+ # end
19
+ def assert_errors_on(object, *attributes_or_hash)
20
+ if block_given?
21
+ yield
22
+ else
23
+ assert !object.valid?, "#{object.inspect} should be invalid."
24
+ end
25
+
26
+ hash = attributes_or_hash[-1].is_a?(Hash) ? attributes_or_hash.pop : {}
27
+ attributes_or_hash.each { |field| hash[field] = 1 }
28
+
29
+ hash.each do |fields, pattern|
30
+ Array.wrap(fields).each do |field|
31
+ errors = Array.wrap(object.errors[field])
32
+
33
+ case pattern
34
+ when Fixnum
35
+ assert_equal pattern, errors.size,
36
+ "#{pattern} error(s) expected for #{object.class}.#{field} but got #{errors.inspect}."
37
+ when Regexp
38
+ assert errors.all? { |message| pattern.match(message) },
39
+ "expected to match #{pattern} for #{object.class}.#{field} but got #{errors.inspect}."
40
+ when String
41
+ assert_equal [ pattern ], errors,
42
+ "#{pattern.inspect} error(s) expected for #{object.class}.#{field} but got #{errors.inspect}."
43
+ when Array
44
+ assert_equal pattern.sort, errors.sort,
45
+ "#{pattern.inspect} error(s) expected for #{object.class}.#{field} but got #{errors.inspect}."
46
+ else
47
+ fail "unknown type #{pattern.inspect}"
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ Test::Unit::TestCase.class_eval do
2
+ include SimpleAssertions::AssertErrorsOn
3
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleAssertions
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ module SimpleAssertions
2
+ autoload :AssertErrorsOn, 'simple_assertions/assert_errors_on'
3
+
4
+ autoload :VERSION, 'simple_assertions/version'
5
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "simple_assertions"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "simple_assertions"
7
+ s.version = SimpleAssertions::VERSION
8
+ s.authors = ["Peter Suschlik"]
9
+ s.email = ["ps@neopoly.de"]
10
+ s.homepage = "https://github.com/neopoly/test-unit-assertions"
11
+ s.summary = %q{Useful assertions for test/unit}
12
+ s.description = %q{}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # specify any dependencies here; for example:
20
+ # s.add_development_dependency "rspec"
21
+ # s.add_runtime_dependency "test-unit"
22
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_assertions
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Peter Suschlik
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-26 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: ""
22
+ email:
23
+ - ps@neopoly.de
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - README.rdoc
34
+ - Rakefile
35
+ - lib/simple_assertions.rb
36
+ - lib/simple_assertions/assert_errors_on.rb
37
+ - lib/simple_assertions/testunit.rb
38
+ - lib/simple_assertions/version.rb
39
+ - simple_assertions.gemspec
40
+ homepage: https://github.com/neopoly/test-unit-assertions
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.10
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Useful assertions for test/unit
73
+ test_files: []
74
+