niclasnilsson-clean-assert 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +12 -0
- data/README.rdoc +50 -0
- data/Rakefile +28 -0
- data/clean-assert.gemspec +44 -0
- data/lib/clean-assert.rb +8 -0
- data/lib/clean-assert/clean-assert.rb +19 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/clean_assert_spec.rb +75 -0
- data/spec/regular_methods.rb +32 -0
- metadata +87 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
= clean-assert
|
2
|
+
|
3
|
+
* http://github.com/niclasnilsson/clean-assert/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A Ruby library to get really clean asserts.
|
8
|
+
|
9
|
+
Example:
|
10
|
+
|
11
|
+
assert / "name != nil" / "not name.empty?" / "age >= 21"
|
12
|
+
|
13
|
+
This will do three separate assertion checks and will give you an error message that includes
|
14
|
+
the broken assertion code, the class and in which method. No need for having first the actual assertion and
|
15
|
+
a strained error message that you normally have to write. This is executable, Design by Contract style.
|
16
|
+
|
17
|
+
== FEATURES/PROBLEMS:
|
18
|
+
|
19
|
+
* No known problems.
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* sudo gem install niclasnilsson-clean-assert
|
24
|
+
|
25
|
+
(which is not working yet)
|
26
|
+
|
27
|
+
== LICENSE:
|
28
|
+
|
29
|
+
(The MIT License)
|
30
|
+
|
31
|
+
Copyright (c) 2009 Niclas Nilsson
|
32
|
+
|
33
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
34
|
+
a copy of this software and associated documentation files (the
|
35
|
+
'Software'), to deal in the Software without restriction, including
|
36
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
37
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
38
|
+
permit persons to whom the Software is furnished to do so, subject to
|
39
|
+
the following conditions:
|
40
|
+
|
41
|
+
The above copyright notice and this permission notice shall be
|
42
|
+
included in all copies or substantial portions of the Software.
|
43
|
+
|
44
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
45
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
46
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
47
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
48
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
49
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
50
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/clean-assert'
|
3
|
+
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('clean-assert', CleanAssert::VERSION) do |p|
|
7
|
+
p.developer('Niclas Nilsson', 'niclas@niclasnilsson.se')
|
8
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
+
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
10
|
+
p.rubyforge_name = p.name # TODO this is default value
|
11
|
+
# p.extra_deps = [
|
12
|
+
# ['activesupport','>= 2.0.2'],
|
13
|
+
# ]
|
14
|
+
p.extra_dev_deps = [
|
15
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
16
|
+
]
|
17
|
+
|
18
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
19
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
20
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
21
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
25
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
26
|
+
|
27
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
28
|
+
# task :default => [:spec, :features]
|
@@ -0,0 +1,44 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{clean-assert}
|
3
|
+
s.version = "0.5.0"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Niclas Nilsson"]
|
7
|
+
s.date = %q{2009-04-29}
|
8
|
+
s.description = %q{A Ruby library to get really clean asserts.
|
9
|
+
|
10
|
+
Example:
|
11
|
+
|
12
|
+
assert / "name != nil" / "not name.empty?" / "age >= 21"
|
13
|
+
|
14
|
+
This will do three separate assertion checks and will give you an error message that includes
|
15
|
+
the broken assertion code, the class and in which method. No need for having first the actual assertion and
|
16
|
+
a strained error message that you normally have to write. This is executable, Design by Contract style.}
|
17
|
+
s.email = ["niclas@niclasnilsson.se"]
|
18
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
19
|
+
s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "clean-assert.gemspec", "lib/clean-assert.rb", "lib/clean-assert/clean-assert.rb", "script/console", "script/destroy", "script/generate", "spec/clean_assert_spec.rb", "spec/regular_methods.rb"]
|
20
|
+
s.has_rdoc = true
|
21
|
+
s.homepage = %q{http://github.com/niclasnilsson/clean-assert/}
|
22
|
+
s.post_install_message = %q{PostInstall.txt}
|
23
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
s.rubyforge_project = %q{clean-assert}
|
26
|
+
s.rubygems_version = %q{1.3.2}
|
27
|
+
s.summary = %q{A Ruby library to get really clean asserts}
|
28
|
+
|
29
|
+
if s.respond_to? :specification_version then
|
30
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
31
|
+
s.specification_version = 3
|
32
|
+
|
33
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
34
|
+
s.add_development_dependency(%q<newgem>, [">= 1.3.0"])
|
35
|
+
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
|
36
|
+
else
|
37
|
+
s.add_dependency(%q<newgem>, [">= 1.3.0"])
|
38
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
39
|
+
end
|
40
|
+
else
|
41
|
+
s.add_dependency(%q<newgem>, [">= 1.3.0"])
|
42
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
43
|
+
end
|
44
|
+
end
|
data/lib/clean-assert.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require '/Users/nicke/code/facets/lib/core/facets'
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
alias_method :assert, :binding
|
5
|
+
end
|
6
|
+
|
7
|
+
class Binding
|
8
|
+
|
9
|
+
def / expression
|
10
|
+
if not eval expression
|
11
|
+
the_caller = /\`([^\']+)\'/.match(caller(1).first)
|
12
|
+
m = "unknown"
|
13
|
+
m = the_caller ? the_caller[1] : m
|
14
|
+
raise "Assertion '#{expression}' not satisfied in #{self.self()}##{m}"
|
15
|
+
end
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/clean-assert.rb'}"
|
9
|
+
puts "Loading clean-assert gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require 'test/unit'
|
3
|
+
require "spec"
|
4
|
+
|
5
|
+
$LOAD_PATH << File.expand_path(File.join('..', 'lib'), File.dirname(__FILE__))
|
6
|
+
|
7
|
+
require 'clean-assert'
|
8
|
+
|
9
|
+
class Binary
|
10
|
+
@@binary_states = 2
|
11
|
+
|
12
|
+
def self.binary_states= value
|
13
|
+
@@binary_states = value
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.check_binary_states
|
17
|
+
assert / "@@binary_states == 2"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Person
|
22
|
+
attr_accessor :age
|
23
|
+
def check_invariant
|
24
|
+
assert / "@age >= 0"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "clean asserts" do
|
29
|
+
|
30
|
+
before do
|
31
|
+
@my_member = "my member"
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "that are satisfied" do
|
35
|
+
it "should provide clean assertion syntax" do
|
36
|
+
name = "Niclas Nilsson"
|
37
|
+
assert / "name != nil"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should support chained assertions to keep code terse" do
|
41
|
+
name = "Niclas Nilsson"
|
42
|
+
age = 38
|
43
|
+
assert / "name != nil" / "not name.empty?" / "age >= 21"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should work for instance variables" do
|
47
|
+
niclas = Person.new
|
48
|
+
niclas.age = 38
|
49
|
+
niclas.check_invariant
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should work for class variables" do
|
53
|
+
Binary.binary_states = 2
|
54
|
+
Binary.check_binary_states
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should work for regular methods" do
|
58
|
+
load "spec/regular_methods.rb"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "that are not satisfied" do
|
63
|
+
it "should work for instance variables" do
|
64
|
+
niclas = Person.new
|
65
|
+
niclas.age = -1
|
66
|
+
lambda { niclas.check_invariant }.should raise_error(RuntimeError, /Assertion '@age >= 0' not satisfied/)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should work for class variables" do
|
70
|
+
Binary.binary_states = 3
|
71
|
+
lambda { Binary.check_binary_states }.should raise_error(RuntimeError, /Assertion '@@binary_states == 2' not satisfied in Binary#check_binary_states/)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'clean-assert'
|
2
|
+
|
3
|
+
def method_with_valid_assert
|
4
|
+
assert / "2 == 2"
|
5
|
+
end
|
6
|
+
|
7
|
+
def method_with_broken_assert
|
8
|
+
assert / "1 == 2"
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_with_argument value
|
12
|
+
assert / "value == 2"
|
13
|
+
end
|
14
|
+
|
15
|
+
# Test valid assertions outside of classes and outside of rspec
|
16
|
+
method_with_valid_assert
|
17
|
+
method_with_argument 2
|
18
|
+
|
19
|
+
# Test broken assertions outside of classes and outside of rspec
|
20
|
+
|
21
|
+
begin
|
22
|
+
method_with_broken_assert
|
23
|
+
rescue RuntimeError => e
|
24
|
+
raise if not e.message =~ /Assertion '1 == 2' not satisfied in main#method_with_broken_assert/
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
method_with_argument 3
|
29
|
+
rescue RuntimeError => e
|
30
|
+
raise if not e.message =~ /Assertion 'value == 2' not satisfied in main#method_with_argument/
|
31
|
+
end
|
32
|
+
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: niclasnilsson-clean-assert
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Niclas Nilsson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-29 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: newgem
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.3.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.0
|
34
|
+
version:
|
35
|
+
description: "A Ruby library to get really clean asserts. Example: assert / \"name != nil\" / \"not name.empty?\" / \"age >= 21\" This will do three separate assertion checks and will give you an error message that includes the broken assertion code, the class and in which method. No need for having first the actual assertion and a strained error message that you normally have to write. This is executable, Design by Contract style."
|
36
|
+
email:
|
37
|
+
- niclas@niclasnilsson.se
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- History.txt
|
44
|
+
- Manifest.txt
|
45
|
+
- README.rdoc
|
46
|
+
files:
|
47
|
+
- History.txt
|
48
|
+
- Manifest.txt
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- clean-assert.gemspec
|
52
|
+
- lib/clean-assert.rb
|
53
|
+
- lib/clean-assert/clean-assert.rb
|
54
|
+
- script/console
|
55
|
+
- script/destroy
|
56
|
+
- script/generate
|
57
|
+
- spec/clean_assert_spec.rb
|
58
|
+
- spec/regular_methods.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/niclasnilsson/clean-assert/
|
61
|
+
post_install_message: PostInstall.txt
|
62
|
+
rdoc_options:
|
63
|
+
- --main
|
64
|
+
- README.rdoc
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project: clean-assert
|
82
|
+
rubygems_version: 1.2.0
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: A Ruby library to get really clean asserts
|
86
|
+
test_files: []
|
87
|
+
|