asrt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1ae767d14b182a4d8c749050c58a0a7dc5663b55
4
+ data.tar.gz: 0bacdf797d4bafbeecffc64126bcd03b4136d351
5
+ SHA512:
6
+ metadata.gz: d48ee7d8f08a0e3b2b867295f3d0b7488bbcab17f10482766371a9ccb09267085846eb1a35a195ff15385f0f7b11d6258a73cb13f4cdfeaf102f1bb710398daa
7
+ data.tar.gz: 850a6b2186ade4151ba04be01557fdfc0ac2ebefd5afb96d3614d3e7c88bafc290c4fcf3c3b6d610e6d31e4c9a002d4f3333d49beaeee4f14c17efea07e37b92
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ install: bundle install --without development
6
+ script: bundle exec rake test
7
+ notifications:
8
+ email: false
9
+ cache: bundler
data/CHANGELOG.rst ADDED
@@ -0,0 +1,12 @@
1
+ Changelog for asrt
2
+ ==================
3
+
4
+ 1.0.0
5
+ -----
6
+
7
+ Stable release.
8
+
9
+ 0.*.*
10
+ -----
11
+
12
+ Check out the commit history :-)
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'rspec'
5
+ gem 'rake'
6
+ end
7
+
8
+ group :coverage do
9
+ gem 'coveralls', require: false
10
+ end
11
+
12
+ group :development do
13
+ gem 'pry'
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ coderay (1.1.0)
5
+ coveralls (0.7.0)
6
+ multi_json (~> 1.3)
7
+ rest-client
8
+ simplecov (>= 0.7)
9
+ term-ansicolor
10
+ thor
11
+ diff-lcs (1.2.5)
12
+ docile (1.1.3)
13
+ method_source (0.8.2)
14
+ mime-types (2.1)
15
+ multi_json (1.8.4)
16
+ pry (0.9.12.6)
17
+ coderay (~> 1.0)
18
+ method_source (~> 0.8)
19
+ slop (~> 3.4)
20
+ rake (10.1.1)
21
+ rest-client (1.6.7)
22
+ mime-types (>= 1.16)
23
+ rspec (2.14.1)
24
+ rspec-core (~> 2.14.0)
25
+ rspec-expectations (~> 2.14.0)
26
+ rspec-mocks (~> 2.14.0)
27
+ rspec-core (2.14.7)
28
+ rspec-expectations (2.14.5)
29
+ diff-lcs (>= 1.1.3, < 2.0)
30
+ rspec-mocks (2.14.5)
31
+ simplecov (0.8.2)
32
+ docile (~> 1.1.0)
33
+ multi_json
34
+ simplecov-html (~> 0.8.0)
35
+ simplecov-html (0.8.0)
36
+ slop (3.4.7)
37
+ term-ansicolor (1.3.0)
38
+ tins (~> 1.0)
39
+ thor (0.18.1)
40
+ tins (1.0.0)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ coveralls
47
+ pry
48
+ rake
49
+ rspec
data/LICENSE.rst ADDED
@@ -0,0 +1,4 @@
1
+ License for asrt
2
+ ================
3
+
4
+ Refer to http://opensource.org/licenses/MIT.
data/README.rst ADDED
@@ -0,0 +1,71 @@
1
+ .. role:: ruby(code)
2
+ :language: ruby
3
+
4
+ .. role:: sh(code)
5
+ :language: sh
6
+
7
+ asrt
8
+ ==========
9
+
10
+ .. image:: http://img.shields.io/license/MIT.png?color=green
11
+ :alt: MIT License
12
+ :target: http://opensource.org/licenses/MIT
13
+
14
+ Introduction
15
+ ------------
16
+
17
+ `This gem <https://rubygems.org/gems/asrt>`_ simply gives you :ruby:`asrt` so
18
+ you can do
19
+
20
+ .. code-block:: ruby
21
+
22
+ def funny(input)
23
+ asrt input.is_a?(String), 'Me only eat strings.'
24
+
25
+ input + ' is funny'
26
+ end
27
+
28
+ Why use :ruby:`asrt` rather than :ruby:`assert`? Well, it's short and you may
29
+ like to use some other assert stuff for your unit tests.
30
+
31
+
32
+ Installation
33
+ ------------
34
+
35
+ .. code-block:: sh
36
+
37
+ gem install asrt
38
+
39
+ In your ``Gemfile`` may want to have :ruby:`gem 'asrt'`.
40
+
41
+ Dependencies
42
+ ............
43
+
44
+ None.
45
+
46
+
47
+ Examples
48
+ --------
49
+
50
+ .. code-block:: ruby
51
+
52
+ def funny(input)
53
+ asrt input.is_a?(String), 'Me only eat strings.'
54
+
55
+ input + ' is funny'
56
+ end
57
+
58
+
59
+
60
+ Contribute
61
+ ----------
62
+
63
+ * `Fork <https://github.com/ct-clearhaus/asrt/fork>`_
64
+ * Clone
65
+ * :sh:`bundle install && bundle exec rake test`
66
+ * Make your changes
67
+ * :sh:`bundle exec rake test` again, preferably against Ruby 1.9.3, 2.0.0 and
68
+ 2.1.0 (`Travis <https://travis-ci.org/ct-clearhaus/asrt/pull_requests>`_
69
+ will do that).
70
+ * Create a Pull Request
71
+ * Enjoy!
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ task :default => :test
4
+
5
+ desc 'Run all specs'
6
+ RSpec::Core::RakeTask.new(:test) do |task|
7
+ task.pattern = './spec/asrt/*_spec.rb'
8
+ end
data/asrt.gemspec ADDED
@@ -0,0 +1,11 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'asrt'
3
+ s.version = '0.1.0'
4
+ s.summary = 'Assertion library.'
5
+ s.description = 'Allows you to assert things to be true in your code.'
6
+ s.license = 'MIT'
7
+ s.authors = ['Casper Thomsen']
8
+ s.email = 'ct@clearhaus.com'
9
+ s.homepage = 'https://github.com/ct-clearhaus/asrt'
10
+ s.files = `git ls-files`.split($/)
11
+ end
data/lib/asrt.rb ADDED
@@ -0,0 +1,44 @@
1
+ module Asrt
2
+ class AssertionError < StandardError
3
+ end
4
+
5
+ module Fallible
6
+ def asrt(*args, &block)
7
+ if block.nil?
8
+ condition, message, garbage = args
9
+
10
+ okay = (condition == true)
11
+ else
12
+ message, garbage = args
13
+
14
+ okay = (yield rescue false) == true
15
+ end
16
+
17
+ raise ArgumentError, 'wrong number of arguments.' unless garbage.nil?
18
+
19
+ raise AssertionError, message unless okay
20
+ end
21
+ end
22
+
23
+ module Infallible
24
+ def asrt(*args, &block)
25
+ if block.nil?
26
+ _, _, garbage = args
27
+ else
28
+ _, garbage = args
29
+ end
30
+
31
+ raise ArgumentError, 'wrong number of arguments.' unless garbage.nil?
32
+ end
33
+ end
34
+
35
+ def self.disable
36
+ Object.class_eval do
37
+ include Asrt::Infallible
38
+ end
39
+ end
40
+ end
41
+
42
+ Object.class_eval do
43
+ include Asrt::Fallible
44
+ end
@@ -0,0 +1,51 @@
1
+ require 'asrt'
2
+
3
+ describe 'Asrt::Fallible#asrt' do
4
+ it 'should fail if no parameter nor block is given' do
5
+ expect{ asrt }.to raise_error(Asrt::AssertionError)
6
+ end
7
+
8
+ it 'should fail unless parameter is true' do
9
+ expect{ asrt false }.to raise_error(Asrt::AssertionError)
10
+ expect{ asrt nil }.to raise_error(Asrt::AssertionError)
11
+ expect{ asrt 1 }.to raise_error(Asrt::AssertionError)
12
+ expect{ asrt 'true' }.to raise_error(Asrt::AssertionError)
13
+ end
14
+
15
+ it 'should not fail when parameter is true' do
16
+ expect{ asrt true }.to_not raise_error
17
+ end
18
+
19
+ it 'should fail when block yields anything but true' do
20
+ expect{ asrt { false } }.to raise_error(Asrt::AssertionError)
21
+ expect{ asrt { nil } }.to raise_error(Asrt::AssertionError)
22
+ expect{ asrt { 1 } }.to raise_error(Asrt::AssertionError)
23
+ expect{ asrt { 'true' } }.to raise_error(Asrt::AssertionError)
24
+ expect{ asrt { raise StandardError } }.to raise_error(Asrt::AssertionError)
25
+ end
26
+
27
+ it 'should not fail when block yields true' do
28
+ expect{ asrt { true } }.to_not raise_error
29
+ end
30
+
31
+ it 'should fail with the given message, when failing' do
32
+ expect{ asrt false, 'msg' }.to raise_error(Asrt::AssertionError, 'msg')
33
+ expect{ asrt 'msg' do false end }.to raise_error(Asrt::AssertionError, 'msg')
34
+ end
35
+
36
+ it 'should complain when too many arguments are given' do
37
+ expect{ asrt 1, 2, 3 }.to raise_error(ArgumentError)
38
+ expect{ asrt 1, 2, 3, 4 }.to raise_error(ArgumentError)
39
+ end
40
+
41
+ it 'should have the right associativity' do
42
+ def negate(x)
43
+ not x
44
+ end
45
+
46
+ expect{ asrt negate false }.to_not raise_error
47
+ expect{ asrt ! false }.to_not raise_error
48
+ expect{ asrt 1 + 2 == 3 }.to_not raise_error
49
+ expect{ asrt raise StandardError rescue raise StandardError, 'msg' }.to raise_error(StandardError, 'msg')
50
+ end
51
+ end
@@ -0,0 +1,23 @@
1
+ require 'asrt'
2
+
3
+ describe 'Asrt::Infallible#asrt' do
4
+ include Asrt::Infallible
5
+
6
+ it 'should not fail' do
7
+ expect{
8
+ asrt
9
+ asrt true
10
+ asrt false
11
+ asrt false, 'message'
12
+ asrt 'message' do false end
13
+ asrt 'message' do raise StandardError end
14
+ }.to_not raise_error
15
+ end
16
+
17
+ it 'should complain when too many arguments are given' do
18
+ expect{ asrt 1, 2 do 3 end }.to raise_error(ArgumentError)
19
+ expect{ asrt 1, 2, 3 }.to raise_error(ArgumentError)
20
+ expect{ asrt 1, 2, 3, 4 }.to raise_error(ArgumentError)
21
+ end
22
+ end
23
+
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asrt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Casper Thomsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Allows you to assert things to be true in your code.
14
+ email: ct@clearhaus.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - .travis.yml
20
+ - CHANGELOG.rst
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - LICENSE.rst
24
+ - README.rst
25
+ - Rakefile
26
+ - asrt.gemspec
27
+ - lib/asrt.rb
28
+ - spec/asrt/fallible_spec.rb
29
+ - spec/asrt/infallible_spec.rb
30
+ homepage: https://github.com/ct-clearhaus/asrt
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.2.2
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Assertion library.
54
+ test_files: []