etest 0.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -1,13 +0,0 @@
1
- Manifest
2
- Rakefile
3
- etest.gemspec
4
- init.rb
5
- lib/dlog_ext.rb
6
- lib/etest.rb
7
- lib/etest/assertions.rb
8
- lib/etest/grep.rb
9
- lib/module_ext.rb
10
- lib/string_ext.rb
11
- script/console
12
- script/rebuild
13
- test/test.rb
data/Rakefile CHANGED
@@ -12,18 +12,6 @@ task :rdoc do
12
12
  sh "rdoc -o doc/rdoc"
13
13
  end
14
14
 
15
- require 'rubygems'
16
- require 'rake'
17
- require 'echoe'
18
-
19
- Echoe.new('etest', '0.1') do |p|
20
- p.description = "Embedded tests"
21
- p.url = "http://github.com/pboy/etest"
22
- p.author = "pboy"
23
- p.email = "eno-pboy@open-lab.org"
24
- p.ignore_pattern = ["tmp/*"]
25
- # p.runtime_dependencies = %w(nokogiri htmlentities rdiscount)
26
- end
27
-
28
- Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
29
-
15
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext|
16
+ puts ext
17
+ load ext }
data/VERSION ADDED
@@ -0,0 +1,2 @@
1
+ 0.3.1
2
+
data/etest.gemspec CHANGED
@@ -2,21 +2,21 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{etest}
5
- s.version = "0.1"
5
+ s.version = "0.3.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["pboy"]
9
- s.date = %q{2010-02-28}
10
- s.description = %q{Embedded tests}
9
+ s.date = %q{2010-05-23}
10
+ s.description = %q{Embedded testing}
11
11
  s.email = %q{eno-pboy@open-lab.org}
