spec/unit/key_spec.rb in transcriber-0.0.2 vs spec/unit/key_spec.rb in transcriber-0.0.3
- old
+ new
@@ -14,10 +14,63 @@
it "sets options" do
subject.options.should == options
end
end
- describe "present?" do
+ describe "#visible?" do
+ context "when :visible option was defined" do
+ context "and :if option was defined with false" do
+ subject {Resource::Property.new(name, {if: proc {false}, visible: true})}
+ it "return false even when visible is true" do
+ subject.visible?(nil).should be_false
+ end
+ end
+
+ context "and it evaluates to false" do
+ subject {Resource::Property.new(name, {visible: false})}
+
+ it "returns false" do
+ subject.visible?(nil).should be_false
+ end
+ end
+
+ context "and it evaluates to true" do
+ subject {Resource::Property.new(name, {visible: true})}
+
+ it "returns true" do
+ subject.visible?(nil).should be_true
+ end
+ end
+
+ context "with a proc" do
+ context "and it evaluates true" do
+ subject {Resource::Property.new(name, {visible: proc {true}})}
+ it "returns true" do
+ subject.visible?("a").should be_true
+ end
+ end
+
+ context "and it evaluates false" do
+ subject {Resource::Property.new(name, {visible: proc {false}})}
+ it "returns false" do
+ subject.visible?("a").should be_false
+ end
+ end
+
+ context "and it depends on resource instance" do
+ subject {Resource::Property.new(name, {visible: proc {show}})}
+
+ it "uses it" do
+ resource = OpenStruct.new
+ resource.show = true
+ subject.visible?(resource).should be_true
+ end
+ end
+ end
+ end
+ end
+
+ describe "#present?" do
context "when :if option was defined with a proc" do
context "and it evaluates to false" do
subject {Resource::Property.new(name, {if: proc {false}})}
it "returns false" do