ennui 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +1 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +6 -0
- data/Rakefile +1 -3
- data/ennui.gemspec +5 -1
- data/examples/usage.rb +28 -3
- data/lib/ennui.rb +16 -4
- data/spec/lib/ennui_spec.rb +44 -16
- data/spec/spec_helper.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTJiYjRiZGYwMjkxMzNhNjZkMGE5NjMxNjQzMTdhNWQxNzkxM2QxYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Yzc0NDUyNWVmNGQwNTVhZTQ3YTNkYjViNzAzN2JmYjU5ZGNkODkwMw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDY3MmJmNDRiZGE1NTY2YmFmMDI5NjdmNWQ5YTRkNWY3YTcyNmY4ZTNmNTcz
|
10
|
+
Zjg1ODQ3MDZlNWU5MGI3NzRhYWMyM2E2ZmEwOGM3NzQxMDA3NzdmMTFjM2Fh
|
11
|
+
YTBiMDEzYzFiMDhjNjFhNWRiYzc5MmQ2ZTEyYjE0OTE2NzY0ZDE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDliYThmYzczNmUzN2VlNGU3OWE2Njc3NGU0MmE1OWE1OTIxNTgwNGExMmM4
|
14
|
+
NmRiYWYzY2FiMDg0NDJhOGJiZGYzNDg4YjBkNjhkYjYwNjJlOTBiZjZkMjg4
|
15
|
+
ZGRhN2FkNzk1NDE3ZGQ1Yjc4Y2Y2OWUxMGNmMTFjZmI5MTA2MGU=
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -26,11 +26,9 @@ end
|
|
26
26
|
desc "Build gem locally"
|
27
27
|
task :build => :gemspec do
|
28
28
|
system "gem build #{gemspec.name}.gemspec"
|
29
|
-
FileUtils.mkdir_p "pkg"
|
30
|
-
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", "pkg"
|
31
29
|
end
|
32
30
|
|
33
31
|
desc "Install gem locally"
|
34
32
|
task :install => :build do
|
35
|
-
system "gem install
|
33
|
+
system "gem install #{gemspec.name}-#{gemspec.version}.gem"
|
36
34
|
end
|
data/ennui.gemspec
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
1
5
|
Gem::Specification.new do |s|
|
2
6
|
s.name = "ennui"
|
3
|
-
s.version = "0.0.
|
7
|
+
s.version = "0.0.2"
|
4
8
|
s.platform = Gem::Platform::RUBY
|
5
9
|
s.authors = ["Todd Mohney"]
|
6
10
|
s.email = ["toddmohney@gmail.com"]
|
data/examples/usage.rb
CHANGED
@@ -1,7 +1,32 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
3
|
+
require "ennui"
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
class Example
|
6
|
+
include Ennui
|
7
|
+
|
8
|
+
def do_sometimes_predicate_example
|
9
|
+
puts
|
10
|
+
puts "do sometimes predicate example"
|
11
|
+
puts "------------------------------"
|
12
|
+
10.times do
|
13
|
+
puts "meh" if sometimes?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def do_sometimes_block_example
|
19
|
+
puts
|
20
|
+
puts "do sometimes block example"
|
21
|
+
puts "--------------------------"
|
22
|
+
10.times do
|
23
|
+
sometimes do
|
24
|
+
puts "pfft"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
7
28
|
end
|
29
|
+
|
30
|
+
example_runner = Example.new
|
31
|
+
example_runner.do_sometimes_predicate_example
|
32
|
+
example_runner.do_sometimes_block_example
|
data/lib/ennui.rb
CHANGED
@@ -1,16 +1,28 @@
|
|
1
1
|
module Ennui
|
2
2
|
|
3
|
-
def
|
3
|
+
def sometimes?
|
4
4
|
random_number % 2 == 0
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
7
|
+
def sometimes
|
8
|
+
yield if sometimes? && block_given?
|
9
|
+
end
|
10
|
+
|
11
|
+
def whatever
|
12
|
+
sometimes
|
13
|
+
end
|
14
|
+
|
15
|
+
def maybe
|
16
|
+
sometimes
|
17
|
+
end
|
18
|
+
|
19
|
+
def who_cares?
|
8
20
|
random_number % 4 == 0
|
9
21
|
end
|
10
22
|
|
11
|
-
private
|
23
|
+
private
|
12
24
|
|
13
|
-
def
|
25
|
+
def random_number
|
14
26
|
Random.new.rand(0..1000)
|
15
27
|
end
|
16
28
|
|
data/spec/lib/ennui_spec.rb
CHANGED
@@ -1,41 +1,69 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'pry'
|
3
|
+
require 'ennui'
|
4
|
+
|
5
|
+
include Ennui
|
6
|
+
|
7
|
+
class EnnuiTest
|
8
|
+
include Ennui
|
9
|
+
end
|
3
10
|
|
4
11
|
describe Ennui do
|
12
|
+
let(:ennui_test) { EnnuiTest.new }
|
5
13
|
|
6
14
|
describe "#sometimes?" do
|
7
|
-
|
8
|
-
|
15
|
+
it "is true about %50 of the time" do
|
16
|
+
score = truthiness_score(1000, Proc.new { sometimes? })
|
17
|
+
score.should be_within(0.10).of(0.50)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#sometimes" do
|
22
|
+
it "calls sometimes?" do
|
23
|
+
Ennui.should_receive(:sometimes?)
|
24
|
+
Ennui.sometimes
|
25
|
+
end
|
9
26
|
|
10
|
-
|
11
|
-
|
27
|
+
context "when sometimes? is true" do
|
28
|
+
before do
|
29
|
+
Ennui.stub(:sometimes?) { true }
|
12
30
|
end
|
13
31
|
|
14
|
-
|
32
|
+
it "yields to the block" do
|
33
|
+
expect { |block| Ennui.sometimes(&block) }.to yield_control
|
34
|
+
end
|
15
35
|
end
|
16
36
|
|
17
|
-
|
18
|
-
|
19
|
-
|
37
|
+
context "when sometimes? is false" do
|
38
|
+
before do
|
39
|
+
Ennui.stub(:sometimes?) { false }
|
40
|
+
end
|
41
|
+
|
42
|
+
it "does not yield to the block" do
|
43
|
+
expect { |block| Ennui.sometimes(&block) }.not_to yield_control
|
44
|
+
end
|
20
45
|
end
|
21
46
|
end
|
22
47
|
|
23
48
|
describe "#who_cares?" do
|
24
49
|
it "is true about %25 of the time" do
|
25
|
-
score = truthiness_score(1000, Proc.new {
|
50
|
+
score = truthiness_score(1000, Proc.new { who_cares? })
|
26
51
|
score.should be_within(0.10).of(0.25)
|
27
52
|
end
|
28
53
|
end
|
29
54
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
55
|
+
describe "#whatever" do
|
56
|
+
it "is an alias for sometimes" do
|
57
|
+
Ennui.should_receive(:sometimes)
|
58
|
+
Ennui.whatever
|
34
59
|
end
|
60
|
+
end
|
35
61
|
|
36
|
-
|
37
|
-
|
38
|
-
|
62
|
+
describe "#maybe" do
|
63
|
+
it "is an alias for sometimes" do
|
64
|
+
Ennui.should_receive(:sometimes)
|
65
|
+
Ennui.maybe
|
66
|
+
end
|
39
67
|
end
|
40
68
|
|
41
69
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,3 +2,15 @@ require 'simplecov'
|
|
2
2
|
SimpleCov.start
|
3
3
|
|
4
4
|
require 'ennui'
|
5
|
+
|
6
|
+
def truthiness_score(iterations, proc)
|
7
|
+
truthiness = 0
|
8
|
+
iterations.times do
|
9
|
+
truthiness += 1 if proc.call
|
10
|
+
end
|
11
|
+
|
12
|
+
score = truthiness.to_f / iterations.to_f
|
13
|
+
puts "Truthiness score: #{score}"
|
14
|
+
score
|
15
|
+
end
|
16
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ennui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Mohney
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ennui provides a library of predicates which return true at various frequencies.
|
14
14
|
email:
|