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-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/spec/insist/predicates_spec.rb