fizx-assertion_fu 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1 @@
1
+ Assertion_fu is a bunch of assert_* methods for Ruby's Test::Unit. Hopefully they're convenient. Look at the RDoc or CHANGELOG for a list.
@@ -0,0 +1,81 @@
1
+ # To gain access to the assertions, you can let your tests extend
2
+ # AssertionFu::AbstractTest, or you can include AssertionFu in your testing
3
+ # class.
4
+ module AssertionFu
5
+
6
+ # # To gain access to the assertions, you can let your tests extend
7
+ # # AssertionFu::AbstractTest, or you can include AssertionFu in your testing
8
+ # # class.
9
+ # class AbstractTest < Test::Unit::TestCase
10
+ # include AssertionFu
11
+ #
12
+ #
13
+ # def test_assertion_fu_included #:nodoc:
14
+ # assert true
15
+ # end
16
+ # end
17
+
18
+ # The contents of the file at the path should match the regex or
19
+ # include the string
20
+ def assert_file_includes(path, regex_or_string)
21
+ assert_file_exists(path)
22
+ content = File.read(path)
23
+ case regex_or_string
24
+ when Regexp
25
+ assert content =~ regex_or_string,
26
+ "#{path} doesn't match #{regex_or_string.inspect}"
27
+ else
28
+ assert content.include?(regex_or_string.to_s),
29
+ "#{path} doesn't include #{regex_or_string.inspect}"
30
+ end
31
+ end
32
+
33
+ def assert_includes(content, regex_or_string)
34
+ case regex_or_string
35
+ when Regexp
36
+ assert content =~ regex_or_string,
37
+ "#{content.inspect} doesn't match #{regex_or_string.inspect}"
38
+ else
39
+ assert content.include?(regex_or_string.to_s),
40
+ "#{content.inspect} doesn't include #{regex_or_string.inspect}"
41
+ end
42
+ end
43
+
44
+ def assert_length(expected, array)
45
+ assert_equal expected, array.length, "#{array.inspect} has length of #{array.length}, expected #{expected}"
46
+ end
47
+
48
+ def assert_file_doesnt_include(path, regex_or_string)
49
+ assert_file_exists(path)
50
+ content = File.read(path)
51
+ case regex_or_string
52
+ when Regexp
53
+ assert !(content =~ regex_or_string),
54
+ "#{path} matches #{regex_or_string.inspect}"
55
+ else
56
+ assert !content.include?(regex_or_string.to_s),
57
+ "#{path} includes #{regex_or_string.inspect}"
58
+ end
59
+ end
60
+
61
+ def assert_doesnt_include(content, regex_or_string)
62
+ case regex_or_string
63
+ when Regexp
64
+ assert !(content =~ regex_or_string),
65
+ "#{content.inspect} matches #{regex_or_string.inspect}"
66
+ else
67
+ assert !content.include?(regex_or_string.to_s),
68
+ "#{content.inspect} includes #{regex_or_string.inspect}"
69
+ end
70
+ end
71
+
72
+ def assert_file_exists(path)
73
+ assert File.exists?(path), "#{path} doesn't exist"
74
+ end
75
+
76
+ def assert_file_doesnt_exist(path)
77
+ assert !File.exists?(path), "#{path} exists"
78
+ end
79
+
80
+
81
+ end
@@ -0,0 +1,22 @@
1
+ require "test/unit"
2
+ require File.dirname(__FILE__) + "/../lib/assertion_fu"
3
+
4
+ class AssertionFuTest < Test::Unit::TestCase #:nodoc:
5
+ include AssertionFu
6
+
7
+ def test_file_exists
8
+ assert_file_exists(__FILE__)
9
+ assert_file_doesnt_exist(__FILE__ + "dfadsfa")
10
+ end
11
+
12
+ def test_file_includes
13
+ assert_file_includes(__FILE__, "__FILE__")
14
+ assert_file_doesnt_include(__FILE__, "12341234" + "asdeasf")
15
+ assert_file_includes(__FILE__, /__FILE__/)
16
+ assert_file_doesnt_include(__FILE__, /dafaf{999}/)
17
+ end
18
+
19
+ def test_length
20
+ assert_length 3, %w[a b c]
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fizx-assertion_fu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Maxwell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-12 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: kyle@kylemaxwell.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - README
26
+ - lib/assertion_fu.rb
27
+ - test/assertion_fu_test.rb
28
+ has_rdoc: true
29
+ homepage:
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.2.0
51
+ signing_key:
52
+ specification_version: 2
53
+ summary: Bonus Test::Unit assertions
54
+ test_files: []
55
+