if 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/if.rb +1 -1
- data/spec/if_spec.rb +24 -22
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0638f3a18630bbc0ff3f75dedbdd2eaf0479e8c8
|
4
|
+
data.tar.gz: 5f28eea0d2d53de6df401a8f8389b2a19b9dedd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4b65ac816967ccdbacba2746f2e3b5b12dbd4a45b54df8e65e07a1f4191c75aeb275a0025fbf623ea7f9704ba356432a356d27371d39abcbc6e9dd5644809c4
|
7
|
+
data.tar.gz: 4c354d60a9c8e1637b2d3dcfa587cb03c04ce8b29f98baed61c675d6a82e291642e99b8d60fc618ade7238f2630ff12839960f58fd4b3b0c9e1bbdd1e65166a1
|
data/lib/if.rb
CHANGED
data/spec/if_spec.rb
CHANGED
@@ -5,19 +5,20 @@ RSpec.describe BasicObject do
|
|
5
5
|
|
6
6
|
describe '#if' do
|
7
7
|
it 'always evaluates the first block to if' do
|
8
|
-
expect(object.if
|
8
|
+
expect(object.if proc { "I'm true!" }).to eq("I'm true!")
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'ignores any else blocks' do
|
12
|
-
expect(object.if
|
13
|
-
else
|
12
|
+
expect(object.if proc { "I'm true!" },
|
13
|
+
:else => proc { "I'm false!" }).to eq("I'm true!")
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '#if_true' do
|
18
18
|
it 'evaluates the given block' do
|
19
|
-
expect {
|
20
|
-
.
|
19
|
+
expect {
|
20
|
+
object.if_true { puts "I'm true!" }
|
21
|
+
}.to output("I'm true!\n").to_stdout
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'returns the object for chaining' do
|
@@ -33,9 +34,9 @@ RSpec.describe BasicObject do
|
|
33
34
|
|
34
35
|
describe 'chaining #if_true and #if_false' do
|
35
36
|
it 'evaluates based on the original object' do
|
36
|
-
expect {
|
37
|
-
|
38
|
-
|
37
|
+
expect {
|
38
|
+
object.if_true { puts "I'm true!"; false }.if_false { puts "I'm false!" }
|
39
|
+
}.to output("I'm true!\n").to_stdout
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
@@ -43,12 +44,12 @@ end
|
|
43
44
|
RSpec.describe NilClass do
|
44
45
|
describe '#if' do
|
45
46
|
it 'always returns the else block' do
|
46
|
-
expect(nil.if
|
47
|
-
else
|
47
|
+
expect(nil.if proc { "I'm true!" },
|
48
|
+
:else => proc { "I'm false!" }).to eq("I'm false!")
|
48
49
|
end
|
49
50
|
|
50
51
|
it 'does nothing by default' do
|
51
|
-
expect(nil.if
|
52
|
+
expect(nil.if proc { "I'm true!" }).to be_nil
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
@@ -60,8 +61,9 @@ RSpec.describe NilClass do
|
|
60
61
|
|
61
62
|
describe '#if_false' do
|
62
63
|
it 'evaluates the given block' do
|
63
|
-
expect {
|
64
|
-
.
|
64
|
+
expect {
|
65
|
+
nil.if_false { puts "I'm false!" }
|
66
|
+
}.to output("I'm false!\n").to_stdout
|
65
67
|
end
|
66
68
|
|
67
69
|
it 'returns nil' do
|
@@ -71,9 +73,9 @@ RSpec.describe NilClass do
|
|
71
73
|
|
72
74
|
describe 'chaining #if_false and #if_true' do
|
73
75
|
it 'evaluates based on the original object' do
|
74
|
-
expect {
|
75
|
-
|
76
|
-
|
76
|
+
expect {
|
77
|
+
nil.if_false { puts "I'm false!"; true }.if_true { puts "I'm true!" }
|
78
|
+
}.to output("I'm false!\n").to_stdout
|
77
79
|
end
|
78
80
|
end
|
79
81
|
end
|
@@ -81,12 +83,12 @@ end
|
|
81
83
|
RSpec.describe FalseClass do
|
82
84
|
describe '#if' do
|
83
85
|
it 'always returns the else block' do
|
84
|
-
expect(false.if
|
85
|
-
else
|
86
|
+
expect(false.if proc { "I'm true!" },
|
87
|
+
:else => proc { "I'm false!" }).to eq("I'm false!")
|
86
88
|
end
|
87
89
|
|
88
90
|
it 'does nothing by default' do
|
89
|
-
expect(false.if
|
91
|
+
expect(false.if proc { "I'm true!" }).to be_nil
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
@@ -108,9 +110,9 @@ RSpec.describe FalseClass do
|
|
108
110
|
|
109
111
|
describe 'chaining #if_false and #if_true' do
|
110
112
|
it 'evaluates based on the original object' do
|
111
|
-
expect {
|
112
|
-
|
113
|
-
|
113
|
+
expect {
|
114
|
+
nil.if_false { puts "I'm false!"; true }.if_true { puts "I'm true!" }
|
115
|
+
}.to output("I'm false!\n").to_stdout
|
114
116
|
end
|
115
117
|
end
|
116
118
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: if
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Mucur
|
@@ -35,7 +35,8 @@ files:
|
|
35
35
|
- spec/if_spec.rb
|
36
36
|
- spec/spec_helper.rb
|
37
37
|
homepage: https://github.com/mudge/if
|
38
|
-
licenses:
|
38
|
+
licenses:
|
39
|
+
- MIT
|
39
40
|
metadata: {}
|
40
41
|
post_install_message:
|
41
42
|
rdoc_options: []
|