class Lebowski::RSpec::Operators::That
Public Class Methods
new(sym, *args)
click to toggle source
# File lib/lebowski/rspec/operators/that.rb, line 12 def initialize(sym, *args) @sym = sym @args = args end
Public Instance Methods
evaluate(value)
click to toggle source
# File lib/lebowski/rspec/operators/that.rb, line 17 def evaluate(value) case operator when :not_empty return not_empty? value when :empty return empty? value when :between return between? value when :at_most return at_most? value when :at_least return at_least? value when :greater_than return greater_than? value when :less_than return less_than? value when :contains return contains? value when :matches return matches? value when :equals return equals? value when :equal_to return equals? value else raise ArgumentError "Invalid that operator: #{operator}" end end
method_missing(sym, *args, &block)
click to toggle source
# File lib/lebowski/rspec/operators/that.rb, line 54 def method_missing(sym, *args, &block) return self end
operator()
click to toggle source
# File lib/lebowski/rspec/operators/that.rb, line 46 def operator() ["that_is_", "that_"].each do |prefix| if @sym =~ /^#{prefix}/ return @sym.to_s.sub(prefix, "").to_sym end end end
Private Instance Methods
at_least?(value)
click to toggle source
# File lib/lebowski/rspec/operators/that.rb, line 77 def at_least?(value) return false if not value.kind_of? Numeric return value >= @args[0] end
at_most?(value)
click to toggle source
# File lib/lebowski/rspec/operators/that.rb, line 82 def at_most?(value) return false if not value.kind_of? Numeric return value <= @args[0] end
between?(value)
click to toggle source
# File lib/lebowski/rspec/operators/that.rb, line 70 def between?(value) return false if not value.kind_of? Numeric min = @args[0] max = @args[1] return ((value >= min) and (value <= max)) end
contains?(value)
click to toggle source
# File lib/lebowski/rspec/operators/that.rb, line 97 def contains?(value) return false if value.nil? if value.kind_of? String return false if @args.length > 1 return value == @args[0] elsif value.kind_of? Array return @args.all? do |x| value.member? x end end return false end
empty?(value)
click to toggle source
# File lib/lebowski/rspec/operators/that.rb, line 64 def empty?(value) return true if value.nil? return value.length == 0 if value.kind_of?(Array) or value.kind_of?(String) return false end
equals?(value)
click to toggle source
# File lib/lebowski/rspec/operators/that.rb, line 114 def equals?(value) return @args[0] == value end
greater_than?(value)
click to toggle source
# File lib/lebowski/rspec/operators/that.rb, line 87 def greater_than?(value) return false if not value.kind_of? Numeric return value > @args[0] end
less_than?(value)
click to toggle source
# File lib/lebowski/rspec/operators/that.rb, line 92 def less_than?(value) return false if not value.kind_of? Numeric return value < @args[0] end
matches?(value)
click to toggle source
# File lib/lebowski/rspec/operators/that.rb, line 110 def matches?(value) return Lebowski::RSpec::Util.match?(@args[0], value) end
not_empty?(value)
click to toggle source
# File lib/lebowski/rspec/operators/that.rb, line 60 def not_empty?(value) return (not empty? value) end