12
- s.extra_rdoc_files = ["lib/dlog_ext.rb", "lib/etest.rb", "lib/etest/assertions.rb", "lib/etest/grep.rb", "lib/module_ext.rb", "lib/string_ext.rb"]
13
- s.files = ["Manifest", "Rakefile", "etest.gemspec", "init.rb", "lib/dlog_ext.rb", "lib/etest.rb", "lib/etest/assertions.rb", "lib/etest/grep.rb", "lib/module_ext.rb", "lib/string_ext.rb", "script/console", "script/rebuild", "test/test.rb"]
12
+ s.extra_rdoc_files = ["lib/dlog_ext.rb", "lib/etest.rb", "lib/etest/assertions.rb", "lib/etest/comparison_assertions.rb", "lib/etest/grep.rb", "lib/module_ext.rb", "lib/string_ext.rb", "tasks/echoe.rake"]
13
+ s.files = ["Manifest", "Rakefile", "VERSION", "gem.yml", "init.rb", "lib/dlog_ext.rb", "lib/etest.rb", "lib/etest/assertions.rb", "lib/etest/comparison_assertions.rb", "lib/etest/grep.rb", "lib/module_ext.rb", "lib/string_ext.rb", "script/console", "script/rebuild", "tasks/echoe.rake", "test/test.rb", "etest.gemspec"]
14
14
  s.homepage = %q{http://github.com/pboy/etest}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Etest"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = %q{etest}
18
- s.rubygems_version = %q{1.3.5}
19
- s.summary = %q{Embedded tests}
18
+ s.rubygems_version = %q{1.3.6}
19
+ s.summary = %q{Embedded testing}
20
20
 
21
21
  if s.respond_to? :specification_version then
22
22
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
data/gem.yml ADDED
@@ -0,0 +1,12 @@
1
+ gem:
2
+ description: Embedded testing
3
+ url: http://github.com/pboy/etest
4
+ author: pboy
5
+ email: eno-pboy@open-lab.org
6
+ ignore_pattern:
7
+ - "tmp/*"
8
+ - "**/.*"
9
+ # runtime_dependencies:
10
+ # - nokogiri
11
+ # - htmlentities
12
+ # - rdiscount
data/lib/dlog_ext.rb CHANGED
@@ -14,14 +14,49 @@ module Dlog
14
14
 
15
15
  HOME = ENV["HOME"] + "/"
16
16
 
17
+ def self.release!
18
+ @release = true
19
+ end
20
+
21
+ def self.release?
22
+ @release
23
+ end
24
+
25
+ def self.debug!
26
+ @release = false
27
+ end
28
+
29
+ def self.debug?
30
+ !@release
31
+ end
32
+
33
+ def self.quiet!
34
+ @quiet = true
35
+ end
36
+
37
+ def self.quiet?
38
+ @quiet
39
+ end
40
+
17
41
  def dlog(*args)
42
+ return if Dlog.quiet?
43
+
18
44
  msg = ""
19
45
  was_string = true
20
46
  args.map do |s|
21
47
  msg += was_string ? " " : ", " unless msg.empty?
22
48
  msg += ((was_string = s.is_a?(String)) ? s : s.inspect)
23
49
  end
24
- STDERR.puts "#{dlog_caller}: #{msg}"
50
+ STDERR.puts "#{Dlog.release? ? rlog_caller : dlog_caller} #{msg}"
51
+ end
52
+
53
+ def rlog_caller
54
+ if caller[1] =~ /^(.*):(\d+)/
55
+ file, line = $1, $2
56
+ "[" + File.basename(file).sub(/\.[^\.]*$/, "") + "]"
57
+ else
58
+ "[log]"
59
+ end
25
60
  end
26
61
 
27
62
  def dlog_caller
@@ -32,9 +67,9 @@ module Dlog
32
67
  file.gsub!(ROOT, ".") or
33
68
  file.gsub!(HOME, "~/")
34
69
 
35
- "#{file}(#{line})"
70
+ "#{file}(#{line}):"
36
71
  else
37
- "<dlog>"
72
+ "<dlog>:"
38
73
  end
39
74
  end
40
75
  end
@@ -2,6 +2,10 @@
2
2
  #
3
3
  # Some assertions
4
4
  module Etest::Assertions
5
+ def assert_not_equal(unexpected, actual)
6
+ assert unexpected != actual, "#{actual} equals #{unexpected}, when it shouldn't"
7
+ end
8
+
5
9
  def assert_respond_to(obj, *args)
6
10
  raise ArgumentError, "Missing argument(s)" if args.length < 1
7
11
 
@@ -45,6 +49,7 @@ module Etest::Assertions
45
49
  #
46
50
  #
47
51
  def assert_valid_xml(*args)
52
+ return unless libxml_installed?
48
53
  args.push @response.body if args.empty?
49
54
 
50
55
  args.each do |xml|
@@ -52,8 +57,27 @@ module Etest::Assertions
52
57
  end
53
58
  end
54
59
 
60
+ def assert_invalid_xml(*args)
61
+ return unless libxml_installed?
62
+ args.push @response.body if args.empty?
63
+
64
+ args.each do |xml|
65
+ assert !xml_valid?(xml), "XML should not be valid: #{xml}"
66
+ end
67
+ end
68
+
69
+ def libxml_installed?
70
+ return @libxml_installed unless @libxml_installed.nil?
71
+ @libxml_installed = begin
72
+ require "libxml"
73
+ true
74
+ rescue LoadError
75
+ STDERR.puts "*** Skipping xml_validation. Please install the 'libxml' gem"
76
+ false
77
+ end
78
+ end
79
+
55
80
  def xml_valid?(xml)
56
- require "libxml"
57
81
  LibXML::XML::Error.reset_handler
58
82
 
59
83
  LibXML::XML::Document.io StringIO.new(xml)
@@ -62,49 +86,99 @@ module Etest::Assertions
62
86
  false
63
87
  end
64
88
 
65
- def assert_invalid_xml(*args)
66
- args.push @response.body if args.empty?
67
-
68
- args.each do |xml|
69
- assert !xml_valid?(xml), "XML should not be valid: #{xml}"
70
- end
71
- end
72
-
73
89
  def assert_route(uri_path, params)
74
90
  assert_recognizes params, uri_path
75
91
  end
76
92
 
77
- def assert_raises_kind_of(klass, &block)
78
- begin
79
- yield
80
- assert false, "Should raise a #{klass} exception, but didn't raise at all"
81
- rescue klass
82
- assert $!.is_a?(klass), "Should raise a #{klass} exception, but raised a #{$!.class.name} exception"
93
+ def catch_exception_on(&block)
94
+ yield
95
+ nil
96
+ rescue Exception
97
+ $!
98
+ end
99
+
100
+ def assert_raise(klass, msg=nil, &block)
101
+ ex = catch_exception_on(&block)
102
+ if ex.nil?
103
+ assert false, msg || "Should raise a #{klass} exception, but didn't raise at all"
104
+ else
105
+ assert ex.class.name == klass.name, msg || "Should raise a #{klass} exception, but raised a #{ex.class.name} exception"
83
106
  end
84
107
  end
85
- end
86
-
87
-
88
- module Etest::Assertions::Etest
89
- #
90
- # this actually tests the existance of an assertion and one successful
91
- # assertion, nothing less, and nothing more...
92
- def test_asserts
93
- assert_respond_to "nsn", :upcase
94
- assert respond_to?(:assert_invalid)
95
- assert respond_to?(:assert_valid)
108
+
109
+ def assert_nothing_raised(msg=nil, &block)
110
+ ex = catch_exception_on(&block)
111
+ assert ex.nil?, msg || "Should not raise an exception, but raised a #{ex.class.name} exception"
112
+ end
113
+
114
+ def assert_raises_kind_of(klass, msg=nil, &block)
115
+ ex = catch_exception_on(&block)
116
+ if ex.nil?
117
+ assert false, msg || "Should raise a #{klass} exception, but didn't raise at all"
118
+ else
119
+ assert ex.is_a?(klass), msg || "Should raise a #{klass} exception, but raised a #{ex.class.name} exception"
120
+ end
121
+ end
122
+
123
+ def assert_not_nil(v)
124
+ assert !v.nil?, "Should be nil, but is an #{v.class.name} object"
96
125
  end
97
126
 
98
- class TestError < RuntimeError; end
127
+ def assert_file_exist(*paths)
128
+ paths.flatten.each do |path|
129
+ assert File.exist?(path), "Missing file: #{path}"
130
+ end
131
+ end
99
132
 
100
- def test_assert_raises_kind_of
101
- assert_raises_kind_of RuntimeError do
102
- raise TestError
133
+ def assert_file_doesnt_exist(*paths)
134
+ paths.flatten.each do |path|
135
+ assert !File.exist?(path), "File should not exist: #{path}"
103
136
  end
104
137
  end
105
138
 
106
- def test_xml
107
- assert_valid_xml <<-XML
139
+ def assert_not_equal(unexpected, actual)
140
+ assert unexpected != actual, "#{actual.inspect} should be != #{unexpected.inspect}"
141
+ end
142
+
143
+ def assert_not_nil(actual)
144
+ assert !actual.nil?, "#{actual.inspect} should not be nil"
145
+ end
146
+
147
+ def assert_nil(actual)
148
+ assert actual.nil?, "#{actual.inspect} should be nil"
149
+ end
150
+ end
151
+
152
+ class MiniTest::Unit::TestCase
153
+ include Etest::Assertions
154
+ end
155
+
156
+ unless defined?(ETEST_TEST)
157
+
158
+ module Etest::Assertions::Etest
159
+ #
160
+ # this actually tests the existance of an assertion and one successful
161
+ # assertion, nothing less, and nothing more...
162
+ def test_asserts
163
+ assert_respond_to "nsn", :upcase
164
+ assert respond_to?(:assert_invalid)
165
+ assert respond_to?(:assert_valid)
166
+ end
167
+
168
+ class TestError < RuntimeError; end
169
+
170
+ def test_assert_raises_kind_of
171
+ assert_raises_kind_of RuntimeError do
172
+ raise TestError
173
+ end
174
+ end
175
+
176
+ def test_assert_file_exist
177
+ assert_file_exist __FILE__
178
+ end
179
+
180
+ def test_xml
181
+ assert_valid_xml <<-XML
108
182
  <root>
109
183
  <p> lkhj </p>
110
184
  </root>
@@ -114,5 +188,7 @@ XML
114
188
  <root>
115
189
  <p> lkhj </p>
116
190
  XML
191
+ end
117
192
  end
118
193
  end
194
+
@@ -0,0 +1,47 @@
1
+ module Etest::ComparisonAssertions
2
+ def assert_lt(p1, p2)
3
+ assert(p1 < p2, "#{p1.inspect} should be less than #{p2.inspect} but is not")
4
+ end
5
+
6
+ def assert_le(p1, p2)
7
+ assert(p1 <= p2, "#{p1.inspect} should be less than or equal #{p2.inspect} but is not")
8
+ end
9
+
10
+ def assert_ge(p1, p2)
11
+ assert(p1 >= p2, "#{p1.inspect} should be greater than or equal #{p2.inspect} but is not")
12
+ end
13
+
14
+ def assert_gt(p1, p2)
15
+ assert(p1 > p2, "#{p1.inspect} should be greater than #{p2.inspect} but is not")
16
+ end
17
+
18
+ # for reasons of API completeness and orthogonality only.
19
+
20
+ def assert_eq(p1, p2)
21
+ assert_equal(p1, p2)
22
+ end
23
+
24
+ def assert_ne(p1, p2)
25
+ assert_not_equal(p1, p2)
26
+ end
27
+ end
28
+
29
+ class MiniTest::Unit::TestCase
30
+ include ::Etest::ComparisonAssertions
31
+ end
32
+
33
+ unless defined?(ETEST_TEST)
34
+
35
+ module Etest::ComparisonAssertions::Etest
36
+ # I don't know how to test asserts. This, at least, give (fake) C0 coverage
37
+ def test_comparision_assertions
38
+ assert_lt 1, 2
39
+ assert_le 1, 1
40
+ assert_ge 2, 2
41
+ assert_gt 2, 1
42
+ assert_eq 2, 2
43
+ assert_ne 1, 2
44
+ end
45
+ end
46
+
47
+ end
data/lib/etest.rb CHANGED
@@ -10,24 +10,38 @@ require File.dirname(__FILE__) + "/dlog_ext"
10
10
  # The Etest module contains methods to run etests.
11
11
  #
12
12
  module Etest
13
+ VERSION=File.read(File.dirname(__FILE__) + "/../VERSION")
13
14
  end
14
15
 
15
16
  require File.dirname(__FILE__) + "/etest/assertions"
17
+ require File.dirname(__FILE__) + "/etest/comparison_assertions"
16
18
 
17
19
  class MiniTest::Unit::TestCase
18
20
  def self.run_etests(*test_cases)
21
+ outside_etests = @@test_suites
22
+ reset
23
+
19
24
  MiniTest::Unit::TestCase.reset
20
25
 
21
26
  test_cases.each do |test_case|
22
27
  MiniTest::Unit::TestCase.inherited test_case
23
28
  end
24
29
 
25
- MiniTest::Unit.new.run([])
26
- MiniTest::Unit::TestCase.reset
30
+ MiniTest::Unit.new.run(ARGV.dup)
31
+ ensure
32
+ @@test_suites = outside_etests
27
33
  end
28
34
  end
29
35
 
30
36
  module Etest
37
+
38
+ class TestCase < MiniTest::Unit::TestCase
39
+ end
40
+
41
+ def self.autorun
42
+ auto_run
43
+ end
44
+
31
45
  def self.auto_run
32
46
  #
33
47
  # find all modules that are not named /::Etest$/, and try to load
@@ -56,11 +70,14 @@ module Etest
56
70
  #
57
71
  # convert an Etest moodule into a MiniTest testcase
58
72
  def self.to_test_case(mod)
59
- klass = Class.new MiniTest::Unit::TestCase
73
+ klass = Class.new TestCase
60
74
  klass.send :include, mod
61
75
  klass.send :include, Assertions
62
76
 
63
- mod.const_set("TestCase", klass)
77
+ Kernel.silent do
78
+ mod.const_set("TestCase", klass)
79
+ end
64
80
  klass
65
81
  end
66
82
  end
83
+
data/lib/module_ext.rb CHANGED
@@ -1,3 +1,12 @@
1
+ module Kernel
2
+ def self.silent(&block)
3
+ old_verbose, $VERBOSE = $VERBOSE, nil
4
+ yield
5
+ ensure
6
+ $VERBOSE = old_verbose
7
+ end
8
+ end
9
+
1
10
  #
2
11
  # TDD helpers for modules.
3
12
  class Module
@@ -19,14 +28,12 @@ class Module
19
28
  #
20
29
  # load a module by name.
21
30
  def self.by_name(name) #:nodoc:
22
- old_verbose, $VERBOSE = $VERBOSE, nil
23
-
24
- r = eval(name, nil, __FILE__, __LINE__)
25
- r if r.is_a?(Module) && r.name == name
31
+ Kernel.silent do
32
+ r = eval(name, nil, __FILE__, __LINE__)
33
+ r if r.is_a?(Module) && r.name == name
34
+ end
26
35
  rescue NameError, LoadError
27
36
  nil
28
- ensure
29
- $VERBOSE = old_verbose
30
37
  end
31
38
 
32
39
  #
data/lib/string_ext.rb CHANGED
@@ -13,15 +13,18 @@ class String
13
13
  end
14
14
  end
15
15
 
16
- module String::Etest
17
- def test_camelize
18
- assert_equal "x", "X".underscore
19
- assert_equal "xa_la_nder", "XaLaNder".underscore
20
- end
16
+ unless defined?(TEST_ETEST)
17
+
18
+ module String::Etest
19
+ def test_camelize
20
+ assert_equal "x", "X".underscore
21
+ assert_equal "xa_la_nder", "XaLaNder".underscore
22
+ end
21
23
 
22
- def test_underscore
23
- assert_equal "X", "x".camelize
24
- assert_equal "XaLaNder", "xa_la_nder".camelize
24
+ def test_underscore
25
+ assert_equal "X", "x".camelize
26
+ assert_equal "XaLaNder", "xa_la_nder".camelize
27
+ end
25
28
  end
26
- end
27
29
 
30
+ end
data/tasks/echoe.rake ADDED
@@ -0,0 +1,31 @@
1
+ #
2
+ # GEM settings
3
+ #
4
+ GEM_ROOT = File.expand_path("#{File.dirname(__FILE__)}/..")
5
+ if gem_config = YAML.load(File.read("#{GEM_ROOT}/gem.yml"))["gem"]
6
+ require 'echoe'
7
+
8
+ GEM_NAME = File.basename(GEM_ROOT)
9
+ Echoe.new(File.basename(GEM_ROOT), File.read("#{GEM_ROOT}/VERSION")) do |p|
10
+ gem_config.each do |k,v|
11
+ p.send "#{k}=",v
12
+ end
13
+ end
14
+
15
+ desc "Rebuild and install the gem"
16
+ task :rebuild => %w(manifest default build_gemspec package) do
17
+ gem = Dir.glob("pkg/*.gem").sort_by do |filename|
18
+ File.new(filename).mtime
19
+ end.last
20
+
21
+ puts "============================================="
22
+ puts "Installing gem..."
23
+
24
+ system "gem install #{gem} > /dev/null 2>&1"
25
+
26
+ puts ""
27
+ puts "I built and installed the gem for you. To upload, run "
28
+ puts
29
+ puts " gem push #{gem}"
30
+ end
31
+ end
data/test/test.rb CHANGED
@@ -2,10 +2,15 @@
2
2
  DIRNAME = File.expand_path File.dirname(__FILE__)
3
3
  Dir.chdir(DIRNAME)
4
4
 
5
+ ETEST_TEST=true
6
+
5
7
  #
6
8
  # initialize the gem
7
9
  require '../init'
8
10
 
11
+ require "#{DIRNAME}/etest_assertions.rb"
12
+ require "#{DIRNAME}/etest_string.rb"
13
+
9
14
  require 'logger'
10
15
  require 'rubygems'
11
16
  require 'ruby-debug'
@@ -20,6 +25,7 @@ RAILS_ENV="test"
20
25
  RAILS_ROOT="#{DIRNAME}"
21
26
 
22
27
  if !defined?(RAILS_DEFAULT_LOGGER)
28
+ require "fileutils"
23
29
  FileUtils.mkdir_p File.dirname(LOGFILE)
24
30
  RAILS_DEFAULT_LOGGER = Logger.new(LOGFILE)
25
31
  RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
@@ -46,7 +52,7 @@ end
46
52
 
47
53
  $etests_did_run = false
48
54
  Etest.reload
49
- Etest.auto_run
55
+ Etest.autorun
50
56
 
51
57
  unless $etests_did_run
52
58
  STDERR.puts "Something's wrong with etests :("
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etest
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.1"
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 1
9
+ version: 0.3.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - pboy
@@ -9,11 +14,11 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-28 00:00:00 +01:00
17
+ date: 2010-05-23 00:00:00 +02:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
16
- description: Embedded tests
21
+ description: Embedded testing
17
22
  email: eno-pboy@open-lab.org
18
23
  executables: []
19
24
 
@@ -23,23 +28,29 @@ extra_rdoc_files:
23
28
  - lib/dlog_ext.rb
24
29
  - lib/etest.rb
25
30
  - lib/etest/assertions.rb
31
+ - lib/etest/comparison_assertions.rb
26
32
  - lib/etest/grep.rb
27
33
  - lib/module_ext.rb
28
34
  - lib/string_ext.rb
35
+ - tasks/echoe.rake
29
36
  files:
30
37
  - Manifest
31
38
  - Rakefile
32
- - etest.gemspec
39
+ - VERSION
40
+ - gem.yml
33
41
  - init.rb
34
42
  - lib/dlog_ext.rb
35
43
  - lib/etest.rb
36
44
  - lib/etest/assertions.rb
45
+ - lib/etest/comparison_assertions.rb
37
46
  - lib/etest/grep.rb
38
47
  - lib/module_ext.rb
39
48
  - lib/string_ext.rb
40
49
  - script/console
41
50
  - script/rebuild
51
+ - tasks/echoe.rake
42
52
  - test/test.rb
53
+ - etest.gemspec
43
54
  has_rdoc: true
44
55
  homepage: http://github.com/pboy/etest
45
56
  licenses: []
@@ -56,20 +67,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
67
  requirements:
57
68
  - - ">="
58
69
  - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
59
72
  version: "0"
60
- version:
61
73
  required_rubygems_version: !ruby/object:Gem::Requirement
62
74
  requirements:
63
75
  - - ">="
64
76
  - !ruby/object:Gem::Version
77
+ segments:
78
+ - 1
79
+ - 2
65
80
  version: "1.2"
66
- version:
67
81
  requirements: []
68
82
 
69
83
  rubyforge_project: etest
70
- rubygems_version: 1.3.5
84
+ rubygems_version: 1.3.6
71
85
  signing_key:
72
86
  specification_version: 3
73
- summary: Embedded tests
87
+ summary: Embedded testing
74
88
  test_files: []
75
89