File tree Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,14 @@ def less_than_or_equal_to(object)
53
53
alias lte less_than_or_equal_to
54
54
alias less_than_or_equal less_than_or_equal_to
55
55
56
+ def include ( object )
57
+ build ( { Include : [ self , object ] } )
58
+ end
59
+
60
+ def in ( object )
61
+ build ( { In : [ self , object ] } )
62
+ end
63
+
56
64
def percentage_of_actors ( object )
57
65
build ( { PercentageOfActors : [ self , build ( object ) ] } )
58
66
end
Original file line number Diff line number Diff line change
1
+ module Flipper
2
+ module Expressions
3
+ class Include
4
+ def self . call ( left , right )
5
+ left . respond_to? ( :include? ) && left . include? ( right )
6
+ end
7
+ end
8
+ end
9
+ end
Original file line number Diff line number Diff line change 79
79
] )
80
80
end
81
81
82
+ it "can build Include" do
83
+ expression = described_class . build ( {
84
+ "Inlcude" => [ [ "hello" ] , "hello" ]
85
+ } )
86
+
87
+ expect ( expression ) . to be_instance_of ( Flipper ::Expression )
88
+ expect ( expression . function ) . to be ( Flipper ::Expressions ::Include )
89
+ expect ( expression . args ) . to eq ( [
90
+ Flipper . constant ( [ "hello" ] ) ,
91
+ Flipper . constant ( "hello" ) ,
92
+ ] )
93
+ end
94
+
82
95
it "can build NotEqual" do
83
96
expression = described_class . build ( {
84
97
"NotEqual" => [
Original file line number Diff line number Diff line change
1
+ RSpec . describe Flipper ::Expressions ::Include do
2
+ describe "#call" do
3
+ it "returns true when left includes right" do
4
+ expect ( described_class . call ( [ 2 ] , 2 ) ) . to be ( true )
5
+ end
6
+
7
+ it "returns false when left does not include right" do
8
+ expect ( described_class . call ( [ 2 ] , "2" ) ) . to be ( false )
9
+ end
10
+
11
+ it "returns false when left does not respond to #include?" do
12
+ expect ( described_class . call ( nil , nil ) ) . to be ( false )
13
+ end
14
+
15
+ it "raises ArgumentError with no arguments" do
16
+ expect { described_class . call } . to raise_error ( ArgumentError )
17
+ end
18
+
19
+ it "raises ArgumentError with one argument" do
20
+ expect { described_class . call ( 10 ) } . to raise_error ( ArgumentError )
21
+ end
22
+ end
23
+ end
You can’t perform that action at this time.
0 commit comments