Sha256: 1faa70a87c60a4c1346fe3352d5edadd665e6b24cf7a5cd15e2ba94f98904614

Contents?: true

Size: 872 Bytes

Versions: 6

Compression:

Stored size: 872 Bytes

Contents

require 'spec_helper'

describe Mixpal::Util do
  subject { described_class }

  describe '.hash_to_js_object_string' do
    it 'converts ruby hash to string representation of a javascript object' do
      hash = { key: 'value', another: 'more value' }
      expect(subject.hash_to_js_object_string(hash))
        .to eq '{"key": "value","another": "more value"}'
    end

    it 'leaves Booleans intact to be interpreted as JS Boolean' do
      expect(subject.hash_to_js_object_string(is_cool: true))
        .to eq '{"is_cool": true}'
    end

    it 'leaves Fixnums intact to be interpreted as JS Numbers' do
      expect(subject.hash_to_js_object_string(age: 21))
        .to eq '{"age": 21}'
    end

    it 'does not include keys with nil values' do
      expect(subject.hash_to_js_object_string(age: 21, gender: nil))
        .to eq '{"age": 21}'
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mixpal-0.4.1 spec/lib/mixpal/util_spec.rb
mixpal-0.4.0 spec/lib/mixpal/util_spec.rb
mixpal-0.3.0 spec/lib/mixpal/util_spec.rb
mixpal-0.2.1 spec/lib/mixpal/util_spec.rb
mixpal-0.2.0 spec/lib/mixpal/util_spec.rb
mixpal-0.1.0 spec/lib/mixpal/util_spec.rb