File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,6 +53,14 @@ def less_than_or_equal_to(object)
5353 alias lte less_than_or_equal_to
5454 alias less_than_or_equal less_than_or_equal_to
5555
56+ def include ( object )
57+ build ( { Include : [ self , object ] } )
58+ end
59+
60+ def in ( object )
61+ build ( { In : [ self , object ] } )
62+ end
63+
5664 def percentage_of_actors ( object )
5765 build ( { PercentageOfActors : [ self , build ( object ) ] } )
5866 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 7979 ] )
8080 end
8181
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+
8295 it "can build NotEqual" do
8396 expression = described_class . build ( {
8497 "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