to_json_spec.rb 1.1 KB

12345678910111213141516171819202122
  1. require 'spec_helper'
  2. describe 'to_json' do
  3. it { is_expected.not_to eq(nil) }
  4. it { is_expected.to run.with_params('').and_return('""') }
  5. it { is_expected.to run.with_params(true).and_return('true') }
  6. it { is_expected.to run.with_params('one').and_return('"one"') }
  7. it { is_expected.to run.with_params([]).and_return('[]') }
  8. it { is_expected.to run.with_params(['one']).and_return('["one"]') }
  9. it { is_expected.to run.with_params(%w[one two]).and_return('["one","two"]') }
  10. it { is_expected.to run.with_params({}).and_return('{}') }
  11. it { is_expected.to run.with_params('key' => 'value').and_return('{"key":"value"}') }
  12. it {
  13. is_expected.to run.with_params('one' => { 'oneA' => 'A', 'oneB' => { 'oneB1' => '1', 'oneB2' => '2' } }, 'two' => %w[twoA twoB])
  14. .and_return('{"one":{"oneA":"A","oneB":{"oneB1":"1","oneB2":"2"}},"two":["twoA","twoB"]}')
  15. }
  16. it { is_expected.to run.with_params('‰').and_return('"‰"') }
  17. it { is_expected.to run.with_params('竹').and_return('"竹"') }
  18. it { is_expected.to run.with_params('Ü').and_return('"Ü"') }
  19. it { is_expected.to run.with_params('∇').and_return('"∇"') }
  20. end