test_env 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.md +52 -0
- data/Rakefile +43 -0
- data/VERSION +1 -0
- data/lib/test_env.rb +107 -0
- data/test/helper.rb +10 -0
- data/test/test_test_env.rb +5 -0
- data/test_env.gemspec +51 -0
- metadata +73 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Ryan Lewis
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# test_env
|
2
|
+
|
3
|
+
My own personal test environment
|
4
|
+
|
5
|
+
# Example
|
6
|
+
|
7
|
+
require 'test_env'
|
8
|
+
|
9
|
+
class User
|
10
|
+
attr_accessor :username, :email
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"#{@username} - #{@email}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class UserTest < TestEnvironment
|
18
|
+
test_instance_of User do |user|
|
19
|
+
|
20
|
+
# Setups run once before any assertions ever take place
|
21
|
+
# You can have multiple setup blocks
|
22
|
+
setup do
|
23
|
+
@username = 'default'
|
24
|
+
@email = 'default@domain.com'
|
25
|
+
end
|
26
|
+
|
27
|
+
assert 'output str should be correct' do
|
28
|
+
user.to_s == 'default - default@domain.com'
|
29
|
+
end
|
30
|
+
|
31
|
+
assert 'output str should still be correct' do
|
32
|
+
user.username = 'c00lryguy'
|
33
|
+
user.email = 'c00lryguy@gmail.com'
|
34
|
+
|
35
|
+
user.to_s == 'c00lryguy - c00lryguy@gmail.com'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
## Note on Patches/Pull Requests
|
41
|
+
|
42
|
+
* Fork the project.
|
43
|
+
* Make your feature addition or bug fix.
|
44
|
+
* Add tests for it. This is important so I don't break it in a
|
45
|
+
future version unintentionally.
|
46
|
+
* Commit, do not mess with rakefile, version, or history.
|
47
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
48
|
+
* Send me a pull request. Bonus points for topic branches.
|
49
|
+
|
50
|
+
## Copyright
|
51
|
+
|
52
|
+
Copyright (c) 2010 Ryan Lewis. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
#===--- Test
|
5
|
+
|
6
|
+
require 'rake/testtask'
|
7
|
+
Rake::TestTask.new(:test) do |test|
|
8
|
+
test.libs << 'lib' << 'test'
|
9
|
+
test.pattern = 'test/**/test_*.rb'
|
10
|
+
test.verbose = true
|
11
|
+
end
|
12
|
+
task :test => :check_dependencies
|
13
|
+
|
14
|
+
#===--- Reek
|
15
|
+
|
16
|
+
begin
|
17
|
+
require 'reek/rake/task'
|
18
|
+
Reek::Rake::Task.new do |t|
|
19
|
+
t.fail_on_error = true
|
20
|
+
t.verbose = false
|
21
|
+
t.source_files = 'lib/**/*.rb'
|
22
|
+
end
|
23
|
+
rescue LoadError
|
24
|
+
puts "Reek (or a dependency) not available. Install it with: gem install reek"
|
25
|
+
end
|
26
|
+
|
27
|
+
#===--- Jeweler
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'jeweler'
|
31
|
+
Jeweler::Tasks.new do |gem|
|
32
|
+
gem.name = "test_env"
|
33
|
+
gem.summary = %Q{My own personal test environment}
|
34
|
+
gem.description = %Q{My own personal test environment}
|
35
|
+
gem.email = "c00lryguy@gmail.com"
|
36
|
+
gem.homepage = "http://github.com/c00lryguy/test_env"
|
37
|
+
gem.authors = ["Ryan Lewis"]
|
38
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
39
|
+
end
|
40
|
+
Jeweler::GemcutterTasks.new
|
41
|
+
rescue LoadError
|
42
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
43
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/lib/test_env.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
class TestEnvironment
|
2
|
+
class Assertion
|
3
|
+
def initialize(msg=nil, blk)
|
4
|
+
@msg, @blk, @passed = msg, blk, false
|
5
|
+
end
|
6
|
+
|
7
|
+
def call
|
8
|
+
@passed = @blk.call
|
9
|
+
@failed = !@passed
|
10
|
+
# http://toolmantim.com/thoughts/bangbang_your_nil_is_dead
|
11
|
+
# @passed = !!@blk.call
|
12
|
+
end
|
13
|
+
|
14
|
+
def passed?; @passed; end
|
15
|
+
def failed?; @failed; end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
result = ""
|
19
|
+
pass_fail = { true => 'PASSED', false => 'FAILED'}
|
20
|
+
|
21
|
+
result << "#{pass_fail[@passed]}"
|
22
|
+
result << "\n #{@msg}" unless @msg.nil?
|
23
|
+
|
24
|
+
result
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Assertions < Array
|
29
|
+
def passed_count
|
30
|
+
find_all { |a| a.passed? }.length
|
31
|
+
end
|
32
|
+
|
33
|
+
def failed_count
|
34
|
+
find_all { |a| a.failed? }.length
|
35
|
+
end
|
36
|
+
|
37
|
+
def call_all
|
38
|
+
each { |a| a.call }
|
39
|
+
end
|
40
|
+
|
41
|
+
def inspect
|
42
|
+
collect.with_index { |assertion, i| " #{i+1}) #{assertion.to_s}" }
|
43
|
+
end
|
44
|
+
alias to_s inspect
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class TestEnvironment
|
49
|
+
class << self
|
50
|
+
def test_instance_of(obj, *args, &blk)
|
51
|
+
raise(ArgumentError, 'a block is required') unless block_given?
|
52
|
+
|
53
|
+
instance_of_obj = obj.new(*args)
|
54
|
+
|
55
|
+
instance_of_self = new(instance_of_obj)
|
56
|
+
instance_of_self.instance_exec(instance_of_obj, &blk)
|
57
|
+
|
58
|
+
|
59
|
+
puts "", "=" * 80, ""
|
60
|
+
|
61
|
+
puts "Testing an instance of #{obj}:"
|
62
|
+
|
63
|
+
instance_of_self.run_setups
|
64
|
+
instance_of_self.assertions.call_all
|
65
|
+
|
66
|
+
puts instance_of_self.assertions.to_s
|
67
|
+
|
68
|
+
puts "", "=" * 80, ""
|
69
|
+
puts "Assertions: #{instance_of_self.assertions.count}"
|
70
|
+
puts "Passed: #{instance_of_self.assertions.passed_count}"
|
71
|
+
puts "Failed: #{instance_of_self.assertions.failed_count}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
attr :assertions
|
76
|
+
|
77
|
+
def initialize(obj)
|
78
|
+
@obj, @setups = obj, []
|
79
|
+
|
80
|
+
@assertions = Assertions.new
|
81
|
+
end
|
82
|
+
|
83
|
+
def setup(&blk)
|
84
|
+
raise(ArgumentError, 'a block is required') unless block_given?
|
85
|
+
@setups << blk
|
86
|
+
end
|
87
|
+
|
88
|
+
def run_setups
|
89
|
+
#===--- One instance_exec
|
90
|
+
# @obj.instance_exec(@setups) do |setups|
|
91
|
+
# setups.each { |s| s.call }
|
92
|
+
# end
|
93
|
+
|
94
|
+
#===--- Multi instance_exec
|
95
|
+
@setups.each do |setup|
|
96
|
+
# @obj.instance_eval(&setup) # Shouldnt it be this?
|
97
|
+
@obj.instance_exec(&setup)
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
def assert(msg=nil, &blk)
|
103
|
+
raise(ArgumentError, 'a block is required') unless block_given?
|
104
|
+
|
105
|
+
@assertions << Assertion.new(msg, blk)
|
106
|
+
end
|
107
|
+
end
|
data/test/helper.rb
ADDED
data/test_env.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{test_env}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ryan Lewis"]
|
12
|
+
s.date = %q{2010-05-11}
|
13
|
+
s.description = %q{My own personal test environment}
|
14
|
+
s.email = %q{c00lryguy@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/test_env.rb",
|
27
|
+
"test/helper.rb",
|
28
|
+
"test/test_test_env.rb",
|
29
|
+
"test_env.gemspec"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/c00lryguy/test_env}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.6}
|
35
|
+
s.summary = %q{My own personal test environment}
|
36
|
+
s.test_files = [
|
37
|
+
"test/helper.rb",
|
38
|
+
"test/test_test_env.rb"
|
39
|
+
]
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
else
|
47
|
+
end
|
48
|
+
else
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: test_env
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Ryan Lewis
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-11 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: My own personal test environment
|
22
|
+
email: c00lryguy@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- LICENSE
|
29
|
+
- README.md
|
30
|
+
files:
|
31
|
+
- .document
|
32
|
+
- .gitignore
|
33
|
+
- LICENSE
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- lib/test_env.rb
|
38
|
+
- test/helper.rb
|
39
|
+
- test/test_test_env.rb
|
40
|
+
- test_env.gemspec
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/c00lryguy/test_env
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --charset=UTF-8
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.6
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: My own personal test environment
|
71
|
+
test_files:
|
72
|
+
- test/helper.rb
|
73
|
+
- test/test_test_env.rb
|