clean-assert 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.sw*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in clean-assert.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Niclas Nilsson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,52 @@
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 the method name. No need for having both the actual assertion and
15
+ then a strained error message that you normally have to write to understand what broke. Also, due to it's terseness,
16
+ you can afford having several guard clauses on one line instead of letting them take over your method, which keeps
17
+ the signal-to-noise ratio sane.
18
+
19
+ == FEATURES/PROBLEMS:
20
+
21
+ * No known problems.
22
+
23
+ == INSTALL:
24
+
25
+ $ gem sources -a http://gems.github.com
26
+ $ sudo gem install niclasnilsson-clean-assert
27
+
28
+
29
+ == LICENSE:
30
+
31
+ (The MIT License)
32
+
33
+ Copyright (c) 2009 Niclas Nilsson
34
+
35
+ Permission is hereby granted, free of charge, to any person obtaining
36
+ a copy of this software and associated documentation files (the
37
+ 'Software'), to deal in the Software without restriction, including
38
+ without limitation the rights to use, copy, modify, merge, publish,
39
+ distribute, sublicense, and/or sell copies of the Software, and to
40
+ permit persons to whom the Software is furnished to do so, subject to
41
+ the following conditions:
42
+
43
+ The above copyright notice and this permission notice shall be
44
+ included in all copies or substantial portions of the Software.
45
+
46
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
47
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
48
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
49
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
50
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
51
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
52
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'clean-assert/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "clean-assert"
8
+ spec.version = Clean::Assert::VERSION
9
+ spec.authors = ["Niclas Nilsson"]
10
+ spec.email = ["niclas@niclasnilsson.se"]
11
+ spec.description = %q{A Ruby gem to get really clean asserts}
12
+ spec.summary = %q{A Ruby gem to get really clean asserts}
13
+ spec.homepage = "https://github.com/niclasnilsson/clean-assert"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "facets", "~> 2.9"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,19 @@
1
+ require '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(0).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
@@ -0,0 +1,5 @@
1
+ module Clean
2
+ module Assert
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'clean-assert/clean-assert'
5
+
6
+ module CleanAssert
7
+ VERSION = '0.6.2'
8
+ 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,72 @@
1
+ $LOAD_PATH << File.expand_path(File.join('..', 'lib'), File.dirname(__FILE__))
2
+
3
+ require 'clean-assert'
4
+
5
+ class Binary
6
+ @@binary_states = 2
7
+
8
+ def self.binary_states= value
9
+ @@binary_states = value
10
+ end
11
+
12
+ def self.check_binary_states
13
+ assert / "@@binary_states == 2"
14
+ end
15
+ end
16
+
17
+ class Person
18
+ attr_accessor :age
19
+ def check_invariant
20
+ assert / "@age >= 0"
21
+ end
22
+ end
23
+
24
+ describe "clean asserts" do
25
+
26
+ before do
27
+ @my_member = "my member"
28
+ end
29
+
30
+ it "should provide clean assertion syntax" do
31
+ name = "Niclas Nilsson"
32
+ assert / "name != nil"
33
+ end
34
+
35
+ it "should support chained assertions to keep code terse" do
36
+ name = "Niclas Nilsson"
37
+ age = 38
38
+ assert / "name != nil" / "not name.empty?" / "age >= 21"
39
+ end
40
+
41
+ describe "that are satisfied" do
42
+ it "should work for instance variables" do
43
+ niclas = Person.new
44
+ niclas.age = 38
45
+ niclas.check_invariant
46
+ end
47
+
48
+ it "should work for class variables" do
49
+ Binary.binary_states = 2
50
+ Binary.check_binary_states
51
+ end
52
+
53
+ end
54
+
55
+ describe "that are not satisfied" do
56
+ it "should work for instance variables" do
57
+ niclas = Person.new
58
+ niclas.age = -1
59
+ lambda { niclas.check_invariant }.should raise_error(RuntimeError, /Assertion '@age >= 0' not satisfied/)
60
+ end
61
+
62
+ it "should work for class variables" do
63
+ Binary.binary_states = 3
64
+ lambda { Binary.check_binary_states }.should raise_error(RuntimeError, /Assertion '@@binary_states == 2' not satisfied in Binary#check_binary_states/)
65
+ end
66
+ end
67
+
68
+ it "should work for regular methods" do
69
+ load "spec/regular_methods.rb"
70
+ end
71
+ end
72
+
@@ -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,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clean-assert
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Niclas Nilsson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: facets
16
+ requirement: &70102167125920 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.9'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70102167125920
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &70102167125180 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.3'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70102167125180
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70102167124580 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70102167124580
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70102167122900 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70102167122900
58
+ description: A Ruby gem to get really clean asserts
59
+ email:
60
+ - niclas@niclasnilsson.se
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.rdoc
69
+ - Rakefile
70
+ - clean-assert.gemspec
71
+ - lib/clean-assert.rb
72
+ - lib/clean-assert/clean-assert.rb
73
+ - lib/clean-assert/version.rb
74
+ - script/console
75
+ - script/destroy
76
+ - script/generate
77
+ - spec/clean_assert_spec.rb
78
+ - spec/regular_methods.rb
79
+ homepage: https://github.com/niclasnilsson/clean-assert
80
+ licenses:
81
+ - MIT
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.17
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: A Ruby gem to get really clean asserts
104
+ test_files:
105
+ - spec/clean_assert_spec.rb
106
+ - spec/regular_methods.rb
107
+ has_rdoc: