require 'spec_helper' module FluentConditions describe BooleanAccessorDefiner do it "should add accessor methods" do clazz = Class.new do include FluentConditions attr_accessor :admin fluent :admin end @obj = clazz.new @obj.is.should respond_to(:admin) @obj.is.should respond_to(:admin?) @obj.is.should respond_to(:not_admin) @obj.is.should respond_to(:not_admin?) end end describe TextValueAccessorDefiner do it "should add accessor methods" do clazz = Class.new do include FluentConditions attr_accessor :color fluent :color, :values => [:red, :green] end @product = clazz.new @product.is.should respond_to(:red) @product.is.should respond_to(:green) @product.is.should respond_to(:not_red) @product.is.should respond_to(:not_green) @product.is.should respond_to(:red?) @product.is.should respond_to(:green?) @product.is.should respond_to(:not_red?) @product.is.should respond_to(:not_green?) end end describe CustomAccessorDefiner do it "should add accessor methods" do clazz = Class.new do include FluentConditions attr_accessor :length fluent :length, :as => :long, :if => proc { |length| length >= 500 } fluent :length, :as => :short, :if => proc { |length| length < 500 } end @post = clazz.new @post.is.should respond_to(:long) @post.is.should respond_to(:not_long) @post.is.should respond_to(:long?) @post.is.should respond_to(:not_long?) @post.is.should respond_to(:short) @post.is.should respond_to(:not_short) @post.is.should respond_to(:short?) @post.is.should respond_to(:not_short?) end end end