Sha256: f003d3e0347e92662f3cc757a8326394a26509fcd331c6ca6ca2a9c95207636b

Contents?: true

Size: 1.54 KB

Versions: 67

Compression:

Stored size: 1.54 KB

Contents

require "spec_setup"
require "insist"
require "insist/predicates"

# The predicates feature will delegateany predicate method calls (ones ending
# in "?") to the block value and fail if the return is false.
describe Insist::Predicates do
  describe "#is_a?" do
    it "should succeed if value#is_a? returns true" do
      insist { "some string" }.is_a?(Object)
      insist { "some string" }.is_a?(String)
    end
    it "should fail if value#is_a? returns false" do
      reject { "some string" }.is_a?(Numeric)
      reject { "some string" }.is_a?(Fixnum)
      reject { "some string" }.is_a?(File)
    end
  end

  describe "#respond_to?" do
    subject do
      insist { [1, 2, 3] }
    end

    it "should be OK if the #value responds to a given method" do
      subject.respond_to?(:[])
      subject.respond_to?(:to_a)
      subject.respond_to?(:each)
    end

    it "should fail if the #value does not respond to a given method" do
      insist { subject.respond_to?(:SOME_INVALID_METHOD) }.fails
    end

    it "should fail if the respond_to? is invoked incorrectly" do
      insist { subject.respond_to? }.raises(ArgumentError)
    end
  end # #respond_to?

  describe "#empty?" do
    it "should be OK if the #value.empty? returns true" do
      insist { [] }.empty?
      insist { {} }.empty?
      insist { "" }.empty?
    end

    it "should fail if the #value.empty? returns a false" do
     insist {  insist { [1] }.empty? }.fails
     insist { insist { { :foo => :bar } }.empty? }.fails
     insist { insist { "hello" }.empty? }.fails
    end
  end # #empty?
end

Version data entries

67 entries across 63 versions & 18 rubygems

Version Path
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-filter-csharp-0.1.0 vendor/bundle/jruby/2.3.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-filter-htmlentities-0.1.0 vendor/bundle/jruby/1.9/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-icinga-1.0.0 vendor/jruby/1.9/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-filter-zabbix-0.1.2 vendor/bundle/jruby/1.9/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-filter-zabbix-0.1.1 vendor/bundle/jruby/1.9/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-input-fifo-0.9.1 vendor/bundle/jruby/1.9/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-input-fifo-0.9.0 vendor/bundle/jruby/1.9/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-input-salesforce-3.0.0 vendor/jruby/1.9/gems/insist-1.0.0/spec/insist/predicates_spec.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/insist-1.0.0/spec/insist/predicates_spec.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/insist-1.0.0/spec/insist/predicates_spec.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-filter-delta-1.1.0 vendor/bundle/jruby/2.2.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-filter-delta-1.0.1 vendor/bundle/jruby/2.2.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-filter-base64-1.0.4 vendor/bundle/jruby/2.2.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-filter-base64-1.0.3 vendor/bundle/jruby/2.2.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-filter-delta-1.0.0 vendor/bundle/jruby/2.2.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-filter-base64-1.0.2 vendor/bundle/jruby/2.3.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-filter-base64-1.0.1 vendor/bundle/jruby/2.3.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-filter-base64-1.0.0 vendor/bundle/jruby/2.3.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb