truthiness 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +15 -0
- data/Gemfile.lock +40 -0
- data/README +19 -0
- data/Rakefile +16 -0
- data/lib/truthiness.rb +32 -0
- data/lib/truthiness/version.rb +3 -0
- data/test/unit/truthiness_test.rb +68 -0
- data/truthiness.gemspec +21 -0
- metadata +55 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
truthiness (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ansi (1.4.2)
|
10
|
+
coderay (1.0.5)
|
11
|
+
metaclass (0.0.1)
|
12
|
+
method_source (0.7.1)
|
13
|
+
minitest (2.11.3)
|
14
|
+
mocha (0.10.5)
|
15
|
+
metaclass (~> 0.0.1)
|
16
|
+
pry (0.9.8.4)
|
17
|
+
coderay (~> 1.0.5)
|
18
|
+
method_source (~> 0.7.1)
|
19
|
+
slop (>= 2.4.4, < 3)
|
20
|
+
rake (0.9.2.2)
|
21
|
+
shoulda (3.0.1)
|
22
|
+
shoulda-context (~> 1.0.0)
|
23
|
+
shoulda-matchers (~> 1.0.0)
|
24
|
+
shoulda-context (1.0.0)
|
25
|
+
shoulda-matchers (1.0.0)
|
26
|
+
slop (2.4.4)
|
27
|
+
turn (0.9.4)
|
28
|
+
ansi
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
minitest
|
35
|
+
mocha
|
36
|
+
pry
|
37
|
+
rake
|
38
|
+
shoulda
|
39
|
+
truthiness!
|
40
|
+
turn
|
data/README
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Evaluate the truthiness of an object without getting out the logical
|
2
|
+
expressions
|
3
|
+
|
4
|
+
true.true? # => true
|
5
|
+
false.true? # => false
|
6
|
+
"true".true? # => false
|
7
|
+
nil.true? # => false
|
8
|
+
|
9
|
+
false.false? # => true
|
10
|
+
true.false? # => false
|
11
|
+
"false".false? # => false
|
12
|
+
nil.false? # => false
|
13
|
+
|
14
|
+
"almost anything".truthy? # => true
|
15
|
+
false.truthy? # => false
|
16
|
+
nil.truthy? # => false
|
17
|
+
|
18
|
+
NOTE: The truthy? method original came from another gem called "truthy"
|
19
|
+
but I determined that it was still the best name for that type of method
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
task :default => :test
|
5
|
+
|
6
|
+
require 'rake/testtask'
|
7
|
+
Rake::TestTask.new(:test) do |test|
|
8
|
+
test.libs << "lib" << "test"
|
9
|
+
test.test_files = FileList["test/unit/**/*_test.rb"]
|
10
|
+
test.verbose = true
|
11
|
+
# test.warning = true
|
12
|
+
end
|
13
|
+
|
14
|
+
task :console do
|
15
|
+
sh "pry -I lib/truthiness -r truthiness.rb"
|
16
|
+
end
|
data/lib/truthiness.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Truthiness
|
2
|
+
|
3
|
+
def truthy?
|
4
|
+
!!self
|
5
|
+
end
|
6
|
+
|
7
|
+
def not_truthy?
|
8
|
+
!self
|
9
|
+
end
|
10
|
+
alias_method :falsey?, :not_truthy?
|
11
|
+
|
12
|
+
def true?
|
13
|
+
self == true
|
14
|
+
end
|
15
|
+
|
16
|
+
def not_true?
|
17
|
+
!true?
|
18
|
+
end
|
19
|
+
|
20
|
+
def false?
|
21
|
+
self == false
|
22
|
+
end
|
23
|
+
|
24
|
+
def not_false?
|
25
|
+
!false?
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
class Object
|
31
|
+
include Truthiness
|
32
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'truthiness'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'shoulda'
|
5
|
+
require 'turn'
|
6
|
+
require 'mocha'
|
7
|
+
|
8
|
+
class TruthinessTest < Test::Unit::TestCase
|
9
|
+
subject { Object.new }
|
10
|
+
|
11
|
+
should "respond to truthy methods" do
|
12
|
+
[:truthy?, :not_truthy?, :falsey?,
|
13
|
+
:true?, :not_true?, :false?, :not_false?].each do |m|
|
14
|
+
assert subject.respond_to?(m)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "#true?" do
|
19
|
+
context "on true" do
|
20
|
+
subject { true }
|
21
|
+
|
22
|
+
should "return false" do
|
23
|
+
assert subject.true?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "on anything other than true" do
|
28
|
+
should "return false" do
|
29
|
+
[nil, false, "string", [], {}, Object.new].each do |o|
|
30
|
+
assert !o.true?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "#not_true?" do
|
37
|
+
should "evaluate true? and return the opposite" do
|
38
|
+
subject.expects(:true?).returns(mock)
|
39
|
+
subject.not_true?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "#false?" do
|
44
|
+
context "on false" do
|
45
|
+
subject { false }
|
46
|
+
|
47
|
+
should "return true" do
|
48
|
+
assert subject.false?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "on anything other than false" do
|
53
|
+
should "return false" do
|
54
|
+
[nil, true, "string", [], {}, Object.new].each do |o|
|
55
|
+
assert !o.false?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "#not_false?" do
|
62
|
+
should "evaluate true? and return the opposite" do
|
63
|
+
subject.expects(:true?).returns(mock)
|
64
|
+
subject.not_true?
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
data/truthiness.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require 'truthiness/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "truthiness"
|
6
|
+
s.version = Truthiness::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Jon Karna"]
|
9
|
+
s.email = ["ipg49vv2@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/jonkarna/truthiness"
|
11
|
+
s.summary = %q{I want the truth!!!}
|
12
|
+
s.description = %q{Evaluate the truthiness of an object without getting out
|
13
|
+
the logical expressions}
|
14
|
+
|
15
|
+
s.rubyforge_project = "truthiness"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: truthiness
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jon Karna
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-18 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! "Evaluate the truthiness of an object without getting out\n the
|
15
|
+
logical expressions"
|
16
|
+
email:
|
17
|
+
- ipg49vv2@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- README
|
25
|
+
- Rakefile
|
26
|
+
- lib/truthiness.rb
|
27
|
+
- lib/truthiness/version.rb
|
28
|
+
- test/unit/truthiness_test.rb
|
29
|
+
- truthiness.gemspec
|
30
|
+
homepage: https://github.com/jonkarna/truthiness
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project: truthiness
|
50
|
+
rubygems_version: 1.8.10
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: I want the truth!!!
|
54
|
+
test_files:
|
55
|
+
- test/unit/truthiness_test.rb
|