Sha256: 309b4c1b2b8b580ecf31b6720473bd37f6af3747c8a6e67ae0184e7417f64205

Contents?: true

Size: 1.38 KB

Versions: 402

Compression:

Stored size: 1.38 KB

Contents

require 'rspec/matchers'
# Special matcher for comparing encoded strings so that
# we don't run any expectation failures through the Differ,
# which also relies on EncodedString. Instead, confirm the
# strings have the same bytes.
RSpec::Matchers.define :be_identical_string do |expected|

  if String.method_defined?(:encoding)
    match do
      expected_encoding? &&
        actual.bytes.to_a == expected.bytes.to_a
    end

    failure_message do
      "expected\n#{actual.inspect} (#{actual.encoding.name}) to be identical to\n"\
        "#{expected.inspect} (#{expected.encoding.name})\n"\
        "The exact bytes are printed below for more detail:\n"\
        "#{actual.bytes.to_a}\n"\
        "#{expected.bytes.to_a}\n"\
    end

    # Depends on chaining :with_same_encoding for it to
    # check for string encoding.
    def expected_encoding?
      if defined?(@expect_same_encoding) && @expect_same_encoding
        actual.encoding == expected.encoding
      else
        true
      end
    end
  else
    match do
      actual.split(//) == expected.split(//)
    end

    failure_message do
      "expected\n#{actual.inspect} to be identical to\n#{expected.inspect}\n"
    end
  end

  chain :with_same_encoding do
    @expect_same_encoding ||= true
  end
end
RSpec::Matchers.alias_matcher :a_string_identical_to, :be_identical_string
RSpec::Matchers.alias_matcher :be_diffed_as, :be_identical_string

Version data entries

402 entries across 329 versions & 82 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
passbase-1.3.0 vendor/bundle/ruby/2.7.0/gems/rspec-support-3.9.3/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/rspec-support-3.8.2/lib/rspec/support/spec/string_matcher.rb