Sha256: 1c8d38ae449ba638060bb0ec4a99409ab7007e510939f206ffa0128c4d868c8b

Contents?: true

Size: 1.32 KB

Versions: 22

Compression:

Stored size: 1.32 KB

Contents

# encoding: utf-8

require 'spec_helper'

unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
  describe 'String#ascii_only' do
    it 'returns same value for string with ASCII chars only' do
      expect('abc'.ascii_only).to eq 'abc'
    end

    it 'returns string without non-ASCII chars' do
      expect("abc\u{6666}".force_encoding("UTF-8").ascii_only).to eq 'abc'
    end

    it 'returns string without non-ASCII chars and with ASCII chars' do
      expect("\u{6666}".force_encoding("UTF-8").ascii_only).to eq ''
    end

    it 'does not change the original string' do
      string = "abc\u{6666}".force_encoding("UTF-8")
      string.ascii_only
      expect(string).to eq "abc\u{6666}".force_encoding("UTF-8")
    end
  end

  describe 'String#ascii_only!' do
    it 'returns same value for string with ASCII chars only' do
      expect('abc'.ascii_only!).to eq 'abc'
    end

    it 'returns string without non-ASCII chars' do
      expect("abc\u{6666}".force_encoding("UTF-8").ascii_only!).to eq 'abc'
    end

    it 'returns string without non-ASCII chars and with ASCII chars' do
      expect("\u{6666}".force_encoding("UTF-8").ascii_only!).to eq ''
    end

    it 'changes the original string' do
      string = "abc\u{6666}".force_encoding("UTF-8")
      string.ascii_only!
      expect(string).to eq 'abc'
    end
  end
end

Version data entries

22 entries across 19 versions & 6 rubygems

Version Path
powerpack-0.1.3 spec/powerpack/string/ascii_only_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/spec/powerpack/string/ascii_only_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/spec/powerpack/string/ascii_only_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/spec/powerpack/string/ascii_only_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/spec/powerpack/string/ascii_only_spec.rb
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.1/spec/powerpack/string/ascii_only_spec.rb
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.2/spec/powerpack/string/ascii_only_spec.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.1/spec/powerpack/string/ascii_only_spec.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/powerpack-0.1.2/spec/powerpack/string/ascii_only_spec.rb
powerpack-0.1.2 spec/powerpack/string/ascii_only_spec.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/spec/powerpack/string/ascii_only_spec.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/spec/powerpack/string/ascii_only_spec.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/spec/powerpack/string/ascii_only_spec.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/spec/powerpack/string/ascii_only_spec.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/spec/powerpack/string/ascii_only_spec.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/powerpack-0.1.1/spec/powerpack/string/ascii_only_spec.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/powerpack-0.1.1/spec/powerpack/string/ascii_only_spec.rb
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/powerpack-0.0.9/spec/powerpack/string/ascii_only_spec.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/powerpack-0.0.9/spec/powerpack/string/ascii_only_spec.rb
powerpack-0.1.1 spec/powerpack/string/ascii_only_spec.rb